2011-03-25 17:47:54 +01:00
|
|
|
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";
|
|
|
|
|
|
|
|
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";
|
2011-03-25 17:47:54 +01:00
|
|
|
int membersCount = -9999;
|
2011-03-30 18:26:43 +02:00
|
|
|
membersCount = getMembersCount();
|
2011-03-25 17:47:54 +01:00
|
|
|
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");
|
2011-03-25 17:47:54 +01:00
|
|
|
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");
|
|
|
|
setParams.put("contact_email", "rainer.mustermann@example.org");
|
|
|
|
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
|
|
|
// Object execute = client.execute(CUST_MODULE + ".add", params);
|
2011-03-25 17:47:54 +01:00
|
|
|
// Map<?, ?> result = (Map<?, ?>) execute;
|
|
|
|
// System.out.println(result);
|
2011-03-30 18:26:43 +02:00
|
|
|
assertEquals(membersCount + 1, getMembersCount());
|
2011-03-25 17:47:54 +01:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAddPac() {
|
|
|
|
int count = getPacsCount();
|
2011-05-05 20:42:58 +02:00
|
|
|
String user = "ad";
|
2011-03-25 17:47:54 +01:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
setParams.put("name", "aaa00");
|
2011-05-05 20:42:58 +02:00
|
|
|
setParams.put("hive", "h81");
|
|
|
|
setParams.put("customer", "hsh00-aaa");
|
2011-03-25 17:47:54 +01:00
|
|
|
setParams.put("basepac", "DW/B");
|
2011-05-05 20:42:58 +02:00
|
|
|
setParams.put("curinetaddr", "192.168.108.201");
|
2011-03-25 17:47:54 +01:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(PAC_MODULE + ".add", params);
|
|
|
|
assertTrue(execute instanceof Map<?, ?>);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count + 1, getPacsCount());
|
|
|
|
}
|
|
|
|
|
2011-03-30 18:26:43 +02:00
|
|
|
@Test
|
|
|
|
public void testDelPac() {
|
|
|
|
int count = getPacsCount();
|
2011-05-05 20:42:58 +02:00
|
|
|
String user = "ad";
|
2011-03-30 18:26:43 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
whereParams.put("name", "aaa00");
|
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
client.execute(PAC_MODULE + ".delete", params);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count - 1, getPacsCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testDelMember() {
|
|
|
|
int count = getMembersCount();
|
2011-05-05 20:42:58 +02:00
|
|
|
String user = "ad";
|
2011-03-30 18:26:43 +02:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2011-05-05 20:42:58 +02:00
|
|
|
whereParams.put("membercode", "hsh00-aaa");
|
2011-03-30 18:26:43 +02:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
client.execute(CUST_MODULE + ".delete", params);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count - 1, getMembersCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getMembersCount() {
|
|
|
|
int count = 0;
|
2011-05-05 20:42:58 +02:00
|
|
|
String user = "ad";
|
2011-03-25 17:47:54 +01: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 };
|
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;
|
2011-03-25 17:47:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getPacsCount() {
|
|
|
|
int count = 0;
|
2011-05-05 20:42:58 +02:00
|
|
|
String user = "ad";
|
2011-03-25 17:47:54 +01:00
|
|
|
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");
|
2011-03-25 17:47:54 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|