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

157 lines
4.7 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.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.UnknownHostException;
2010-10-05 21:42:07 +02:00
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 DomainTest {
private static final String MODULE = "domain";
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
2014-03-21 16:24:46 +01:00
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(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 16:07:48 +01:00
assertTrue("aaa00".equals(row.get("user")) || "aaa00-admin".equals(row.get("user")));
2010-10-05 21:42:07 +02:00
} else {
fail("map expected");
}
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
2014-03-21 16:24:46 +01:00
public void testUpdate() {
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> setParams = new HashMap<String, String>();
Map<String, String> whereParams = new HashMap<String, String>();
2012-01-02 15:13:43 +01:00
setParams.put("user", "aaa00");
whereParams.put("name", "example01.org");
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);
assertNotNull(execute);
fail("exception expected");
} catch (XmlRpcException e) {
}
}
@Test
2014-03-21 16:24:46 +01:00
public void testCreate() throws UnknownHostException, IOException {
2010-10-05 21:42:07 +02:00
int count = getDomsCount();
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> setParams = new HashMap<String, String>();
2014-03-21 15:20:25 +01:00
setParams.put("name", "f8n.de");
2012-01-02 15:19:56 +01:00
setParams.put("user", "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, getDomsCount());
}
2013-06-19 16:32:57 +02:00
@Test
2014-03-21 16:24:46 +01:00
public void testCreateForeignSubdomain() throws UnknownHostException, IOException {
2013-06-19 16:32:57 +02:00
int count = getDomsCount();
2014-03-21 15:20:25 +01:00
String user = "aaa00";
2013-06-19 16:32:57 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
2014-03-21 15:20:25 +01:00
setParams.put("name", "f6n.de");
setParams.put("user", "aaa00-admin");
2013-06-19 16:32:57 +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());
}
2014-03-21 15:20:25 +01:00
assertEquals(count + 1, getDomsCount());
count = getDomsCount();
user = "aaa01";
grantingTicketURL = cas.getGrantingTicketURL(user);
setParams = new HashMap<String, String>();
setParams.put("name", "subdomain.f6n.de");
setParams.put("user", "aaa01");
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2014-03-21 15:20:25 +01:00
setParams };
try {
2014-03-21 15:20:25 +01:00
Object execute = client.execute(MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
fail("should throw exception");
} catch (XmlRpcException e) {
2014-03-21 15:20:25 +01:00
assertEquals(count, getDomsCount());
}
}
2010-10-05 21:42:07 +02:00
private int getDomsCount() {
int count = 0;
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 };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
}