HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2013-04-25 26950ec96d7fa801c9b080c9c02ce95632f2d489
clean database in ci tests
1 files modified
1 files added
85 ■■■■■ changed files
hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java 3 ●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/DatabaseCleanTest.java 82 ●●●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/ContinuousIntegrationTest.java
@@ -16,7 +16,8 @@
    EMailAliasTest.class,
    DomainTest.class,
    EMailAddressTest.class,
    SSLCertDomainTest.class
    SSLCertDomainTest.class,
    DatabaseCleanTest.class
//    CustomerTest.class,
//    LongCustomerNameTest.class,
//    QueueTaskTest.class
hsarback/test/de/hsadmin/remote/DatabaseCleanTest.java
New file
@@ -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<String, String> whereParams = new HashMap<String, String>();
        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<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;
    }
}