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

225 lines
7.1 KiB
Java
Raw Permalink Normal View History

package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
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 InitDataTest {
private static final String CUST_MODULE = "member";
private static final String PAC_MODULE = "pac";
2011-05-05 21:04:14 +02:00
private static final String USER_MODULE = "user";
2012-01-02 13:26:21 +01:00
private static final String DOM_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 testAddMember() {
2011-05-05 20:42:58 +02:00
String user = "ad";
int membersCount = -9999;
2011-03-30 18:26:43 +02:00
membersCount = getMembersCount();
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
2011-05-05 20:42:58 +02:00
setParams.put("membercode", "hsh00-aaa");
setParams.put("password", "geheimnIs");
setParams.put("memberno", "20001");
setParams.put("membersince", "01.10.2010");
setParams.put("contact_salut", "Herr");
setParams.put("contact_title", "Dr.");
setParams.put("contact_firstname", "Ömer Günther");
setParams.put("contact_lastname", "Janßen-Müller");
setParams.put("contact_salut", "Herr");
setParams.put("contact_street", "Hauptstr. 1");
setParams.put("contact_zipcode", "99998");
setParams.put("contact_city", "Musterstadt");
setParams.put("contact_country", "D");
setParams.put("contact_phone_private", "+49 9999 123456");
2011-08-03 19:05:20 +02:00
setParams.put("contact_email", "test@ostwall195.de");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
try {
client.execute(CUST_MODULE + ".add", params);
2011-03-30 18:26:43 +02:00
assertEquals(membersCount + 1, getMembersCount());
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testAddPac() {
int count = getPacsCount();
2011-05-05 20:42:58 +02:00
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "aaa00");
2012-04-05 16:58:34 +02:00
setParams.put("hive", "h99");
2011-05-05 20:42:58 +02:00
setParams.put("customer", "hsh00-aaa");
setParams.put("basepac", "DW/B");
2012-04-05 20:45:52 +02:00
setParams.put("curinetaddr", "176.9.242.74");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
try {
Object execute = client.execute(PAC_MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
2012-06-12 15:27:10 +02:00
cas.setPassword(client, "aaa00");
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count + 1, getPacsCount());
}
2011-03-30 18:26:43 +02:00
@Test
2011-05-05 21:04:14 +02:00
public void testAddUser() {
int count = getUsersCount();
try {
String user = "aaa00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "aaa00-test2");
setParams.put("password", "test123");
setParams.put("quota", "128");
setParams.put("quotalimit", "192");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
Object execute = client.execute(USER_MODULE + ".add", params);
if (execute instanceof Map<?, ?>) {
Map<?, ?> entry = (Map<?, ?>) execute;
assertEquals("aaa00-test2", entry.get("name"));
assertEquals("aaa00", entry.get("pac"));
assertEquals(null, entry.get("password"));
} else {
fail("map expected");
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count + 1, getUsersCount());
}
2012-01-02 13:26:21 +01:00
@Test
public void testAddDomain() {
int count = getUsersCount();
try {
String user = "aaa00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "aaa00-admin");
setParams.put("password", "test123");
setParams.put("quota", "128");
setParams.put("quotalimit", "192");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
Object execute = client.execute(USER_MODULE + ".add", params);
if (execute instanceof Map<?, ?>) {
Map<?, ?> entry = (Map<?, ?>) execute;
2012-01-02 13:37:52 +01:00
assertEquals("aaa00-admin", entry.get("name"));
2012-01-02 13:26:21 +01:00
assertEquals("aaa00", entry.get("pac"));
assertEquals(null, entry.get("password"));
} else {
fail("map expected");
}
grantingTicketURL = cas.getGrantingTicketURL(user);
setParams = new HashMap<String, String>();
setParams.put("user", "aaa00-admin");
setParams.put("name", "example01.org");
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
execute = client.execute(DOM_MODULE + ".add", params);
if (execute instanceof Map<?, ?>) {
Map<?, ?> entry = (Map<?, ?>) execute;
assertEquals("example01.org", entry.get("name"));
assertEquals("aaa00", entry.get("pac"));
} else {
fail("map expected");
}
} catch (XmlRpcException e) {
fail(e.getMessage());
}
assertEquals(count + 1, getUsersCount());
}
2011-03-30 18:26:43 +02:00
private int getMembersCount() {
int count = 0;
2011-05-05 20:42:58 +02:00
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
2011-03-30 18:26:43 +02:00
Object execute;
try {
execute = client.execute(CUST_MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
private int getPacsCount() {
int count = 0;
2011-05-05 20:42:58 +02:00
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
2011-05-05 20:42:58 +02:00
whereParams.put("customer", "hsh00-aaa");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
try {
Object execute = client.execute(PAC_MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
2011-05-05 21:04:14 +02:00
private int getUsersCount() {
int count = -1;
try {
String user = "aaa00";
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(USER_MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
}