From 26950ec96d7fa801c9b080c9c02ce95632f2d489 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 25 Apr 2013 13:34:53 +0200 Subject: [PATCH] clean database in ci tests --- .../remote/ContinuousIntegrationTest.java | 3 +- .../de/hsadmin/remote/DatabaseCleanTest.java | 82 +++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 hsarback/test/de/hsadmin/remote/DatabaseCleanTest.java diff --git a/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java b/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java index 2e2c322..7fdf00b 100644 --- a/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java +++ b/hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java @@ -16,7 +16,8 @@ import org.junit.runners.Suite; EMailAliasTest.class, DomainTest.class, EMailAddressTest.class, - SSLCertDomainTest.class + SSLCertDomainTest.class, + DatabaseCleanTest.class // CustomerTest.class, // LongCustomerNameTest.class, // QueueTaskTest.class diff --git a/hsarback/test/de/hsadmin/remote/DatabaseCleanTest.java b/hsarback/test/de/hsadmin/remote/DatabaseCleanTest.java new file mode 100644 index 0000000..039e31e --- /dev/null +++ b/hsarback/test/de/hsadmin/remote/DatabaseCleanTest.java @@ -0,0 +1,82 @@ +package de.hsadmin.remote; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +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 DatabaseCleanTest { + + private static final String MODULE_MYSQL_DB = "mysqldb"; + private static final String MODULE_PGSQL_DB = "postgresqldb"; + private static final String MODULE_MYSQL_USER = "mysqluser"; + private static final String MODULE_PGSQL_USER = "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 testDelete() { + delete(MODULE_MYSQL_DB, "aaa00_db1"); + delete(MODULE_PGSQL_DB, "aaa00_db2"); + delete(MODULE_MYSQL_USER, "aaa00_dba"); + delete(MODULE_PGSQL_USER, "aaa00_dba"); + } + + private void delete(String module, String name) { + int count = getDBsCount(module); + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + whereParams.put("name", name); + 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, getDBsCount(module)); + } + + private int getDBsCount(String module) { + int count = 0; + String user = "aaa00"; + String grantingTicketURL = cas.getGrantingTicketURL(user); + Map whereParams = new HashMap(); + 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; + } + +}