hs.hsadmin/hsarback/test/de/hsadmin/remote/QueueTaskTest.java

126 lines
3.6 KiB
Java
Raw Permalink Normal View History

2010-10-01 21:42:49 +02:00
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;
public class QueueTaskTest {
private static final String MODULE = "q";
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";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
2010-10-04 19:44:49 +02:00
assertTrue(result.length > 20);
2010-10-01 21:42:49 +02:00
for (Object o : result) {
if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o;
assertEquals("peh00", ((String) row.get("user")).substring(0, 5));
} else {
fail("map expected");
}
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testUpdate() {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> setParams = new HashMap<String, String>();
Map<String, String> whereParams = new HashMap<String, String>();
setParams.put("details", "Test");
whereParams.put("user", "peh00");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
setParams, whereParams };
try {
Object execute = client.execute(MODULE + ".update", params);
assertNotNull(execute);
fail("exception expected");
} catch (XmlRpcException e) {
// System.out.println(e.getMessage());
}
}
@Test
public void testCreateFails() {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("status", "done");
setParams.put("title", "Test");
setParams.put("user", "peh00");
setParams.put("hive", "h05");
setParams.put("started", "03.03.2010");
setParams.put("finished", "03.03.2010");
setParams.put("details", "Blupp");
setParams.put("exception", "f6n");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
setParams };
try {
Object execute = client.execute(MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
fail("exception expected");
} catch (XmlRpcException e) {
// System.out.println(e.getMessage());
}
}
@Test
public void testDeleteAsPacAdminFails() {
String user = "peh00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
2010-10-01 21:42:49 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("user", "peh00");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-01 21:42:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".delete", params);
assertTrue(execute instanceof Map<?, ?>);
fail("exception expected");
} catch (XmlRpcException e) {
// System.out.println(e.getMessage());
}
}
}