package de.hsadmin.remote; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.util.HashMap; import java.util.Map; import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.client.XmlRpcClient; import org.junit.After; import org.junit.Before; import org.junit.Test; public class InitDataTest { private static final String CUST_MODULE = "member"; private static final String PAC_MODULE = "pac"; private static final String USER_MODULE = "user"; private static final String DOM_MODULE = "domain"; private XmlRpcClient client; private RemoteCASHelper cas; @Before public void setUp() throws Exception { client = RemoteTestHelper.getClient(); cas = new RemoteCASHelper(); } @After public void tearDown() throws Exception { client = null; cas = null; } @Test public void testAddMember() { String user = "ad"; int membersCount = -9999; membersCount = getMembersCount(); String grantingTicketURL = cas.getGrantingTicketURL(user); Map setParams = new HashMap(); setParams.put("membercode", "hsh00-aaa"); setParams.put("password", "geheimnIs"); setParams.put("memberno", "20001"); setParams.put("membersince", "01.10.2010"); setParams.put("contact_salut", "Herr"); setParams.put("contact_title", "Dr."); setParams.put("contact_firstname", "Ömer Günther"); setParams.put("contact_lastname", "Janßen-Müller"); setParams.put("contact_salut", "Herr"); setParams.put("contact_street", "Hauptstr. 1"); setParams.put("contact_zipcode", "99998"); setParams.put("contact_city", "Musterstadt"); setParams.put("contact_country", "D"); setParams.put("contact_phone_private", "+49 9999 123456"); setParams.put("contact_email", "test@ostwall195.de"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams }; try { client.execute(CUST_MODULE + ".add", params); assertEquals(membersCount + 1, getMembersCount()); } catch (XmlRpcException e) { fail(e.getMessage()); } } @Test public void testAddPac() { int count = getPacsCount(); String user = "ad"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map setParams = new HashMap(); setParams.put("name", "aaa00"); setParams.put("hive", "h99"); setParams.put("customer", "hsh00-aaa"); setParams.put("basepac", "DW/B"); setParams.put("curinetaddr", "176.9.242.73"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams }; try { Object execute = client.execute(PAC_MODULE + ".add", params); assertTrue(execute instanceof Map); } catch (XmlRpcException e) { fail(e.getMessage()); } assertEquals(count + 1, getPacsCount()); } @Test public void testAddUser() { int count = getUsersCount(); try { String user = "aaa00"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map setParams = new HashMap(); setParams.put("name", "aaa00-test2"); setParams.put("password", "test123"); setParams.put("quota", "128"); setParams.put("quotalimit", "192"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams }; Object execute = client.execute(USER_MODULE + ".add", params); if (execute instanceof Map) { Map entry = (Map) execute; assertEquals("aaa00-test2", entry.get("name")); assertEquals("aaa00", entry.get("pac")); assertEquals(null, entry.get("password")); } else { fail("map expected"); } } catch (XmlRpcException e) { fail(e.getMessage()); } assertEquals(count + 1, getUsersCount()); } @Test public void testAddDomain() { int count = getUsersCount(); try { String user = "aaa00"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map setParams = new HashMap(); setParams.put("name", "aaa00-admin"); setParams.put("password", "test123"); setParams.put("quota", "128"); setParams.put("quotalimit", "192"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams }; Object execute = client.execute(USER_MODULE + ".add", params); if (execute instanceof Map) { Map entry = (Map) execute; assertEquals("aaa00-admin", entry.get("name")); assertEquals("aaa00", entry.get("pac")); assertEquals(null, entry.get("password")); } else { fail("map expected"); } grantingTicketURL = cas.getGrantingTicketURL(user); setParams = new HashMap(); setParams.put("user", "aaa00-admin"); setParams.put("name", "example01.org"); params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams }; execute = client.execute(DOM_MODULE + ".add", params); if (execute instanceof Map) { Map entry = (Map) execute; assertEquals("example01.org", entry.get("name")); assertEquals("aaa00", entry.get("pac")); } else { fail("map expected"); } } catch (XmlRpcException e) { fail(e.getMessage()); } assertEquals(count + 1, getUsersCount()); } private int getMembersCount() { int count = 0; String user = "ad"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map whereParams = new HashMap(); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), whereParams }; Object execute; try { execute = client.execute(CUST_MODULE + ".search", params); Object[] result = (Object[]) execute; count = result.length; } catch (XmlRpcException e) { fail(e.getMessage()); } return count; } private int getPacsCount() { int count = 0; String user = "ad"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map whereParams = new HashMap(); whereParams.put("customer", "hsh00-aaa"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), whereParams }; try { Object execute = client.execute(PAC_MODULE + ".search", params); Object[] result = (Object[]) execute; count = result.length; } catch (XmlRpcException e) { fail(e.getMessage()); } return count; } private int getUsersCount() { int count = -1; try { String user = "aaa00"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map whereParams = new HashMap(); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), whereParams }; Object execute = client.execute(USER_MODULE + ".search", params); Object[] result = (Object[]) execute; count = result.length; } catch (XmlRpcException e) { fail(e.getMessage()); } return count; } }