From 6d8744533e8d400385d0c51d7762364b9a49524f Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@hostsharing.net>
Date: Tue, 12 Jun 2012 12:57:24 +0200
Subject: [PATCH] Test Pac-Modul

---
 hsarback/test/META-INF/persistence.xml               |   40 +++++++++++++
 hsarback/test/de/hsadmin/processor/PacProcessor.java |   99 +++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+), 0 deletions(-)

diff --git a/hsarback/test/META-INF/persistence.xml b/hsarback/test/META-INF/persistence.xml
new file mode 100644
index 0000000..25c8084
--- /dev/null
+++ b/hsarback/test/META-INF/persistence.xml
@@ -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>
diff --git a/hsarback/test/de/hsadmin/processor/PacProcessor.java b/hsarback/test/de/hsadmin/processor/PacProcessor.java
new file mode 100644
index 0000000..fe7fe1f
--- /dev/null
+++ b/hsarback/test/de/hsadmin/processor/PacProcessor.java
@@ -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");
+	}
+
+}

--
Gitblit v1.9.1