Test Pac-Modul
This commit is contained in:
parent
630795f59c
commit
6d8744533e
40
hsarback/test/META-INF/persistence.xml
Normal file
40
hsarback/test/META-INF/persistence.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
|
||||
<persistence-unit name="hsadmin" transaction-type="RESOURCE_LOCAL">
|
||||
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
|
||||
<class>de.hsadmin.core.qserv.QueueTask</class>
|
||||
<class>de.hsadmin.mods.cust.Customer</class>
|
||||
<class>de.hsadmin.mods.cust.Contact</class>
|
||||
<class>de.hsadmin.mods.cust.BankAccount</class>
|
||||
<class>de.hsadmin.mods.cust.CustomersTariff</class>
|
||||
<class>de.hsadmin.mods.pac.Pac</class>
|
||||
<class>de.hsadmin.mods.pac.BasePac</class>
|
||||
<class>de.hsadmin.mods.pac.BaseComponent</class>
|
||||
<class>de.hsadmin.mods.pac.Component</class>
|
||||
<class>de.hsadmin.mods.pac.PacComponent</class>
|
||||
<class>de.hsadmin.mods.pac.Hive</class>
|
||||
<class>de.hsadmin.mods.pac.INetAddress</class>
|
||||
<class>de.hsadmin.mods.user.UnixUser</class>
|
||||
<class>de.hsadmin.mods.dom.Domain</class>
|
||||
<class>de.hsadmin.mods.email.EMailAddress</class>
|
||||
<class>de.hsadmin.mods.email.EMailAlias</class>
|
||||
<class>de.hsadmin.mods.db.DatabaseUser</class>
|
||||
<class>de.hsadmin.mods.db.MySqlUser</class>
|
||||
<class>de.hsadmin.mods.db.PgSqlUser</class>
|
||||
<class>de.hsadmin.mods.db.Database</class>
|
||||
<class>de.hsadmin.mods.db.MySqlDatabase</class>
|
||||
<class>de.hsadmin.mods.db.PgSqlDatabase</class>
|
||||
<properties>
|
||||
<property name="openjpa.ConnectionProperties"
|
||||
value="DriverClassName=org.postgresql.Driver,
|
||||
Url=jdbc:postgresql://localhost:5432/hsh03_hsatest,
|
||||
MaxActive=100,
|
||||
MaxWait=10000,
|
||||
TestOnBorrow=true,
|
||||
Username=hsh03_hsatest,
|
||||
Password=Eeng7ietee"/>
|
||||
<property name="openjpa.ConnectionDriverName"
|
||||
value="org.apache.commons.dbcp.BasicDataSource"/>
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
</persistence>
|
99
hsarback/test/de/hsadmin/processor/PacProcessor.java
Normal file
99
hsarback/test/de/hsadmin/processor/PacProcessor.java
Normal file
@ -0,0 +1,99 @@
|
||||
package de.hsadmin.processor;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.persistence.Persistence;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import de.hsadmin.core.qserv.Processor;
|
||||
import de.hsadmin.core.qserv.ProcessorException;
|
||||
import de.hsadmin.mods.cust.Customer;
|
||||
import de.hsadmin.mods.pac.BasePac;
|
||||
import de.hsadmin.mods.pac.Hive;
|
||||
import de.hsadmin.mods.pac.Pac;
|
||||
import de.hsadmin.mods.pac.PacProcessorFactory;
|
||||
|
||||
public class PacProcessor {
|
||||
|
||||
private static EntityManagerFactory emFactory;
|
||||
private EntityManager entityManager;
|
||||
private PacProcessorFactory pacProcFactory;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
emFactory = Persistence.createEntityManagerFactory("hsadmin");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
emFactory.close();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
entityManager = emFactory.createEntityManager();
|
||||
pacProcFactory = new PacProcessorFactory();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
if (entityManager != null) {
|
||||
entityManager.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createCreateProcessor() {
|
||||
Customer cust = findCustomer("hsh00-hsh");
|
||||
assertNotNull(cust);
|
||||
BasePac basepac = findBasePacDW();
|
||||
assertNotNull(basepac);
|
||||
Hive hive = findHive("h99");
|
||||
assertNotNull(hive);
|
||||
try {
|
||||
Processor processor = pacProcFactory.createCreateProcessor(entityManager, new Pac("pac01", cust, basepac, hive));
|
||||
System.out.println(processor.toString());
|
||||
} catch (ProcessorException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private BasePac findBasePacDW() {
|
||||
Query basepacQuery = entityManager.createQuery("SELECT b FROM BasePacs b WHERE b.name = :basepacName AND b.valid = :valid");
|
||||
basepacQuery.setParameter("basepacName", "DW/B");
|
||||
basepacQuery.setParameter("valid", Boolean.TRUE);
|
||||
return (BasePac) basepacQuery.getSingleResult();
|
||||
}
|
||||
|
||||
private Customer findCustomer(String name) {
|
||||
Query custQuery = entityManager.createQuery("SELECT c FROM Customers c WHERE c.name = :custName");
|
||||
custQuery.setParameter("custName", name);
|
||||
return (Customer) custQuery.getSingleResult();
|
||||
}
|
||||
|
||||
private Hive findHive(String name) {
|
||||
Query hiveQuery = entityManager.createQuery("SELECT h FROM Hives h WHERE h.name = :hiveName");
|
||||
hiveQuery.setParameter("hiveName", name);
|
||||
return (Hive) hiveQuery.getSingleResult();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUpdateProcessor() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDeleteProcessor() {
|
||||
fail("Not yet implemented");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user