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

115 lines
3.3 KiB
Java
Raw Permalink Normal View History

2011-04-01 18:53:37 +02:00
package de.hsadmin.remote;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
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 PgsqlUserTest {
private static final String MODULE = "postgresqluser";
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 testCreate() {
int count = getDBsCount();
String user = "aaa00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
setParams.put("name", "aaa00_dba");
setParams.put("password", "geHeimNis");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams };
try {
Object execute = client.execute(MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
2011-05-06 18:28:11 +02:00
setParams.put("name", "aaa00_dba2");
params[1] = cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL());
execute = client.execute(MODULE + ".add", params);
assertTrue(execute instanceof Map<?, ?>);
2011-04-01 18:53:37 +02:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
2011-05-06 18:28:11 +02:00
assertEquals(count + 2, getDBsCount());
2011-04-01 18:53:37 +02:00
}
2011-05-06 18:28:11 +02:00
@Test
public void testDelete() {
int count = getDBsCount();
2011-04-01 18:53:37 +02:00
String user = "aaa00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> whereParams = new HashMap<String, String>();
2011-05-06 18:28:11 +02:00
whereParams.put("name", "aaa00_dba2");
2011-04-01 18:53:37 +02:00
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
try {
2011-05-06 18:28:11 +02:00
Object execute = client.execute(MODULE + ".delete", params);
assertNull(execute);
2011-04-01 18:53:37 +02:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
2011-05-06 18:28:11 +02:00
assertEquals(count - 1, getDBsCount());
2011-04-01 18:53:37 +02:00
}
2012-01-02 14:14:10 +01:00
// @Test
2011-05-06 18:28:11 +02:00
public void testSearch() {
2011-04-01 18:53:37 +02:00
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 };
try {
2011-05-06 18:28:11 +02:00
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
assertEquals(1, result.length);
2011-04-01 18:53:37 +02:00
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
private int getDBsCount() {
int count = 0;
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 };
try {
Object execute = client.execute(MODULE + ".search", params);
Object[] result = (Object[]) execute;
count = result.length;
} catch (XmlRpcException e) {
fail(e.getMessage());
}
return count;
}
}