2011-03-22 23:02:06 +01:00
|
|
|
package de.hsadmin.remote;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
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 PacTest {
|
|
|
|
|
|
|
|
private static final String MODULE = "pac";
|
|
|
|
|
|
|
|
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 testSearchAllAsPacAdmin() {
|
|
|
|
String user = "peh00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
|
|
|
assertEquals(1, result.length);
|
|
|
|
for (Object o : result) {
|
|
|
|
if (o instanceof Map<?, ?>) {
|
|
|
|
Map<?, ?> row = (Map<?, ?>) o;
|
|
|
|
assertEquals("hsh00-peh", row.get("customer"));
|
|
|
|
} else {
|
|
|
|
fail("map expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUpdate() {
|
|
|
|
String user = "peh00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
setParams.put("curinetaddr", "192.168.10.2");
|
|
|
|
whereParams.put("name", "peh00");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
|
|
|
fail("exception expected");
|
|
|
|
} catch (XmlRpcException e) {
|
2011-03-23 16:49:58 +01:00
|
|
|
|
2011-03-22 23:02:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreate() {
|
|
|
|
int count = getPacsCount();
|
|
|
|
String user = "pe";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
setParams.put("name", "peh07");
|
|
|
|
setParams.put("hive", "h05");
|
|
|
|
setParams.put("customer", "hsh00-peh");
|
|
|
|
setParams.put("basepac", "DW/S");
|
|
|
|
setParams.put("curinetaddr", "212.42.230.178");
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDelete() {
|
|
|
|
int count = getPacsCount();
|
|
|
|
String user = "pe";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "peh07");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".delete", params);
|
|
|
|
assertNull(execute);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count - 1, getPacsCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getPacsCount() {
|
|
|
|
int count = 0;
|
|
|
|
String user = "pe";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("customer", "hsh00-peh");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|