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

254 lines
8.1 KiB
Java
Raw Permalink Normal View History

2010-10-04 19:44:49 +02: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 CustomerTest {
private static final String MODULE = "member";
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 testAddAsHostmaster() {
2011-05-05 20:12:04 +02:00
String user = "ad";
2010-10-04 19:44:49 +02:00
int membersCount = -9999;
try {
membersCount = getMembersCount(user);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
2011-05-05 21:09:15 +02:00
setParams.put("membercode", "hsh00-abc");
2010-10-05 21:42:07 +02:00
setParams.put("password", "geheimnIs");
2011-05-05 21:09:15 +02:00
setParams.put("memberno", "20002");
2010-10-04 19:44:49 +02:00
setParams.put("membersince", "01.10.2010");
setParams.put("contact_salut", "Herr");
setParams.put("contact_title", "Dr.");
2010-10-05 21:42:07 +02:00
setParams.put("contact_firstname", "Ömer Günther");
setParams.put("contact_lastname", "Janßen-Müller");
2010-10-04 19:44:49 +02:00
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,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
setParams };
try {
client.execute(MODULE + ".add", params);
assertEquals(membersCount + 1, getMembersCount(user));
2011-07-14 18:20:15 +02:00
for (int idx=11; idx < 12; idx++) {
2011-05-05 20:12:04 +02:00
setParams.put("membercode", "hsh00-n" + idx);
setParams.put("memberno", "200" + idx);
2011-05-05 20:42:58 +02:00
setParams.put("contact_street", "Hauptstr. " + idx);
params[1] = cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL());
2011-05-05 20:12:04 +02:00
client.execute(MODULE + ".add", params);
}
2010-10-04 19:44:49 +02:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsHostmaster() {
2011-05-05 20:12:04 +02:00
String user = "ad";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length > 2);
2010-10-04 19:44:49 +02:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsPacAdmin() {
2011-05-05 21:04:14 +02:00
String user = "aaa00";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length == 0);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsPacUser() {
2011-05-05 21:04:14 +02:00
String user = "aaa00-test2";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length == 0);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testSearchAsMember() {
2011-05-05 21:04:14 +02:00
String user = "hsh00-aaa";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertTrue(result.length == 1);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
2010-10-05 21:42:07 +02:00
public void testUpdateAsMember() {
2010-10-04 19:44:49 +02:00
String user = "hsh00-aaa";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Map<String, String> setParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
setParams.put("contact_firstname", "Hugo");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
2010-10-04 19:44:49 +02:00
try {
2010-10-05 21:42:07 +02:00
client.execute(MODULE + ".update", params);
fail("exception erwartet");
} catch (XmlRpcException e) {
// Exception erwartet
}
}
@Test
public void testUpdateAsHostmaster() {
2011-05-05 20:12:04 +02:00
String user = "ad";
2010-10-05 21:42:07 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Map<String, String> setParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
setParams.put("contact_title", "Prof.");
setParams.put("membersince", "Hugo");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
client.execute(MODULE + ".update", params);
2010-10-04 19:44:49 +02:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
2010-10-05 21:42:07 +02:00
}
@Test
public void testUpdateAsHostmasterSharesSigned() {
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Map<String, String> setParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
setParams.put("sharessigned", "1");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
client.execute(MODULE + ".update", params);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
2010-10-05 21:42:07 +02:00
@Test
public void testDeleteAsMember() {
String user = "hsh00-aaa";
2010-10-04 19:44:49 +02:00
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
try {
client.execute(MODULE + ".delete", params);
2010-10-05 21:42:07 +02:00
fail("exception erwartet");
2010-10-04 19:44:49 +02:00
} catch (XmlRpcException e) {
2010-10-05 21:42:07 +02:00
// Exception erwartet
2010-10-04 19:44:49 +02:00
}
}
2013-05-23 11:27:59 +02:00
// TODO needs update of memberuntil
// @Test
2010-10-04 19:44:49 +02:00
public void testDeleteAsHostmaster() {
2011-05-05 20:12:04 +02:00
String user = "ad";
2010-10-04 19:44:49 +02:00
int membersCount = -9999;
try {
membersCount = getMembersCount(user);
} catch (XmlRpcException e) {
fail(e.getMessage());
}
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
whereParams.put("membercode", "hsh00-aaa");
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
try {
client.execute(MODULE + ".delete", params);
assertEquals(membersCount - 1, getMembersCount(user));
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
private int getMembersCount(String user) throws XmlRpcException {
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
Object[] params = new Object[] { user,
2010-10-05 21:42:07 +02:00
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
2010-10-04 19:44:49 +02:00
whereParams };
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
return result.length;
}
}