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>();
|
|
|
|
setParams.put("membercode", "hsh00-aaa");
|
2010-10-05 21:42:07 +02:00
|
|
|
setParams.put("password", "geheimnIs");
|
2010-10-04 19:44:49 +02:00
|
|
|
setParams.put("memberno", "20001");
|
|
|
|
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_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,
|
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-05-05 20:12:04 +02:00
|
|
|
for (int idx=11; idx < 99; idx++) {
|
|
|
|
setParams.put("membercode", "hsh00-n" + idx);
|
|
|
|
setParams.put("memberno", "200" + idx);
|
2011-05-05 20:16:33 +02:00
|
|
|
setParams.put("contact_street", "Hauptstr. " + idx);
|
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;
|
2011-05-05 20:12:04 +02:00
|
|
|
assertTrue(result.length > 98);
|
2010-10-04 19:44:49 +02:00
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSearchAsPacAdmin() {
|
|
|
|
String user = "peh00";
|
|
|
|
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() {
|
|
|
|
String user = "peh00-phor";
|
|
|
|
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() {
|
|
|
|
String user = "hsh00-peh";
|
|
|
|
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 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|