unit tests and db integration tests and travis-ci

This commit is contained in:
TonyO 2018-01-12 22:23:48 -06:00
parent 88a3884e34
commit 6bd932fd9a
28 changed files with 410 additions and 155 deletions

View File

@ -1,6 +1,13 @@
language: java
jdk:
- oraclejdk8
addons:
mariadb: '10.0'
services:
- mysql
- postgresql
env:
# encrypted Codacy key, see https://docs.travis-ci.com/user/encryption-keys/
@ -8,6 +15,11 @@ env:
before_install:
- wget -O ~/codacy-coverage-reporter-assembly-latest.jar https://github.com/codacy/codacy-coverage-reporter/releases/download/2.0.0/codacy-coverage-reporter-2.0.0-assembly.jar
# create test database for mysql, mariadb and postgresql
- mysql -u root -e 'CREATE DATABASE test_db;'
- mysql -u root test_db < extensions/database/test/conf/travis-mysql.sql
- psql -c 'CREATE DATABASE test_db;' -U postgres
- psql -U postgres test_db < extensions/database/test/conf/travis-pgsql.sql
script:
- ./refine server_test

View File

@ -13,6 +13,7 @@
<ant dir="jython/" target="build" />
<ant dir="gdata/" target="build" />
<ant dir="pc-axis/" target="build" />
<ant dir="database/" target="build" />
</target>
<target name="clean">
@ -21,10 +22,12 @@
<ant dir="jython/" target="clean" />
<ant dir="gdata/" target="clean" />
<ant dir="pc-axis/" target="clean" />
<ant dir="database/" target="clean" />
</target>
<target name="test">
<echo message="Testing extensions" />
<ant dir="jython/" target="test" />
<ant dir="database/" target="test" />
</target>
</project>

View File

@ -3,7 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/grefine"/>
<classpathentry kind="con" path="org.testng.TESTNG_CONTAINER"/>
<classpathentry exported="true" kind="lib" path="module/MOD-INF/lib/mysql-connector-java-5.1.44-bin.jar"/>
<classpathentry kind="lib" path="module/MOD-INF/lib/json-simple-1.1.1.jar"/>
@ -17,7 +16,8 @@
<classpathentry kind="lib" path="/OpenRefine/main/webapp/WEB-INF/lib/commons-collections-3.2.1.jar"/>
<classpathentry kind="lib" path="module/MOD-INF/lib/jackson-core-asl-1.9.13.jar"/>
<classpathentry kind="lib" path="module/MOD-INF/lib/jasypt-1.9.2.jar"/>
<classpathentry kind="lib" path="module/MOD-INF/lib/mockito-all-1.9.5.jar"/>
<classpathentry kind="lib" path="/OpenRefine/main/webapp/WEB-INF/lib/commons-lang-2.5.jar" sourcepath="/OpenRefine/main/webapp/WEB-INF/lib-src/commons-lang-2.5-sources.jar"/>
<classpathentry kind="lib" path="/OpenRefine/main/tests/server/lib/mockito-all-1.9.5.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/OpenRefine"/>
<classpathentry kind="output" path="module/MOD-INF/classes"/>
</classpath>

View File

@ -6,27 +6,35 @@
|
+-->
<project name="refine-database-extension" default="build" basedir=".">
<project name="refine-database-extension" default="build" basedir="." xmlns:jacoco="antlib:org.jacoco.ant">
<property environment="env"/>
<echo message="JAVA_HOME is set to = ${env.JAVA_HOME}" />
<tstamp/>
<property name="name" value="database-extension"/>
<property name="version" value="0.1"/>
<property name="revision" value="${DSTAMP}${TSTAMP}"/>
<property name="dist.dir" value="dist"/>
<property name="ext.dir" value="${dist.dir}/${name}"/>
<property name="fullname" value="${name}-${version}-${revision}" />
<condition property="version" value="trunk">
<not><isset property="version"/></not>
</condition>
<condition property="revision" value="rXXXX">
<not><isset property="revision"/></not>
</condition>
<condition property="full_version" value="0.0.0.0">
<not><isset property="full_version"/></not>
</condition>
<condition property="dist.dir" value="dist">
<not><isset property="dist.dir"/></not>
</condition>
<property name="fullname" value="${name}-${version}-${revision}" />
<property name="java_version" value="1.8"/>
<property name="refine.dir" value="${basedir}/../../main" />
<property name="server.lib.dir" value="${basedir}/../grefine-server/lib" />
<property name="refine.webinf.dir" value="${refine.dir}/webapp/WEB-INF" />
<property name="refine.modinf.dir" value="${refine.dir}/webapp/modules/core/MOD-INF" />
<property name="refine.classes.dir" value="${refine.webinf.dir}/classes" />
<property name="refine.lib.dir" value="${refine.webinf.dir}/lib" />
<property name="refine.tests.lib.dir" value="${refine.dir}/tests/server/lib" />
<property name="src.dir" value="${basedir}/src" />
<property name="module.dir" value="${basedir}/module" />
@ -34,6 +42,17 @@
<property name="lib.dir" value="${modinf.dir}/lib" />
<property name="classes.dir" value="${modinf.dir}/classes" />
<property name="test.dir" value="${basedir}/test" />
<property name="test.src.dir" value="${test.dir}"/>
<property name="test.out.dir" value="${basedir}/test-out" />
<property name="test.build.dir" value="${test.out.dir}/build" />
<property name="test.classes.dir" value="${test.out.dir}/classes" />
<property name="test.report.dir" value="${test.out.dir}/report"/>
<property name="test.report.html.dir" value="${test.report.dir}/html"/>
<property name="test.report.xml.path" value="${test.report.dir}/jacoco.xml"/>
<path id="class.path">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
@ -45,7 +64,22 @@
<include name="**/*.jar" />
</fileset>
<pathelement path="${refine.classes.dir}"/>
<pathelement path="${classes.dir}"/>
</path>
<path id="extension.tests.class.path">
<path refid="class.path"/>
<pathelement location="${test.classes.dir}"/>
<pathelement location="${refine.tests.lib.dir}/testng-6.8.jar"/>
<fileset dir="${refine.tests.lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="testngtasks" classpath="${refine.tests.lib.dir}/testng-6.8.jar"/>
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${refine.tests.lib.dir}/jacocoant.jar"/>
</taskdef>
<target name="build_java">
<mkdir dir="${classes.dir}" />
@ -56,6 +90,69 @@
</target>
<target name="build" depends="build_java"/>
<target name="build_tests" depends="clean, build">
<mkdir dir="${test.classes.dir}" />
<javac source="${java_version}" target="${java_version}" encoding="utf-8" srcdir="${test.src.dir}" destdir="${test.classes.dir}" debug="true" includeAntRuntime="no">
<classpath refid="extension.tests.class.path" />
</javac>
<copy file="${test.src.dir}/log4j-test.properties" tofile="${test.classes.dir}/log4j-test.properties"/>
</target>
<mkdir dir="${test.build.dir}" />
<target name="test" depends="build_tests">
<jacoco:coverage destfile="${test.report.dir}/jacoco.exec">
<testng verbose="2" haltOnFailure="true" workingdir="${test.build.dir}"
listener="org.testng.reporters.DotTestListener" excludedgroups="broken"
classpathref="extension.tests.class.path">
<xmlfileset file="${test.src.dir}/conf/int_tests.xml"/>
</testng>
</jacoco:coverage>
<jacoco:report>
<executiondata>
<file file="${test.report.dir}/jacoco.exec"/>
</executiondata>
<structure name="Database extension">
<classfiles>
<fileset dir="${classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<html destdir="${test.report.html.dir}"/>
<xml destfile="${test.report.xml.path}"/>
</jacoco:report>
</target>
<target name="unit_test" depends="build_tests">
<jacoco:coverage destfile="${test.report.dir}/jacoco.exec">
<testng verbose="2" haltOnFailure="true" workingdir="${test.build.dir}"
listener="org.testng.reporters.DotTestListener" excludedgroups="broken"
classpathref="extension.tests.class.path">
<xmlfileset file="${test.src.dir}/conf/unit_tests.xml"/>
</testng>
</jacoco:coverage>
<jacoco:report>
<executiondata>
<file file="${test.report.dir}/jacoco.exec"/>
</executiondata>
<structure name="Database extension">
<classfiles>
<fileset dir="${classes.dir}"/>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}"/>
</sourcefiles>
</structure>
<html destdir="${test.report.html.dir}"/>
<xml destfile="${test.report.xml.path}"/>
</jacoco:report>
</target>
<target name="dist" depends="build">
<mkdir dir="${ext.dir}"/>
@ -85,9 +182,10 @@
<delete dir="${ext.dir}"/>
</target>
<target name="clean">
<delete dir="${classes.dir}" />
</target>
<target name="clean">
<delete dir="${classes.dir}" />
<delete dir="${test.out.dir}" />
</target>
<target name="distclean">
<delete dir="${dist.dir}" />

View File

@ -160,20 +160,18 @@ public class DBQueryResultPreviewReader implements TableDataReader {
try {
rowOfCells.add(Long.parseLong(text));
continue;
} catch (NumberFormatException e) {
// ignore
}
try {
double d = Double.parseDouble(text);
if (!Double.isInfinite(d) && !Double.isNaN(d)) {
rowOfCells.add(d);
continue;
}
} catch (NumberFormatException e) {
// ignore
}
}
} catch (NumberFormatException e) {}
}else if(col.getType() == DatabaseColumnType.DOUBLE || col.getType() == DatabaseColumnType.FLOAT ) {
try {
double d = Double.parseDouble(text);
if (!Double.isInfinite(d) && !Double.isNaN(d)) {
rowOfCells.add(d);
continue;
}
} catch (NumberFormatException e) {}
}
rowOfCells.add(text);
}

View File

@ -81,8 +81,9 @@ public class DatabaseImportController implements ImportingController {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.info("doPost Query String::{}", request.getQueryString());
if(logger.isDebugEnabled()){
logger.debug("doPost Query String::{}", request.getQueryString());
}
response.setCharacterEncoding("UTF-8");
Properties parameters = ParsingUtilities.parseUrlParameters(request);
@ -171,7 +172,7 @@ public class DatabaseImportController implements ImportingController {
if(logger.isDebugEnabled()) {
logger.debug("JobID::{}", parameters.getProperty("jobID"));
}
logger.info("JobID::{}", parameters.getProperty("jobID"));
long jobID = Long.parseLong(parameters.getProperty("jobID"));
ImportingJob job = ImportingManager.getJob(jobID);
@ -180,7 +181,10 @@ public class DatabaseImportController implements ImportingController {
return;
}
DatabaseQueryInfo databaseQueryInfo = getQueryInfo(request);
if(databaseQueryInfo == null) {
HttpUtilities.respond(response, "error", "Invalid or missing Query Info");
}
@ -270,6 +274,7 @@ public class DatabaseImportController implements ImportingController {
JSONObject options,
List<Exception> exceptions) throws DatabaseServiceException{
DatabaseService databaseService = DatabaseService.get(dbQueryInfo.getDbConfig().getDatabaseType());
String querySource = getQuerySource(dbQueryInfo);
@ -398,6 +403,7 @@ public class DatabaseImportController implements ImportingController {
JSONObject options,
List<Exception> exceptions) throws DatabaseServiceException{
DatabaseService databaseService = DatabaseService.get(dbQueryInfo.getDbConfig().getDatabaseType());
String querySource = getQuerySource(dbQueryInfo);
@ -459,7 +465,7 @@ public class DatabaseImportController implements ImportingController {
jdbcConfig.setDatabaseSchema(request.getParameter("initialSchema"));
String query = request.getParameter("query");
logger.info("jdbcConfig::{}, query::{}", jdbcConfig, query);
if (jdbcConfig.getDatabaseHost() == null || jdbcConfig.getDatabaseName() == null
|| jdbcConfig.getDatabasePassword() == null || jdbcConfig.getDatabaseType() == null
|| jdbcConfig.getDatabaseUser() == null || query == null) {

View File

@ -70,7 +70,10 @@ public abstract class DatabaseService {
databaseServiceMap.put(name, db);
logger.info(String.format("Registered %s Database", name));
}else {
logger.info(name + " Database Type already exists");
if(logger.isDebugEnabled()) {
logger.debug(name + " Database Type already exists");
}
}
}

View File

@ -72,7 +72,7 @@ public class MariaDBConnectionManager {
*/
public static MariaDBConnectionManager getInstance() throws DatabaseServiceException {
if (instance == null) {
logger.info("::Creating new MariaDB Connection Manager ::");
//logger.info("::Creating new MariaDB Connection Manager ::");
instance = new MariaDBConnectionManager();
}
@ -126,7 +126,7 @@ public class MariaDBConnectionManager {
// logger.info("connection::{}, forceNewConnection: {}", connection, forceNewConnection);
if (connection != null && !forceNewConnection) {
logger.info("connection closed::{}", connection.isClosed());
// logger.debug("connection closed::{}", connection.isClosed());
if (!connection.isClosed()) {
if(logger.isDebugEnabled()) {
logger.debug("Returning existing connection::{}", connection);

View File

@ -74,7 +74,10 @@ public class PgSQLConnectionManager {
*/
public static PgSQLConnectionManager getInstance() throws DatabaseServiceException {
if (instance == null) {
logger.info("::Creating new PgSQL ConnectionManager ::");
if(logger.isDebugEnabled()) {
logger.debug("::Creating new PgSQL ConnectionManager ::");
}
instance = new PgSQLConnectionManager();
}

View File

@ -126,7 +126,7 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
"http://127.0.0.1:3333/command/core/importing-controller?controller=database/database-import-controller&subCommand=invalid-sub-command");
when(response.getWriter()).thenReturn(pw);
//test
SUT.doPost(request, response);
String result = sw.getBuffer().toString().trim();
@ -257,12 +257,13 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
@BeforeTest
@Parameters({ "mySqlDbName", "mySqlDbHost", "mySqlDbPort", "mySqlDbUser", "mySqlDbPassword", "mySqlTestTable"})
public void beforeTest(@Optional(DEFAULT_MYSQL_DB_NAME) String mySqlDbName, @Optional(DEFAULT_MYSQL_HOST) String mySqlDbHost,
@Optional(DEFAULT_MYSQL_PORT) String mySqlDbPort, @Optional(DEFAULT_MYSQL_USER) String mySqlDbUser,
public void beforeTest(
@Optional(DEFAULT_MYSQL_DB_NAME) String mySqlDbName, @Optional(DEFAULT_MYSQL_HOST) String mySqlDbHost,
@Optional(DEFAULT_MYSQL_PORT) String mySqlDbPort, @Optional(DEFAULT_MYSQL_USER) String mySqlDbUser,
@Optional(DEFAULT_MYSQL_PASSWORD) String mySqlDbPassword, @Optional(DEFAULT_TEST_TABLE) String mySqlTestTable) {
MockitoAnnotations.initMocks(this);
// System.out.println("beforeTest " + pgSqlDbName);
testDbConfig = new DatabaseConfiguration();
testDbConfig.setDatabaseHost(mySqlDbHost);
testDbConfig.setDatabaseName(mySqlDbName);
@ -271,12 +272,14 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
testDbConfig.setDatabaseType(MySQLDatabaseService.DB_NAME);
testDbConfig.setDatabaseUser(mySqlDbUser);
testDbConfig.setUseSSL(false);
query = "SELECT count(*) FROM " + mySqlTestTable;
//testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
}

View File

@ -5,7 +5,6 @@ import java.sql.Connection;
import java.util.List;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@ -44,7 +43,7 @@ public class DatabaseServiceTest extends DBExtensionTests{
testDbConfig.setUseSSL(false);
testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MariaDBDatabaseService.DB_NAME, MariaDBDatabaseService.getInstance());
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
@ -52,17 +51,17 @@ public class DatabaseServiceTest extends DBExtensionTests{
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
//
// }
@Test
public void testGetDatabaseUrl() {
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
String dbUrl = dbService.getDatabaseUrl(testDbConfig);
System.out.println("dbUrl:" + dbUrl);
// System.out.println("dbUrl:" + dbUrl);
Assert.assertNotNull(dbUrl);
Assert.assertEquals(dbUrl, DBExtensionTestUtils.getJDBCUrl(testDbConfig));
}

View File

@ -0,0 +1,78 @@
package com.google.refine.extension.database;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import com.google.refine.extension.database.mariadb.MariaDBDatabaseService;
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
import com.google.refine.extension.database.pgsql.PgSQLDatabaseService;
public class DatabaseTestConfig extends DBExtensionTests {
private DatabaseConfiguration mysqlDbConfig;
private DatabaseConfiguration pgsqlDbConfig;
private DatabaseConfiguration mariadbDbConfig;
@BeforeSuite
@Parameters({ "mySqlDbName", "mySqlDbHost", "mySqlDbPort", "mySqlDbUser", "mySqlDbPassword", "mySqlTestTable",
"pgSqlDbName", "pgSqlDbHost", "pgSqlDbPort", "pgSqlDbUser", "pgSqlDbPassword", "pgSqlTestTable",
"mariadbDbName", "mariadbDbHost", "mariadbDbPort", "mariadbyDbUser", "mariadbDbPassword", "mariadbTestTable"})
public void beforeSuite(
@Optional(DEFAULT_MYSQL_DB_NAME) String mySqlDbName, @Optional(DEFAULT_MYSQL_HOST) String mySqlDbHost,
@Optional(DEFAULT_MYSQL_PORT) String mySqlDbPort, @Optional(DEFAULT_MYSQL_USER) String mySqlDbUser,
@Optional(DEFAULT_MYSQL_PASSWORD) String mySqlDbPassword, @Optional(DEFAULT_TEST_TABLE) String mySqlTestTable,
@Optional(DEFAULT_PGSQL_DB_NAME) String pgSqlDbName, @Optional(DEFAULT_PGSQL_HOST) String pgSqlDbHost,
@Optional(DEFAULT_PGSQL_PORT) String pgSqlDbPort, @Optional(DEFAULT_PGSQL_USER) String pgSqlDbUser,
@Optional(DEFAULT_PGSQL_PASSWORD) String pgSqlDbPassword, @Optional(DEFAULT_TEST_TABLE) String pgSqlTestTable,
@Optional(DEFAULT_MARIADB_NAME) String mariadbDbName, @Optional(DEFAULT_MARIADB_HOST) String mariadbDbHost,
@Optional(DEFAULT_MARIADB_PORT) String mariadbDbPort, @Optional(DEFAULT_MARIADB_USER) String mariadbyDbUser,
@Optional(DEFAULT_MARIADB_PASSWORD) String mariadbDbPassword, @Optional(DEFAULT_TEST_TABLE) String mariadbTestTable) {
//System.out.println("@BeforeSuite\n");
mysqlDbConfig = new DatabaseConfiguration();
mysqlDbConfig.setDatabaseHost(mySqlDbHost);
mysqlDbConfig.setDatabaseName(mySqlDbName);
mysqlDbConfig.setDatabasePassword(mySqlDbPassword);
mysqlDbConfig.setDatabasePort(Integer.parseInt(mySqlDbPort));
mysqlDbConfig.setDatabaseType(MySQLDatabaseService.DB_NAME);
mysqlDbConfig.setDatabaseUser(mySqlDbUser);
mysqlDbConfig.setUseSSL(false);
pgsqlDbConfig = new DatabaseConfiguration();
pgsqlDbConfig.setDatabaseHost(pgSqlDbHost);
pgsqlDbConfig.setDatabaseName(pgSqlDbName);
pgsqlDbConfig.setDatabasePassword(pgSqlDbPassword);
pgsqlDbConfig.setDatabasePort(Integer.parseInt(pgSqlDbPort));
pgsqlDbConfig.setDatabaseType(PgSQLDatabaseService.DB_NAME);
pgsqlDbConfig.setDatabaseUser(pgSqlDbUser);
pgsqlDbConfig.setUseSSL(false);
mariadbDbConfig = new DatabaseConfiguration();
mariadbDbConfig.setDatabaseHost(mariadbDbHost);
mariadbDbConfig.setDatabaseName(mariadbDbName);
mariadbDbConfig.setDatabasePassword(mariadbDbPassword);
mariadbDbConfig.setDatabasePort(Integer.parseInt(mariadbDbPort));
mariadbDbConfig.setDatabaseType(MariaDBDatabaseService.DB_NAME);
mariadbDbConfig.setDatabaseUser(mariadbyDbUser);
mariadbDbConfig.setUseSSL(false);
DBExtensionTestUtils.initTestData(mysqlDbConfig);
DBExtensionTestUtils.initTestData(pgsqlDbConfig);
DBExtensionTestUtils.initTestData(mariadbDbConfig);
}
@AfterSuite
public void afterSuite() {
// System.out.println("@AfterSuite");
DBExtensionTestUtils.cleanUpTestData(mysqlDbConfig);
DBExtensionTestUtils.cleanUpTestData(pgsqlDbConfig);
DBExtensionTestUtils.cleanUpTestData(mariadbDbConfig);
}
}

View File

@ -13,13 +13,11 @@ import org.json.JSONObject;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -57,18 +55,18 @@ public class ConnectCommandTest extends DBExtensionTests {
testDbConfig.setUseSSL(false);
//testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
//DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
//
// }
//
@Test
public void testDoPost() {

View File

@ -12,13 +12,11 @@ import org.json.JSONObject;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -55,17 +53,17 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
testDbConfig.setUseSSL(false);
testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
//
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
//
// }
@Test

View File

@ -17,7 +17,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
@ -30,11 +29,9 @@ import com.google.refine.RefineServlet;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseImportController;
import com.google.refine.extension.database.DatabaseService;
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
import com.google.refine.extension.database.stub.RefineDbServletStub;
import com.google.refine.importing.ImportingJob;
import com.google.refine.importing.ImportingManager;
import com.google.refine.io.FileProjectManager;
import com.google.refine.model.Project;
@ -111,11 +108,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
}
@AfterSuite
public void afterSuite() {
}
private void saveDatabaseConfiguration(String savedDbName) {
@ -306,7 +299,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
SUT.doDelete(request, response);
String result = sw.getBuffer().toString().trim();
// String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject();

View File

@ -12,13 +12,11 @@ import org.json.JSONObject;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -56,17 +54,17 @@ public class TestConnectCommandTest extends DBExtensionTests{
testDbConfig.setUseSSL(false);
//testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
//
// }
@Test
public void testDoPost() {

View File

@ -12,13 +12,11 @@ import org.json.JSONObject;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -55,17 +53,17 @@ public class TestQueryCommandTest extends DBExtensionTests {
testDbConfig.setUseSSL(false);
testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
//DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
//
// }
@Test

View File

@ -4,13 +4,11 @@ import java.sql.Connection;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -42,17 +40,17 @@ public class MariaDBConnectionManagerTest extends DBExtensionTests {
testDbConfig.setUseSSL(false);
// testTable = mariaDbTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MariaDBDatabaseService.DB_NAME, MariaDBDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
//
// }
@Test
public void testTestConnection() {

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@ -48,7 +47,7 @@ public class MariaDBDatabaseServiceTest extends DBExtensionTests{
testDbConfig.setUseSSL(false);
testTable = mariaDbTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
//DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MariaDBDatabaseService.DB_NAME, MariaDBDatabaseService.getInstance());
@ -126,7 +125,7 @@ public class MariaDBDatabaseServiceTest extends DBExtensionTests{
String limitQuery = pgSqlService.buildLimitQuery(100, 0, "SELECT * FROM " + testTable);
Assert.assertNotNull(limitQuery);
Assert.assertEquals(limitQuery, "SELECT * FROM " + testTable + " LIMIT " + 100 + " OFFSET " + 0);
Assert.assertEquals(limitQuery, "SELECT * FROM " + testTable + " LIMIT " + 100 + " OFFSET " + 0 + ";");
}
@ -170,9 +169,9 @@ public class MariaDBDatabaseServiceTest extends DBExtensionTests{
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
logger.info("<<After Suite Cleanup>>");
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
// logger.info("<<After Suite Cleanup>>");
// }
}

View File

@ -4,13 +4,11 @@ import java.sql.Connection;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -39,17 +37,17 @@ public class MySQLConnectionManagerTest extends DBExtensionTests {
testDbConfig.setUseSSL(false);
//testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
// DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
// @AfterSuite
// public void afterSuite() {
// DBExtensionTestUtils.cleanUpTestData(testDbConfig);
// }
//
@Test
public void testTestConnection() {

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@ -45,7 +44,7 @@ public class MySQLDatabaseServiceTest extends DBExtensionTests{
testDbConfig.setUseSSL(false);
testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
//DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(MySQLDatabaseService.DB_NAME, MySQLDatabaseService.getInstance());
@ -168,11 +167,6 @@ public class MySQLDatabaseServiceTest extends DBExtensionTests{
}
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
}

View File

@ -4,13 +4,11 @@ import java.sql.Connection;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import com.google.refine.extension.database.DBExtensionTestUtils;
import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService;
@ -41,18 +39,13 @@ public class PgSQLConnectionManagerTest extends DBExtensionTests {
testDbConfig.setUseSSL(false);
//testTable = mySqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
//DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(PgSQLDatabaseService.DB_NAME, PgSQLDatabaseService.getInstance());
}
@AfterSuite
public void afterSuite() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
@Test
public void testTestConnection() {

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.mockito.MockitoAnnotations;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;
@ -45,7 +44,7 @@ public class PgSQLDatabaseServiceTest extends DBExtensionTests{
testDbConfig.setUseSSL(false);
testTable = pgSqlTestTable;
DBExtensionTestUtils.initTestData(testDbConfig);
//DBExtensionTestUtils.initTestData(testDbConfig);
DatabaseService.DBType.registerDatabase(PgSQLDatabaseService.DB_NAME, PgSQLDatabaseService.getInstance());
}
@ -167,12 +166,6 @@ public class PgSQLDatabaseServiceTest extends DBExtensionTests{
e.printStackTrace();
}
}
@AfterSuite
public void afterClass() {
DBExtensionTestUtils.cleanUpTestData(testDbConfig);
}
}

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<suite name="DatabaseExtensionUnitTestSuite">
<parameter name = "mySqlDbName" value="test_db"/>
<parameter name = "mySqlDbHost" value="127.0.0.1"/>
<parameter name = "mySqlDbPort" value="3306"/>
<parameter name = "mySqlDbUser" value="root"/>
<parameter name = "mySqlDbPassword" value=""/>
<parameter name = "mySqlTestTable" value="test_table"/>
<parameter name = "pgSqlDbName" value="test_db"/>
<parameter name = "pgSqlDbHost" value="127.0.0.1"/>
<parameter name = "pgSqlDbPort" value="5432"/>
<parameter name = "pgSqlDbUser" value="postgres"/>
<parameter name = "pgSqlDbPassword" value=""/>
<parameter name = "pgSqlTestTable" value="test_table"/>
<parameter name = "mariaDbName" value="test_db"/>
<parameter name = "mariaDbHost" value="127.0.0.1"/>
<parameter name = "mariadbDbPort" value="3306"/>
<parameter name = "mariaDbUser" value="root"/>
<parameter name = "mariaDbPassword" value=""/>
<parameter name = "mariaDbTestTable" value="test_table"/>
<test name="DatabaseExtensionUnitTest">
<classes>
<class name="com.google.refine.extension.database.DatabaseImportControllerTest"/>
<class name="com.google.refine.extension.database.DatabaseServiceTest"/>
<class name="com.google.refine.extension.database.SimpleTextEncryptorTest"/>
<class name="com.google.refine.extension.database.cmd.ConnectCommandTest"/>
<class name="com.google.refine.extension.database.cmd.ExecuteQueryCommandTest"/>
<class name="com.google.refine.extension.database.cmd.SavedConnectionCommandTest"/>
<class name="com.google.refine.extension.database.cmd.TestConnectCommandTest"/>
<class name="com.google.refine.extension.database.cmd.TestQueryCommandTest"/>
<class name="com.google.refine.extension.database.mariadb.MariaDBConnectionManagerTest"/>
<class name="com.google.refine.extension.database.mariadb.MariaDBDatabaseServiceTest"/>
<class name="com.google.refine.extension.database.mysql.MySQLConnectionManagerTest"/>
<class name="com.google.refine.extension.database.mysql.MySQLDatabaseServiceTest"/>
<class name="com.google.refine.extension.database.pgsql.PgSQLConnectionManagerTest"/>
<class name="com.google.refine.extension.database.pgsql.PgSQLDatabaseServiceTest" />
</classes>
</test>
</suite>

View File

@ -0,0 +1,18 @@
CREATE DATABASE IF NOT EXISTS `test_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE test_db;
CREATE TABLE IF NOT EXISTS `test_table` (
`id` int(11) NOT NULL,
`ue_id` char(8) NOT NULL,
`start_time` timestamp NOT NULL,
`end_date` date DEFAULT NULL,
`bytes_upload` int(11) NOT NULL,
`bytes_download` int(11) NOT NULL,
`mcc` char(3) DEFAULT NULL,
`mnc` char(3) NOT NULL,
`lac` varchar(11) DEFAULT NULL,
`imei` char(16) NOT NULL
);
INSERT INTO test_table(id, ue_id, start_time, end_date, bytes_upload, bytes_download, mcc, mnc, lac, imei)
VALUES (1, '11100022', now(), now(), 1024, 2048, 321, 543, 12209823498, 1344498988877487);

View File

@ -0,0 +1,17 @@
USE test_db;
CREATE TABLE IF NOT EXISTS `test_table` (
`id` int(11) NOT NULL,
`ue_id` char(8) NOT NULL,
`start_time` timestamp NOT NULL,
`end_date` date DEFAULT NULL,
`bytes_upload` int(11) NOT NULL,
`bytes_download` int(11) NOT NULL,
`mcc` char(3) DEFAULT NULL,
`mnc` char(3) NOT NULL,
`lac` varchar(11) DEFAULT NULL,
`imei` char(16) NOT NULL
);
INSERT INTO test_table(id, ue_id, start_time, end_date, bytes_upload, bytes_download, mcc, mnc, lac, imei)
VALUES (1, '11100022', now(), now(), 1024, 2048, 321, 543, 12209823498, 1344498988877487);

View File

@ -0,0 +1,17 @@
USE test_db;
CREATE TABLE IF NOT EXISTS test_table (
id integer NOT NULL,
ue_id char(8) NOT NULL,
start_time timestamp NOT NULL,
end_date date DEFAULT NULL,
bytes_upload integer NOT NULL,
bytes_download integer NOT NULL,
mcc char(3) DEFAULT NULL,
mnc char(3) NOT NULL,
lac varchar(11) DEFAULT NULL,
imei char(16) NOT NULL
);
INSERT INTO test_table(id, ue_id, start_time, end_date, bytes_upload, bytes_download, mcc, mnc, lac, imei)
VALUES (1, '11100022', now(), now(), 1024, 2048, 321, 543, 12209823498, 1344498988877487);

View File

@ -22,16 +22,15 @@
<parameter name = "mariaDbTestTable" value="test_data"/>
<test name="DatabaseExtensionUnitTest">
<classes>
<!-- <class name="com.google.refine.extension.database.DatabaseImportControllerTest" />
<class name="com.google.refine.extension.database.DatabaseServiceTest" />
<class name="com.google.refine.extension.database.DBQueryResultImportReaderTest" />
<class name="com.google.refine.extension.database.DBQueryResultPreviewReaderTest" />
<class name="com.google.refine.extension.database.cmd.ConnectCommandTest" />
<class name="com.google.refine.extension.database.cmd.QueryCommandTest" />
<class name="com.google.refine.extension.database.cmd.SavedConnectionCommandTest" />
<class name="com.google.refine.extension.database.cmd.TestConnectCommandTest" />
-->
<class name="com.google.refine.extension.database.DatabaseTestConfig"/>
<class name="com.google.refine.extension.database.DatabaseImportControllerTest"/>
<class name="com.google.refine.extension.database.DatabaseServiceTest"/>
<class name="com.google.refine.extension.database.SimpleTextEncryptorTest"/>
<class name="com.google.refine.extension.database.cmd.ConnectCommandTest"/>
<class name="com.google.refine.extension.database.cmd.ExecuteQueryCommandTest"/>
<class name="com.google.refine.extension.database.cmd.SavedConnectionCommandTest"/>
<class name="com.google.refine.extension.database.cmd.TestConnectCommandTest"/>
<class name="com.google.refine.extension.database.cmd.TestQueryCommandTest"/>
<class name="com.google.refine.extension.database.mariadb.MariaDBConnectionManagerTest"/>
<class name="com.google.refine.extension.database.mariadb.MariaDBDatabaseServiceTest"/>
<class name="com.google.refine.extension.database.mysql.MySQLConnectionManagerTest"/>