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

267 lines
8.3 KiB
Java
Raw Permalink Normal View History

2010-10-05 21:42:07 +02:00
package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
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 EMailAddressTest {
private static final String MODULE = "emailaddress";
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() {
2011-05-06 18:28:11 +02:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
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;
2014-03-21 16:24:46 +01:00
assertTrue(6 <= result.length);
2010-10-05 21:42:07 +02:00
for (Object o : result) {
if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o;
2011-05-06 18:28:11 +02:00
assertEquals("aaa00", row.get("pac"));
2010-10-05 21:42:07 +02:00
} else {
fail("map expected");
}
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsPacAdmin() {
2011-05-06 18:28:11 +02:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
2012-01-02 15:13:43 +01:00
whereParams.put("domain", "example01.org");
2010-10-05 21:42:07 +02:00
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
2012-01-02 15:41:11 +01:00
assertEquals(3, result.length);
2010-10-05 21:42:07 +02:00
for (Object o : result) {
if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o;
2011-05-06 18:28:11 +02:00
assertEquals("aaa00", row.get("pac"));
2010-10-05 21:42:07 +02:00
} else {
fail("map expected");
}
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testUpdate() {
int count = getTargetCount();
2011-05-06 18:28:11 +02:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, Object> setParams = new HashMap<String, Object>();
2010-10-05 21:42:07 +02:00
Map<String, String> whereParams = new HashMap<String, String>();
setParams.put("target", new String[] { "aaa00-test2" });
2012-01-02 15:27:42 +01:00
whereParams.put("domain", "example01.org");
whereParams.put("localpart", "webmaster");
2010-10-05 21:42:07 +02:00
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
Object execute = client.execute(MODULE + ".update", params);
Object[] result = (Object[]) execute;
assertEquals(1, result.length);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count + 1, getTargetCount());
setParams = new HashMap<String, Object>();
2010-10-05 21:42:07 +02:00
whereParams = new HashMap<String, String>();
setParams.put("target", new String[] { "aaa00-admin" });
2012-01-02 15:27:42 +01:00
whereParams.put("domain", "example01.org");
whereParams.put("localpart", "webmaster");
2010-10-05 21:42:07 +02:00
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
Object execute = client.execute(MODULE + ".update", params);
Object[] result = (Object[]) execute;
assertEquals(1, result.length);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count, getTargetCount());
}
@Test
public void testSearchAsDomAdmin() {
2012-01-02 15:13:43 +01:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
2012-01-02 15:13:43 +01:00
whereParams.put("domain", "example01.org");
2012-01-02 15:41:11 +01:00
whereParams.put("admin", "aaa00-admin");
2010-10-05 21:42:07 +02:00
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
2012-01-02 15:41:11 +01:00
assertEquals(3, result.length);
2010-10-05 21:42:07 +02:00
for (Object o : result) {
if (o instanceof Map<?, ?>) {
Map<?, ?> row = (Map<?, ?>) o;
2012-01-02 15:41:11 +01:00
assertEquals("aaa00-admin", row.get("admin"));
2010-10-05 21:42:07 +02:00
} else {
fail("map expected");
}
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testCreateAsPacAdminFails() {
int count = getObjectCount();
2012-01-02 15:13:43 +01:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, Object> setParams = new HashMap<String, Object>();
2010-10-05 21:42:07 +02:00
setParams.put("localpart", "f6n");
2012-04-05 18:29:41 +02:00
setParams.put("domain", "example02.org");
setParams.put("target", new String[] { "aaa00" });
2010-10-05 21:42:07 +02:00
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
try {
Object execute = client.execute(MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
fail("exception expected");
} catch (XmlRpcException e) {
}
assertEquals(count, getObjectCount());
}
@Test
public void testCreateAndDelete() {
int count = getObjectCount();
2012-01-02 15:13:43 +01:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, Object> setParams = new HashMap<String, Object>();
2010-10-05 21:42:07 +02:00
setParams.put("localpart", "f6n");
2012-01-02 15:13:43 +01:00
setParams.put("domain", "example01.org");
setParams.put("target", new String[] { "aaa00-admin" } );
2010-10-05 21:42:07 +02:00
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, getObjectCount());
count = getObjectCount();
2010-12-17 18:39:53 +01:00
Map<String, Object> whereParams = new HashMap<String, Object>();
2010-10-05 21:42:07 +02:00
whereParams.put("localpart", "f6n");
2012-01-02 15:13:43 +01:00
whereParams.put("domain", "example01.org");
2010-10-05 21:42:07 +02:00
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
try {
2010-12-17 18:39:53 +01:00
Object execute = client.execute(MODULE + ".search", params);
assertTrue(execute instanceof Object[]);
whereParams = new HashMap<String, Object>();
Object[] resArray = (Object[]) execute;
assertEquals(1, resArray.length);
Object res = resArray[0];
2011-03-22 23:02:06 +01:00
if (res instanceof Map<?, ?>) {
Map<?, ?> map = (Map<?, ?>) res;
Object idVal = map.get("id");
whereParams.put("id", idVal);
} else {
fail("unexpected type");
}
2010-12-17 18:39:53 +01:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
try {
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
2010-10-05 21:42:07 +02:00
Object execute = client.execute(MODULE + ".delete", params);
assertNull(execute);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count - 1, getObjectCount());
}
private int getObjectCount() {
int count = -1;
try {
2012-01-02 15:13:43 +01:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
private int getTargetCount() {
int count = -1;
try {
2012-01-02 15:13:43 +01:00
String user = "aaa00";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
2012-01-02 15:41:11 +01:00
whereParams.put("target", "aaa00-test2");
2010-10-05 21:42:07 +02:00
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
}