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.assertNull;
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
2012-07-18 13:53:41 +02:00
|
|
|
import java.util.ArrayList;
|
2010-10-05 21:42:07 +02:00
|
|
|
import java.util.HashMap;
|
2012-07-18 13:53:41 +02:00
|
|
|
import java.util.List;
|
2010-10-05 21:42:07 +02:00
|
|
|
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
|
|
|
|
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;
|
2012-01-02 15:41:11 +01:00
|
|
|
assertEquals(2, result.length);
|
2010-10-05 21:42:07 +02:00
|
|
|
for (Object o : result) {
|
|
|
|
if (o instanceof Map<?, ?>) {
|
|
|
|
Map<?, ?> row = (Map<?, ?>) o;
|
2012-04-05 18:29:41 +02:00
|
|
|
// assertEquals("aaa00", row.get("user"));
|
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
|
|
|
|
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) {
|
|
|
|
// System.out.println(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreate() {
|
|
|
|
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>();
|
|
|
|
setParams.put("name", "f6n.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());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDelete() {
|
|
|
|
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> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "f6n.de");
|
|
|
|
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, getDomsCount());
|
|
|
|
}
|
|
|
|
|
2012-07-18 13:24:46 +02:00
|
|
|
@Test
|
2012-07-18 13:53:41 +02:00
|
|
|
public void testInvalidOption() {
|
2012-07-18 13:24:46 +02:00
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
2012-07-18 13:53:41 +02:00
|
|
|
Map<String, Object> setParams = new HashMap<String, Object>();
|
2012-07-18 13:24:46 +02:00
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2012-07-18 16:49:31 +02:00
|
|
|
// setParams.put("user", "aaa00");
|
2012-07-18 13:53:41 +02:00
|
|
|
List<String> optionslist = new ArrayList<String>();
|
|
|
|
optionslist.add("invalide");
|
|
|
|
setParams.put("domainoptions", optionslist);
|
2012-07-18 13:24:46 +02:00
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
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) {
|
2012-07-18 14:11:08 +02:00
|
|
|
assertEquals(getDomOptionsCount(),0);
|
2012-07-18 13:24:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 13:53:41 +02:00
|
|
|
@Test
|
|
|
|
public void testOneValidOption() {
|
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, Object> setParams = new HashMap<String, Object>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2012-07-18 16:49:31 +02:00
|
|
|
// setParams.put("user", "aaa00");
|
2012-07-18 13:53:41 +02:00
|
|
|
List<String> optionslist = new ArrayList<String>();
|
|
|
|
optionslist.add("graylisting");
|
|
|
|
setParams.put("domainoptions", optionslist);
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
2012-07-18 14:11:08 +02:00
|
|
|
assertEquals(getDomOptionsCount(),1);
|
2012-07-18 13:53:41 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testTwoValidOptions() {
|
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, Object> setParams = new HashMap<String, Object>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2012-07-18 16:49:31 +02:00
|
|
|
// setParams.put("user", "aaa00");
|
2012-07-18 13:53:41 +02:00
|
|
|
List<String> optionslist = new ArrayList<String>();
|
|
|
|
optionslist.add("htdocsfallback");
|
|
|
|
optionslist.add("graylisting");
|
|
|
|
setParams.put("domainoptions", optionslist);
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
2012-07-18 14:11:08 +02:00
|
|
|
assertEquals(getDomOptionsCount(),2);
|
2012-07-18 13:53:41 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-18 15:31:58 +02:00
|
|
|
@Test
|
|
|
|
public void testZeroOptions() {
|
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, Object> setParams = new HashMap<String, Object>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
setParams.put("user", "aaa00");
|
|
|
|
List<String> optionslist = new ArrayList<String>();
|
|
|
|
setParams.put("domainoptions", optionslist);
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
|
|
|
assertEquals(getDomOptionsCount(),0);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-18 14:11:08 +02:00
|
|
|
private int getDomOptionsCount() {
|
|
|
|
int count = 0;
|
|
|
|
String user = "aaa00";
|
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "example01.org");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
2012-07-18 14:51:07 +02:00
|
|
|
assertEquals(result.length, 1);
|
2012-07-18 16:49:31 +02:00
|
|
|
assertTrue(result[0] instanceof Map<?, ?>);
|
2012-07-18 14:51:07 +02:00
|
|
|
Map<String, ?> domainMap = (Map<String, ?>) result[0];
|
|
|
|
assertNotNull(domainMap);
|
|
|
|
List<?> optsList = (List<?>)domainMap.get("domainsoptions");
|
|
|
|
assertNotNull(optsList);
|
|
|
|
count = optsList.size();
|
2012-07-18 14:11:08 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-10-05 21:42:07 +02:00
|
|
|
}
|