From f09b319789fcf76504f1013a158f33a76fbfda28 Mon Sep 17 00:00:00 2001
From: Peter Hormanns <peter.hormanns@hostsharing.net>
Date: Thu, 19 Jul 2012 16:27:58 +0200
Subject: [PATCH] provide option for developer tests without cas and ssl fix several errors on domainoptions

---
 hsarback/conf/jndi.properties                                   |    2 
 hsarback/src/de/hsadmin/mods/dom/DomainOption.java              |   37 ++++--
 hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java          |    2 
 hsarback/src/de/hsadmin/core/model/onetier/TicketValidator.java |   11 +
 hsarback/src/de/hsadmin/remote/DomainRemote.java                |    4 
 hsarback/src/de/hsadmin/core/model/Transaction.java             |    3 
 hsarback/test/de/hsadmin/remote/RemoteCASHelper.java            |    6 +
 hsarback/conf/META-INF/dev-context.xml                          |   33 +++++
 hsarback/conf/WEB-INF/dev-web.xml                               |  185 ++++++++++++++++++++++++++++++
 hsarback/src/de/hsadmin/mods/dom/Domain.java                    |    6 
 hsarback/test/de/hsadmin/remote/DomainTest.java                 |   13 -
 11 files changed, 274 insertions(+), 28 deletions(-)

diff --git a/hsarback/conf/META-INF/dev-context.xml b/hsarback/conf/META-INF/dev-context.xml
new file mode 100644
index 0000000..808ab2b
--- /dev/null
+++ b/hsarback/conf/META-INF/dev-context.xml
@@ -0,0 +1,33 @@
+<Context path="/hsar" reloadable="true" crossContext="true">
+
+	<ResourceLink
+		name="jdbc/HSAdminDB"
+		global="jdbc/HSAdminDB"
+		type="javax.sql.DataSource"/>
+
+	<ResourceLink
+		name="jms/QueueCF"
+		global="jms/QueueCF"
+		type="javax.jms.QueueConnectionFactory"/>
+
+	<ResourceLink
+		name="jms/hsadminSystem-h99"
+		global="jms/hsadminSystem-h99"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
+		name="jms/hsadminSystem-testmail"
+		global="jms/hsadminSystem-testmail"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
+		name="jms/hsadminSystem-testdns"
+		global="jms/hsadminSystem-testdns"
+		type="javax.jms.Queue"/>
+
+	<ResourceLink
+		name="jms/hsadminStatus"
+		global="jms/hsadminStatus"
+		type="javax.jms.Queue"/>
+
+</Context>
diff --git a/hsarback/conf/WEB-INF/dev-web.xml b/hsarback/conf/WEB-INF/dev-web.xml
new file mode 100644
index 0000000..5d6cca9
--- /dev/null
+++ b/hsarback/conf/WEB-INF/dev-web.xml
@@ -0,0 +1,185 @@
+<?xml version="1.0"?> 
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+    version="2.5">
+
+	<listener>
+		<listener-class>de.hsadmin.core.model.onetier.PersistenceManagerContextListener</listener-class>
+	</listener>
+	
+    <servlet>
+        <servlet-name>Queue Status Servlet</servlet-name>
+        <servlet-class>de.hsadmin.core.qserv.QueueStatusReceiverServlet</servlet-class>
+        <load-on-startup>1</load-on-startup>
+    </servlet>
+
+  	<servlet>
+  		<servlet-name>CLI Client Connector</servlet-name>
+	  	<servlet-class>de.hsadmin.cliClientConnector.CLIClientConnectorServlet</servlet-class>
+  		<init-param>
+	  		<param-name>proxyValidateUrl</param-name>
+		  	<param-value>TestUmgebung</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>proxyServiceUrl</param-name>
+		  	<param-value>TestUmgebung</param-value>
+  		</init-param>
+	  	<init-param>
+  			<param-name>Components</param-name>
+	  		<param-value>member,pac,user,domain,emailaddress,emailalias,mysqluser,mysqldb,postgresqluser,postgresqldb,q</param-value>
+		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_member</param-name>
+			<param-value>de.hsadmin.mods.cust.Customer</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_member</param-name>
+		  	<param-value>Mitglieder</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_pac</param-name>
+			<param-value>de.hsadmin.mods.pac.Pac</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_pac</param-name>
+		  	<param-value>Pakete</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentClass_user</param-name>
+		  	<param-value>de.hsadmin.mods.user.UnixUser</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_user</param-name>
+		  	<param-value>Benutzer und Postfaecher anlegen</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_domain</param-name>
+			<param-value>de.hsadmin.mods.dom.Domain</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_domain</param-name>
+		  	<param-value>Domains aufschalten</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_emailaddress</param-name>
+			<param-value>de.hsadmin.mods.email.EMailAddress</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_emailaddress</param-name>
+		  	<param-value>E-Mail Adressen</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_emailalias</param-name>
+			<param-value>de.hsadmin.mods.email.EMailAlias</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_emailalias</param-name>
+		  	<param-value>E-Mail Aliases</param-value>  
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_postgresqluser</param-name>
+			<param-value>de.hsadmin.mods.db.PgSqlUser</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_postgresqluser</param-name>
+		  	<param-value>PostgreSQL DB-Administrator</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_postgresqldb</param-name>
+			<param-value>de.hsadmin.mods.db.PgSqlDatabase</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_postgresqldb</param-name>
+		  	<param-value>PostgreSQL Datenbank</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_mysqluser</param-name>
+			<param-value>de.hsadmin.mods.db.MySqlUser</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_mysqluser</param-name>
+		  	<param-value>MySQL DB-Administrator</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_mysqldb</param-name>
+			<param-value>de.hsadmin.mods.db.MySqlDatabase</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_mysqldb</param-name>
+		  	<param-value>MySQL Datenbank</param-value>
+  		</init-param>
+	  	<init-param>
+		  	<param-name>ComponentClass_q</param-name>
+			<param-value>de.hsadmin.core.qserv.QueueTask</param-value>
+  		</init-param>
+  		<init-param>
+	  		<param-name>ComponentDescription_q</param-name>
+		  	<param-value>Offene Aktionen</param-value>
+  		</init-param>
+        <load-on-startup>1</load-on-startup>
+  	</servlet>
+
+   <servlet>
+        <servlet-name>XmlRpcServlet</servlet-name>
+        <servlet-class>org.apache.xmlrpc.webserver.XmlRpcServlet</servlet-class>
+        <init-param>
+          <param-name>enabledForExtensions</param-name>
+          <param-value>true</param-value>
+        </init-param>
+    </servlet>
+
+    <servlet-mapping>
+        <servlet-name>Queue Status Servlet</servlet-name>
+        <url-pattern>/queueStatus</url-pattern>
+    </servlet-mapping>
+
+    <servlet-mapping>
+        <servlet-name>CLI Client Connector</servlet-name>
+        <url-pattern>/hsadmin/cli-interface/</url-pattern>
+    </servlet-mapping>
+
+    <servlet-mapping>
+        <servlet-name>XmlRpcServlet</servlet-name>
+        <url-pattern>/xmlrpc/*</url-pattern>
+    </servlet-mapping>
+
+    <resource-ref>
+        <res-ref-name>jdbc/HSAdminDB</res-ref-name>
+        <res-type>javax.sql.DataSource</res-type>
+        <res-auth>Container</res-auth>
+    </resource-ref>
+ 	    
+    <resource-ref>
+        <res-ref-name>jms/QueueCF</res-ref-name>
+        <res-type>javax.jms.QueueConnectionFactory</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+ 	    
+    <resource-ref>
+        <res-ref-name>jms/hsadminSystem-h99</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
+        <res-ref-name>jms/hsadminSystem-testdns</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
+        <res-ref-name>jms/hsadminSystem-testmail</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+    <resource-ref>
+        <res-ref-name>jms/hsadminStatus</res-ref-name>
+        <res-type>javax.jms.Queue</res-type>
+        <res-auth>Container</res-auth>
+        <res-sharing-scope>Shareable</res-sharing-scope>
+    </resource-ref>
+ 	    
+</web-app>
diff --git a/hsarback/conf/jndi.properties b/hsarback/conf/jndi.properties
index f9e97d8..5fc5e85 100644
--- a/hsarback/conf/jndi.properties
+++ b/hsarback/conf/jndi.properties
@@ -1,5 +1,5 @@
 java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory
-java.naming.provider.url=ssl://agnes.ostwall195.de:61617
+java.naming.provider.url=ssl://config-test.ostwall195.de:61617
 connectionFactoryNames=QueueCF
 queue.hsadminSystem-h81=queue.hsadminSystem-h81
 queue.hsadminStatus=queue.hsadminStatus
\ No newline at end of file
diff --git a/hsarback/src/de/hsadmin/core/model/Transaction.java b/hsarback/src/de/hsadmin/core/model/Transaction.java
index ad57110..af08c13 100644
--- a/hsarback/src/de/hsadmin/core/model/Transaction.java
+++ b/hsarback/src/de/hsadmin/core/model/Transaction.java
@@ -160,9 +160,6 @@
 	 * old and new attribute values. 
 	 */
 	public void detach(AbstractEntity entity) {
-		// TODO: replace hibernate specific implmentation
-//		org.hibernate.Session hSession = (Session) entityManager.getDelegate();
-//		hSession.evict(entity);
 		if (entityManager instanceof OpenJPAEntityManager) {
 			OpenJPAEntityManager openjpaEM = (OpenJPAEntityManager) entityManager;
 			openjpaEM.detach(entity);
diff --git a/hsarback/src/de/hsadmin/core/model/onetier/TicketValidator.java b/hsarback/src/de/hsadmin/core/model/onetier/TicketValidator.java
index d80e64b..e2630ce 100644
--- a/hsarback/src/de/hsadmin/core/model/onetier/TicketValidator.java
+++ b/hsarback/src/de/hsadmin/core/model/onetier/TicketValidator.java
@@ -40,7 +40,16 @@
 	}
 	
 	public String validateTicket(String ticket) throws AuthenticationException {
-		if (proxyServiceURL == null || proxyServiceURL == null) {
+		// for testing purpose only
+		if ("TestUmgebung".equals(proxyServiceURL) && "TestUmgebung".equals(proxyValidateURL)) {
+			if (ticket.startsWith("user:")) {
+				return ticket.substring(5);
+			} else {
+				throw new AuthenticationException("Invalid Ticket: " + ticket);
+			}
+		}
+		// real implementation
+		if (proxyServiceURL == null || proxyValidateURL == null) {
 			log.fatal("TicketValidator is not initialized.");
 			throw new RuntimeException("TicketValidator is not initialized.");
 		}
diff --git a/hsarback/src/de/hsadmin/mods/dom/Domain.java b/hsarback/src/de/hsadmin/mods/dom/Domain.java
index 421f212..4319c14 100644
--- a/hsarback/src/de/hsadmin/mods/dom/Domain.java
+++ b/hsarback/src/de/hsadmin/mods/dom/Domain.java
@@ -14,6 +14,7 @@
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.SequenceGenerator;
@@ -68,7 +69,10 @@
 	@Column(name = "domain_dns_master", columnDefinition = "character varying(64)")
 	private String dnsMaster;
 
-	@ManyToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="domains")
+	@ManyToMany(cascade={CascadeType.ALL}, fetch=FetchType.EAGER)
+	@JoinTable(name="domain__domain_option", 
+		joinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")},
+		inverseJoinColumns={@JoinColumn(name="domain_option_id", referencedColumnName="domain_option_id")})
 	private Set<DomainOption> domainOptions;
 	
 	public Domain() {
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
index 5dd552a..4b329e6 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainModuleImpl.java
@@ -162,6 +162,8 @@
 			List<?> list = q.getResultList();
 			if (list.size() != 1) {
 				throw new HSAdminException("invalid domain option: " + opt.getName());
+			} else {
+				opt.setId(((DomainOption) list.get(0)).getId());
 			}
 		}
 		needsWriteAccessOn(existingEntity, "update");
diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainOption.java b/hsarback/src/de/hsadmin/mods/dom/DomainOption.java
index 180f8d3..f9c39af 100644
--- a/hsarback/src/de/hsadmin/mods/dom/DomainOption.java
+++ b/hsarback/src/de/hsadmin/mods/dom/DomainOption.java
@@ -2,17 +2,14 @@
 
 import static javax.persistence.GenerationType.SEQUENCE;
 
-import java.util.Set;
+import java.util.List;
 
-import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.EntityManager;
 import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
-import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
 import javax.persistence.ManyToMany;
 import javax.persistence.SequenceGenerator;
 import javax.persistence.Table;
@@ -35,12 +32,9 @@
 	@Column(name = "domain_option_name", columnDefinition = "character varying(256)", nullable = false)
 	private String name;
 
-	@ManyToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
-	@JoinTable(name="domain__domain_option",
-		joinColumns={@JoinColumn(name="domain_option_id", referencedColumnName="domain_option_id")},
-		inverseJoinColumns={@JoinColumn(name="domain_id", referencedColumnName="domain_id")})
-	private Set<Domain> domains;
-
+	@ManyToMany(mappedBy="domainOptions", fetch=FetchType.LAZY)
+	private List<Domain> domains;
+	
 	@Override
 	public long id() {
 		return getId();
@@ -78,11 +72,30 @@
 		this.name = name;
 	}
 
-	public Set<Domain> getDomains() {
+	@Override
+	public boolean equals(Object obj) {
+		if (obj instanceof DomainOption) {
+			DomainOption opt = (DomainOption) obj;
+			return getName().equals(opt.getName());
+		}
+		return false;
+	}
+
+	@Override
+	public int hashCode() {
+		return getName().hashCode();
+	}
+
+	@Override
+	public String toString() {
+		return getName();
+	}
+
+	public List<Domain> getDomains() {
 		return domains;
 	}
 
-	public void setDomains(Set<Domain> domains) {
+	public void setDomains(List<Domain> domains) {
 		this.domains = domains;
 	}
 
diff --git a/hsarback/src/de/hsadmin/remote/DomainRemote.java b/hsarback/src/de/hsadmin/remote/DomainRemote.java
index c7dba9a..f01cd7d 100644
--- a/hsarback/src/de/hsadmin/remote/DomainRemote.java
+++ b/hsarback/src/de/hsadmin/remote/DomainRemote.java
@@ -4,10 +4,10 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.TreeSet;
 
 import de.hsadmin.core.model.AbstractEntity;
 import de.hsadmin.mods.dom.Domain;
@@ -61,7 +61,7 @@
 			u.setName(user);
 			dom.setUser(u);
 		}
-		Set<DomainOption> domainOptionsSet = new TreeSet<DomainOption>();
+		Set<DomainOption> domainOptionsSet = new HashSet<DomainOption>();
 		Object domOptsObj = setParams.get("domainoptions");
 		if (domOptsObj != null && domOptsObj instanceof Object[]) {
 			Object[] domOptions = (Object[]) domOptsObj;
diff --git a/hsarback/test/de/hsadmin/remote/DomainTest.java b/hsarback/test/de/hsadmin/remote/DomainTest.java
index e4ebe53..60f489c 100644
--- a/hsarback/test/de/hsadmin/remote/DomainTest.java
+++ b/hsarback/test/de/hsadmin/remote/DomainTest.java
@@ -51,7 +51,6 @@
 			for (Object o : result) {
 				if (o instanceof Map<?, ?>) {
 					Map<?, ?> row = (Map<?, ?>) o;
-//					assertEquals("aaa00", row.get("user"));
 					assertTrue("aaa00".equals(row.get("user")) || "aaa00-admin".equals(row.get("user")));
 				} else {
 					fail("map expected");
@@ -78,7 +77,6 @@
 			assertNotNull(execute);
 			fail("exception expected");
 		} catch (XmlRpcException e) {
-//			System.out.println(e.getMessage());
 		}
 	}
 
@@ -199,7 +197,6 @@
 		String grantingTicketURL = cas.getGrantingTicketURL(user);
 		Map<String, Object> setParams = new HashMap<String, Object>();
 		Map<String, String> whereParams = new HashMap<String, String>();
-		setParams.put("user", "aaa00");
 		List<String> optionslist = new ArrayList<String>();
 		setParams.put("domainoptions", optionslist);
 		whereParams.put("name", "example01.org");
@@ -245,16 +242,16 @@
 		try {
 			Object execute = client.execute(MODULE + ".search", params);
 			Object[] result = (Object[]) execute;
-			assertEquals(1, result.length);
+			assertEquals(result.length, 1);
 			assertTrue(result[0] instanceof Map<?, ?>);
 			Map<String, ?> domainMap = (Map<String, ?>) result[0];
 			assertNotNull(domainMap);
 			Object[] optsList = (Object[])domainMap.get("domainoptions");
-//			if (optsList == null) {
-//				count = 0;
-//			} else {
+			if (optsList == null) {
+				count = 0;
+			} else {
 				count = optsList.length;
-//			}
+			}
 		} catch (XmlRpcException e) {
 			fail(e.getMessage());
 		}
diff --git a/hsarback/test/de/hsadmin/remote/RemoteCASHelper.java b/hsarback/test/de/hsadmin/remote/RemoteCASHelper.java
index ad7b8d7..d2ae1b6 100644
--- a/hsarback/test/de/hsadmin/remote/RemoteCASHelper.java
+++ b/hsarback/test/de/hsadmin/remote/RemoteCASHelper.java
@@ -35,6 +35,9 @@
 	}
 	
 	public String getGrantingTicketURL(String user) {
+		if ("TestUmgebung".equals(loginURL)) {
+			return "granting:" + user;
+		}
 		String pw = Config.getInstance().getProperty(user + ".passWord", "-");
 		try {
 			String encodedParams = URLEncoder.encode("username", "UTF-8")
@@ -49,6 +52,9 @@
 	}
 
 	public String getServiceTicket(String location, String service) {
+		if (location.startsWith("granting:")) {
+			return "user:" + location.substring(9);
+		}
 		try {
 			String encodedParams = URLEncoder.encode("service", "UTF-8")
 				+ "=" + URLEncoder.encode(service, "UTF-8");

--
Gitblit v1.9.0-SNAPSHOT