199 lines
6.1 KiB
Java
199 lines
6.1 KiB
Java
|
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() {
|
||
|
String user = "pe";
|
||
|
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");
|
||
|
setParams.put("memberno", "20001");
|
||
|
setParams.put("membersince", "01.10.2010");
|
||
|
setParams.put("contact_salut", "Herr");
|
||
|
setParams.put("contact_title", "Dr.");
|
||
|
setParams.put("contact_firstname", "Rainer");
|
||
|
setParams.put("contact_lastname", "Mustermann");
|
||
|
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.BACKEND_URL),
|
||
|
setParams };
|
||
|
try {
|
||
|
client.execute(MODULE + ".add", params);
|
||
|
// Object execute = client.execute(MODULE + ".add", params);
|
||
|
// Map<?, ?> result = (Map<?, ?>) execute;
|
||
|
// System.out.println(result);
|
||
|
assertEquals(membersCount + 1, getMembersCount(user));
|
||
|
} catch (XmlRpcException e) {
|
||
|
fail(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testSearchAsHostmaster() {
|
||
|
String user = "pe";
|
||
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
||
|
Map<String, String> whereParams = new HashMap<String, String>();
|
||
|
Object[] params = new Object[] { user,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
whereParams };
|
||
|
try {
|
||
|
Object execute = client.execute(MODULE + ".search", params);
|
||
|
Object[] result = (Object[]) execute;
|
||
|
assertTrue(result.length > 100);
|
||
|
} 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,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
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,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
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,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
whereParams };
|
||
|
try {
|
||
|
Object execute = client.execute(MODULE + ".search", params);
|
||
|
Object[] result = (Object[]) execute;
|
||
|
assertTrue(result.length == 1);
|
||
|
} catch (XmlRpcException e) {
|
||
|
fail(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testDeleteAsMember() {
|
||
|
String user = "hsh00-aaa";
|
||
|
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,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
whereParams };
|
||
|
try {
|
||
|
client.execute(MODULE + ".delete", params);
|
||
|
assertEquals(membersCount - 1, getMembersCount(user));
|
||
|
} catch (XmlRpcException e) {
|
||
|
fail(e.getMessage());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Test
|
||
|
public void testDeleteAsHostmaster() {
|
||
|
String user = "pe";
|
||
|
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,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
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,
|
||
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.BACKEND_URL),
|
||
|
whereParams };
|
||
|
Object execute = client.execute(MODULE + ".search", params);
|
||
|
Object[] result = (Object[]) execute;
|
||
|
return result.length;
|
||
|
}
|
||
|
}
|