package de.hsadmin.remote; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; 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; import de.hsadmin.core.util.Config; import de.hsadmin.mods.pac.Pac; public class PacMigrationTest { private static final String MODULE = "pac"; private XmlRpcClient client; private RemoteCASHelper cas; private Config config; @Before public void setUp() throws Exception { client = RemoteTestHelper.getClient(); cas = new RemoteCASHelper(); config = Config.getInstance(); } @After public void tearDown() throws Exception { client = null; cas = null; } @Test public void testCreate() { int count = getPacsCount(); String user = "ad"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map setParams = new HashMap(); setParams.put("name", "aaa04"); setParams.put("hive", "h99"); setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); setParams.put("basepac", Pac.PAC_DW); setParams.put("curinetaddr", "176.9.242.77"); HashMap components = new HashMap(); components.put("QUOTA", "512"); components.put("TRAFFIC", "5"); components.put("DAEMON", "1"); setParams.put("components", components); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams }; try { Object execute = client.execute(MODULE + ".add", params); assertTrue(execute instanceof Map); } catch (XmlRpcException e) { fail(e.getMessage()); } assertEquals(count + 1, getPacsCount()); setParams = new HashMap(); Map whereParams = new HashMap(); setParams.put("password", "test123"); whereParams.put("name", "aaa04"); params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams, whereParams }; try { client.execute("user.update", params); } catch (XmlRpcException e) { fail(e.getMessage()); } } @Test public void testUpdate() { String user = "ad"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map setParams = new HashMap(); Map components = new HashMap(); setParams.put("basepac", Pac.PAC_WEB); setParams.put("components", components); components.put("QUOTA", "1024"); components.put("TRAFFIC", "5"); Map whereParams = new HashMap(); whereParams.put("name", "aaa04"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), setParams, whereParams }; try { Object execute = client.execute(MODULE + ".update", params); assertNotNull(execute); params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), whereParams }; execute = client.execute(MODULE + ".search", params); assertNotNull(execute); assertTrue(execute instanceof Object[]); Object[] untypedResultArray = (Object[]) execute; assertEquals(1, untypedResultArray.length); assertTrue(untypedResultArray[0] instanceof Map); @SuppressWarnings("unchecked") Map pacResultMap = (Map) untypedResultArray[0]; assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac")); } catch (XmlRpcException e) { fail(e.getMessage()); } } private int getPacsCount() { int count = 0; String user = "hsh00-aaa"; String grantingTicketURL = cas.getGrantingTicketURL(user); Map whereParams = new HashMap(); whereParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa"); Object[] params = new Object[] { user, cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()), whereParams }; try { Object execute = client.execute(MODULE + ".search", params); Object[] result = (Object[]) execute; count = result.length; } catch (XmlRpcException e) { fail(e.getMessage()); } return count; } }