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;
|
2011-03-22 23:02:06 +01:00
|
|
|
assertEquals(242, 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>();
|
|
|
|
whereParams.put("domain", "herzensklaenge.de");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
|
|
|
assertEquals(2, result.length);
|
|
|
|
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, String> setParams = new HashMap<String, String>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2011-05-06 18:28:11 +02:00
|
|
|
setParams.put("target", "aaa00-test2");
|
2010-10-05 21:42:07 +02:00
|
|
|
whereParams.put("domain", "jalin.de");
|
|
|
|
whereParams.put("localpart", "fax");
|
|
|
|
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, String>();
|
|
|
|
whereParams = new HashMap<String, String>();
|
2011-05-06 18:28:11 +02:00
|
|
|
setParams.put("target", "aaa00-test2");
|
2010-10-05 21:42:07 +02:00
|
|
|
whereParams.put("domain", "jalin.de");
|
|
|
|
whereParams.put("localpart", "fax");
|
|
|
|
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() {
|
|
|
|
String user = "peh00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("domain", "herzensklaenge.de");
|
|
|
|
whereParams.put("admin", "peh00");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
|
|
|
assertEquals(2, result.length);
|
|
|
|
for (Object o : result) {
|
|
|
|
if (o instanceof Map<?, ?>) {
|
|
|
|
Map<?, ?> row = (Map<?, ?>) o;
|
|
|
|
assertEquals("peh00", row.get("admin"));
|
|
|
|
} else {
|
|
|
|
fail("map expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreateAsPacAdminFails() {
|
|
|
|
int count = getObjectCount();
|
|
|
|
String user = "peh00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
setParams.put("localpart", "f6n");
|
|
|
|
setParams.put("domain", "f6n.de");
|
|
|
|
setParams.put("target", "peh00-phor");
|
|
|
|
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();
|
|
|
|
String user = "peh00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
setParams.put("localpart", "f6n");
|
|
|
|
setParams.put("domain", "jalin.de");
|
|
|
|
setParams.put("target", "peh00-phor");
|
|
|
|
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");
|
|
|
|
whereParams.put("domain", "jalin.de");
|
|
|
|
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 {
|
|
|
|
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 };
|
|
|
|
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 {
|
|
|
|
String user = "peh00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("target", "peh00-phor");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|