2011-03-22 23:02:06 +01:00
|
|
|
package de.hsadmin.remote;
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNotNull;
|
|
|
|
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;
|
|
|
|
|
2011-03-30 18:26:43 +02:00
|
|
|
import de.hsadmin.core.util.Config;
|
2013-04-25 13:01:16 +02:00
|
|
|
import de.hsadmin.mods.pac.Pac;
|
2011-03-30 18:26:43 +02:00
|
|
|
|
2011-03-22 23:02:06 +01:00
|
|
|
public class PacTest {
|
|
|
|
|
|
|
|
private static final String MODULE = "pac";
|
|
|
|
|
|
|
|
private XmlRpcClient client;
|
|
|
|
private RemoteCASHelper cas;
|
2011-03-30 18:26:43 +02:00
|
|
|
private Config config;
|
2011-03-22 23:02:06 +01:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
client = RemoteTestHelper.getClient();
|
|
|
|
cas = new RemoteCASHelper();
|
2011-03-30 18:26:43 +02:00
|
|
|
config = Config.getInstance();
|
2011-03-22 23:02:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@After
|
|
|
|
public void tearDown() throws Exception {
|
|
|
|
client = null;
|
|
|
|
cas = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSearchAllAsPacAdmin() {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
2011-03-22 23:02:06 +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 };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".search", params);
|
|
|
|
Object[] result = (Object[]) execute;
|
|
|
|
assertEquals(1, result.length);
|
|
|
|
for (Object o : result) {
|
|
|
|
if (o instanceof Map<?, ?>) {
|
|
|
|
Map<?, ?> row = (Map<?, ?>) o;
|
2011-03-30 18:26:43 +02:00
|
|
|
assertEquals(config.getProperty("accountprefix.customer") + "-aaa", row.get("customer"));
|
2011-03-22 23:02:06 +01:00
|
|
|
} else {
|
|
|
|
fail("map expected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUpdate() {
|
2011-03-30 18:26:43 +02:00
|
|
|
String user = "aaa00";
|
2011-03-22 23:02:06 +01:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> setParams = new HashMap<String, String>();
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2012-04-05 20:45:52 +02:00
|
|
|
setParams.put("curinetaddr", "176.9.242.75");
|
2011-03-30 18:26:43 +02:00
|
|
|
whereParams.put("name", "aaa00");
|
2011-03-22 23:02:06 +01:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".update", params);
|
|
|
|
assertNotNull(execute);
|
|
|
|
fail("exception expected");
|
|
|
|
} catch (XmlRpcException e) {
|
2011-03-23 16:49:58 +01:00
|
|
|
|
2011-03-22 23:02:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testCreate() {
|
|
|
|
int count = getPacsCount();
|
2011-05-06 16:54:43 +02:00
|
|
|
String user = "ad";
|
2011-03-22 23:02:06 +01:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
2013-01-21 13:35:31 +01:00
|
|
|
Map<String, Object> setParams = new HashMap<String, Object>();
|
2011-03-30 18:26:43 +02:00
|
|
|
setParams.put("name", "aaa01");
|
2012-04-05 16:58:34 +02:00
|
|
|
setParams.put("hive", "h99");
|
2011-03-30 18:26:43 +02:00
|
|
|
setParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
|
2013-04-25 13:01:16 +02:00
|
|
|
setParams.put("basepac", Pac.PAC_WEB_BASE);
|
2012-04-05 20:45:52 +02:00
|
|
|
setParams.put("curinetaddr", "176.9.242.76");
|
2013-01-21 13:35:31 +01:00
|
|
|
HashMap<String, String> components = new HashMap<String, String>();
|
|
|
|
components.put("QUOTA", "512");
|
2013-04-12 12:56:53 +02:00
|
|
|
components.put("TRAFFIC", "5");
|
|
|
|
components.put("DAEMON", "1");
|
2013-01-21 13:35:31 +01:00
|
|
|
setParams.put("components", components);
|
2011-03-22 23:02:06 +01:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".add", params);
|
|
|
|
assertTrue(execute instanceof Map<?, ?>);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count + 1, getPacsCount());
|
2013-01-21 13:35:31 +01:00
|
|
|
setParams = new HashMap<String, Object>();
|
2012-07-20 12:16:15 +02:00
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
|
|
|
setParams.put("password", "test123");
|
|
|
|
whereParams.put("name", "aaa01");
|
|
|
|
params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
setParams, whereParams };
|
|
|
|
try {
|
|
|
|
client.execute("user.update", params);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
2011-03-22 23:02:06 +01:00
|
|
|
}
|
|
|
|
|
2012-07-19 17:32:54 +02:00
|
|
|
// @Test
|
2011-03-22 23:02:06 +01:00
|
|
|
public void testDelete() {
|
|
|
|
int count = getPacsCount();
|
2011-05-06 16:54:43 +02:00
|
|
|
String user = "ad";
|
2011-03-22 23:02:06 +01:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2011-03-30 18:26:43 +02:00
|
|
|
whereParams.put("name", "aaa01");
|
2011-03-22 23:02:06 +01:00
|
|
|
Object[] params = new Object[] { user,
|
|
|
|
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
|
|
|
|
whereParams };
|
|
|
|
try {
|
|
|
|
Object execute = client.execute(MODULE + ".delete", params);
|
|
|
|
assertNull(execute);
|
|
|
|
} catch (XmlRpcException e) {
|
|
|
|
fail(e.getMessage());
|
|
|
|
}
|
|
|
|
assertEquals(count - 1, getPacsCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getPacsCount() {
|
|
|
|
int count = 0;
|
2011-05-06 16:54:43 +02:00
|
|
|
String user = "hsh00-aaa";
|
2011-03-22 23:02:06 +01:00
|
|
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
|
|
|
Map<String, String> whereParams = new HashMap<String, String>();
|
2011-03-30 18:26:43 +02:00
|
|
|
whereParams.put("customer", config.getProperty("accountprefix.customer") + "-aaa");
|
2011-03-22 23:02:06 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|