Do not catch exceptions in tests; add database groups
The groups let us enable / disable tests for a specific db, depending on which one is available on the machine.
This commit is contained in:
parent
197dc47f37
commit
b2b9a4bc9a
@ -50,8 +50,11 @@ public class DBExtensionTestUtils {
|
||||
* Create Test Table with one row of Data
|
||||
* @param dbConfig DatabaseConfiguration to test
|
||||
* @param tableName
|
||||
* @throws DatabaseServiceException
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static void initTestData(DatabaseConfiguration dbConfig, String tableName) {
|
||||
public static void initTestData(DatabaseConfiguration dbConfig, String tableName)
|
||||
throws DatabaseServiceException, SQLException {
|
||||
|
||||
Statement stmt = null;
|
||||
Connection conn = null;
|
||||
@ -87,16 +90,11 @@ public class DBExtensionTestUtils {
|
||||
|
||||
logger.info("Database Test Init Data Created!!!");
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if(stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -104,7 +102,6 @@ public class DBExtensionTestUtils {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -113,7 +110,8 @@ public class DBExtensionTestUtils {
|
||||
}
|
||||
|
||||
|
||||
public static void initTestData(DatabaseConfiguration dbConfig) {
|
||||
public static void initTestData(DatabaseConfiguration dbConfig)
|
||||
throws DatabaseServiceException, SQLException {
|
||||
|
||||
Statement stmt = null;
|
||||
Connection conn = null;
|
||||
@ -149,10 +147,6 @@ public class DBExtensionTestUtils {
|
||||
|
||||
logger.info("Database Test Init Data Created!!!");
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
||||
} finally {
|
||||
if(stmt != null) {
|
||||
try {
|
||||
@ -179,8 +173,11 @@ public class DBExtensionTestUtils {
|
||||
* Table name: test_data
|
||||
* @param sampleSize
|
||||
* @param batchSize
|
||||
* @throws DatabaseServiceException
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void generateMySQLTestData(int sampleSize, int batchSize) {
|
||||
public void generateMySQLTestData(int sampleSize, int batchSize)
|
||||
throws DatabaseServiceException, SQLException {
|
||||
mncMap = new HashMap<Integer, Integer>();
|
||||
mccMap = new HashMap<Integer, Integer>();
|
||||
mccMap.put(0, 302);
|
||||
@ -208,65 +205,56 @@ public class DBExtensionTestUtils {
|
||||
+ "id, ue_id, start_time, end_date, bytes_upload, bytes_download, cell_id, mcc, mnc, lac, imei)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
Connection conn;
|
||||
try {
|
||||
conn = DatabaseService.get(MYSQL_DB_NAME).getConnection(dc);
|
||||
Connection conn = DatabaseService.get(MYSQL_DB_NAME).getConnection(dc);
|
||||
|
||||
Statement truncateStmt = conn.createStatement();
|
||||
int result = truncateStmt.executeUpdate(truncateTableSQL);
|
||||
System.out.println("Truncate Table Result::" + result);
|
||||
truncateStmt.close();
|
||||
Statement truncateStmt = conn.createStatement();
|
||||
int result = truncateStmt.executeUpdate(truncateTableSQL);
|
||||
System.out.println("Truncate Table Result::" + result);
|
||||
truncateStmt.close();
|
||||
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(insertTableSQL);
|
||||
PreparedStatement stmt = conn.prepareStatement(insertTableSQL);
|
||||
|
||||
int counter=1;
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
stmt.setLong(1, i);
|
||||
stmt.setString(2, getNextUeId());
|
||||
stmt.setDate(3, getNextStartDate());
|
||||
stmt.setDate(4, getNextEndDate());
|
||||
stmt.setInt(5, rand.nextInt());
|
||||
stmt.setInt(6, rand.nextInt());
|
||||
stmt.setInt(7, rand.nextInt(10));
|
||||
stmt.setInt(8, getMCC());
|
||||
stmt.setInt(9, getMNC());
|
||||
stmt.setInt(10, rand.nextInt(100));
|
||||
stmt.setString(11, getNextIMEI());
|
||||
int counter=1;
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
stmt.setLong(1, i);
|
||||
stmt.setString(2, getNextUeId());
|
||||
stmt.setDate(3, getNextStartDate());
|
||||
stmt.setDate(4, getNextEndDate());
|
||||
stmt.setInt(5, rand.nextInt());
|
||||
stmt.setInt(6, rand.nextInt());
|
||||
stmt.setInt(7, rand.nextInt(10));
|
||||
stmt.setInt(8, getMCC());
|
||||
stmt.setInt(9, getMNC());
|
||||
stmt.setInt(10, rand.nextInt(100));
|
||||
stmt.setString(11, getNextIMEI());
|
||||
|
||||
stmt.addBatch();
|
||||
stmt.addBatch();
|
||||
|
||||
//Execute batch of 1000 records
|
||||
if(i%batchSize==0){
|
||||
stmt.executeBatch();
|
||||
conn.commit();
|
||||
System.out.println("Batch "+(counter++)+" executed successfully");
|
||||
}
|
||||
}
|
||||
//execute final batch
|
||||
stmt.executeBatch();
|
||||
System.out.println("Final Batch Executed "+(counter++)+" executed successfully");
|
||||
conn.commit();
|
||||
conn.close();
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
//Execute batch of 1000 records
|
||||
if(i%batchSize==0){
|
||||
stmt.executeBatch();
|
||||
conn.commit();
|
||||
System.out.println("Batch "+(counter++)+" executed successfully");
|
||||
}
|
||||
}
|
||||
|
||||
//execute final batch
|
||||
stmt.executeBatch();
|
||||
System.out.println("Final Batch Executed "+(counter++)+" executed successfully");
|
||||
conn.commit();
|
||||
conn.close();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sampleSize
|
||||
* @param batchSize
|
||||
* @throws DatabaseServiceException
|
||||
* @throws SQLException
|
||||
*/
|
||||
public void generatePgSQLTestData(int sampleSize, int batchSize) {
|
||||
public void generatePgSQLTestData(int sampleSize, int batchSize) throws DatabaseServiceException, SQLException {
|
||||
mncMap = new HashMap<Integer, Integer>();
|
||||
mccMap = new HashMap<Integer, Integer>();
|
||||
mccMap.put(0, 302);
|
||||
@ -294,56 +282,46 @@ public class DBExtensionTestUtils {
|
||||
+ "id, ue_id, start_time, end_date, bytes_upload, bytes_download, cell_id, mcc, mnc, lac, imei)"
|
||||
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
Connection conn;
|
||||
try {
|
||||
conn = DatabaseService.get(PGSQL_DB_NAME).getConnection(dc);
|
||||
Connection conn = DatabaseService.get(PGSQL_DB_NAME).getConnection(dc);
|
||||
|
||||
Statement truncateStmt = conn.createStatement();
|
||||
int result = truncateStmt.executeUpdate(truncateTableSQL);
|
||||
System.out.println("Truncate Table Result::" + result);
|
||||
truncateStmt.close();
|
||||
Statement truncateStmt = conn.createStatement();
|
||||
int result = truncateStmt.executeUpdate(truncateTableSQL);
|
||||
System.out.println("Truncate Table Result::" + result);
|
||||
truncateStmt.close();
|
||||
|
||||
|
||||
conn.setAutoCommit(false);
|
||||
conn.setAutoCommit(false);
|
||||
|
||||
PreparedStatement stmt = conn.prepareStatement(insertTableSQL);
|
||||
PreparedStatement stmt = conn.prepareStatement(insertTableSQL);
|
||||
|
||||
int counter=1;
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
stmt.setLong(1, i);
|
||||
stmt.setString(2, getNextUeId());
|
||||
stmt.setDate(3, getNextStartDate());
|
||||
stmt.setDate(4, getNextEndDate());
|
||||
stmt.setInt(5, rand.nextInt());
|
||||
stmt.setInt(6, rand.nextInt());
|
||||
stmt.setInt(7, rand.nextInt(10));
|
||||
stmt.setInt(8, getMCC());
|
||||
stmt.setInt(9, getMNC());
|
||||
stmt.setInt(10, rand.nextInt(100));
|
||||
stmt.setString(11, getNextIMEI());
|
||||
int counter=1;
|
||||
for (int i = 0; i < sampleSize; i++) {
|
||||
stmt.setLong(1, i);
|
||||
stmt.setString(2, getNextUeId());
|
||||
stmt.setDate(3, getNextStartDate());
|
||||
stmt.setDate(4, getNextEndDate());
|
||||
stmt.setInt(5, rand.nextInt());
|
||||
stmt.setInt(6, rand.nextInt());
|
||||
stmt.setInt(7, rand.nextInt(10));
|
||||
stmt.setInt(8, getMCC());
|
||||
stmt.setInt(9, getMNC());
|
||||
stmt.setInt(10, rand.nextInt(100));
|
||||
stmt.setString(11, getNextIMEI());
|
||||
|
||||
stmt.addBatch();
|
||||
stmt.addBatch();
|
||||
|
||||
//Execute batch of 1000 records
|
||||
if(i%batchSize==0){
|
||||
stmt.executeBatch();
|
||||
conn.commit();
|
||||
System.out.println("Batch "+(counter++)+" executed successfully");
|
||||
}
|
||||
}
|
||||
//execute final batch
|
||||
stmt.executeBatch();
|
||||
System.out.println("Final Batch Executed "+(counter++)+" executed successfully");
|
||||
conn.commit();
|
||||
conn.close();
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
//Execute batch of 1000 records
|
||||
if(i%batchSize==0){
|
||||
stmt.executeBatch();
|
||||
conn.commit();
|
||||
System.out.println("Batch "+(counter++)+" executed successfully");
|
||||
}
|
||||
}
|
||||
//execute final batch
|
||||
stmt.executeBatch();
|
||||
System.out.println("Final Batch Executed "+(counter++)+" executed successfully");
|
||||
conn.commit();
|
||||
conn.close();
|
||||
|
||||
}
|
||||
|
||||
@ -381,7 +359,7 @@ public class DBExtensionTestUtils {
|
||||
return "" + n;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws DatabaseServiceException, SQLException {
|
||||
DBExtensionTestUtils testUtil = new DBExtensionTestUtils();
|
||||
testUtil.generatePgSQLTestData(SAMPLE_SIZE, BATCH_SIZE);
|
||||
// testUtil.generateMySQLTestData();
|
||||
@ -404,7 +382,7 @@ public class DBExtensionTestUtils {
|
||||
//System.out.println("Drop Table Result::" + dropResult);
|
||||
}
|
||||
|
||||
logger.info("Database Test Cleanup Done!!!");
|
||||
logger.info("Database Test Cleanup Done");
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
|
@ -33,6 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.refine.extension.database;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class DBExtensionTests {
|
||||
@ -61,13 +63,8 @@ public class DBExtensionTests {
|
||||
|
||||
protected final String DEFAULT_TEST_TABLE = "test_data";
|
||||
|
||||
protected Properties properties;
|
||||
|
||||
protected Logger logger;
|
||||
|
||||
// @BeforeSuite
|
||||
// public void init() {
|
||||
// System.out.println("Log4j init...");
|
||||
// System.setProperty("log4j.configuration", "log4j-test.properties");
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -35,7 +36,7 @@ import com.google.refine.model.Project;
|
||||
|
||||
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
|
||||
@Mock
|
||||
@ -118,141 +119,114 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPostInvalidSubCommand() {
|
||||
public void testDoPostInvalidSubCommand() throws IOException, ServletException, JSONException {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
try {
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database/database-import-controller&subCommand=invalid-sub-command");
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"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);
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
//test
|
||||
SUT.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String code = json.getString("status");
|
||||
String message = json.getString("message");
|
||||
Assert.assertNotNull(code);
|
||||
Assert.assertNotNull(message);
|
||||
Assert.assertEquals(code, "error");
|
||||
Assert.assertEquals(message, "No such sub command");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String code = json.getString("status");
|
||||
String message = json.getString("message");
|
||||
Assert.assertNotNull(code);
|
||||
Assert.assertNotNull(message);
|
||||
Assert.assertEquals(code, "error");
|
||||
Assert.assertEquals(message, "No such sub command");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoPostInitializeParser() {
|
||||
public void testDoPostInitializeParser() throws ServletException, IOException, JSONException {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database/database-import-controller&subCommand=initialize-parser-ui");
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database/database-import-controller&subCommand=initialize-parser-ui");
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
|
||||
SUT.doPost(request, response);
|
||||
SUT.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String status = json.getString("status");
|
||||
//System.out.println("json::" + json);
|
||||
Assert.assertEquals(status, "ok");
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String status = json.getString("status");
|
||||
//System.out.println("json::" + json);
|
||||
Assert.assertEquals(status, "ok");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPostParsePreview() {
|
||||
public void testDoPostParsePreview() throws IOException, ServletException, JSONException {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
long jobId = job.id;
|
||||
|
||||
long jobId = job.id;
|
||||
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database%2Fdatabase-import-controller&jobID="
|
||||
+ jobId + "&subCommand=parse-preview");
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database%2Fdatabase-import-controller&jobID="
|
||||
+ jobId + "&subCommand=parse-preview");
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
when(request.getParameter("databasePort")).thenReturn("" + testDbConfig.getDatabasePort());
|
||||
when(request.getParameter("databaseUser")).thenReturn(testDbConfig.getDatabaseUser());
|
||||
when(request.getParameter("databasePassword")).thenReturn(testDbConfig.getDatabasePassword());
|
||||
when(request.getParameter("initialDatabase")).thenReturn(testDbConfig.getDatabaseName());
|
||||
when(request.getParameter("query")).thenReturn(query);
|
||||
when(request.getParameter("options")).thenReturn(JSON_OPTION);
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
when(request.getParameter("databasePort")).thenReturn("" + testDbConfig.getDatabasePort());
|
||||
when(request.getParameter("databaseUser")).thenReturn(testDbConfig.getDatabaseUser());
|
||||
when(request.getParameter("databasePassword")).thenReturn(testDbConfig.getDatabasePassword());
|
||||
when(request.getParameter("initialDatabase")).thenReturn(testDbConfig.getDatabaseName());
|
||||
when(request.getParameter("query")).thenReturn(query);
|
||||
when(request.getParameter("options")).thenReturn(JSON_OPTION);
|
||||
|
||||
SUT.doPost(request, response);
|
||||
SUT.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String status = json.getString("status");
|
||||
//System.out.println("json::" + json);
|
||||
Assert.assertEquals(status, "ok");
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String status = json.getString("status");
|
||||
//System.out.println("json::" + json);
|
||||
Assert.assertEquals(status, "ok");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPostCreateProject() {
|
||||
public void testDoPostCreateProject() throws IOException, ServletException, JSONException {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
long jobId = job.id;
|
||||
|
||||
long jobId = job.id;
|
||||
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database%2Fdatabase-import-controller&jobID="
|
||||
+ jobId + "&subCommand=create-project");
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
when(request.getQueryString()).thenReturn(
|
||||
"http://127.0.0.1:3333/command/core/importing-controller?controller=database%2Fdatabase-import-controller&jobID="
|
||||
+ jobId + "&subCommand=create-project");
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
when(request.getParameter("databasePort")).thenReturn("" + testDbConfig.getDatabasePort());
|
||||
when(request.getParameter("databaseUser")).thenReturn(testDbConfig.getDatabaseUser());
|
||||
when(request.getParameter("databasePassword")).thenReturn(testDbConfig.getDatabasePassword());
|
||||
when(request.getParameter("initialDatabase")).thenReturn(testDbConfig.getDatabaseName());
|
||||
when(request.getParameter("query")).thenReturn(query);
|
||||
when(request.getParameter("options")).thenReturn(JSON_OPTION);
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
when(request.getParameter("databasePort")).thenReturn("" + testDbConfig.getDatabasePort());
|
||||
when(request.getParameter("databaseUser")).thenReturn(testDbConfig.getDatabaseUser());
|
||||
when(request.getParameter("databasePassword")).thenReturn(testDbConfig.getDatabasePassword());
|
||||
when(request.getParameter("initialDatabase")).thenReturn(testDbConfig.getDatabaseName());
|
||||
when(request.getParameter("query")).thenReturn(query);
|
||||
when(request.getParameter("options")).thenReturn(JSON_OPTION);
|
||||
|
||||
|
||||
SUT.doPost(request, response);
|
||||
SUT.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String status = json.getString("status");
|
||||
//System.out.println("json::" + json);
|
||||
Assert.assertEquals(status, "ok");
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String status = json.getString("status");
|
||||
//System.out.println("json::" + json);
|
||||
Assert.assertEquals(status, "ok");
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
|
@ -62,16 +62,14 @@ public class DatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
@Test(groups = {"requiresPgSQL"})
|
||||
public void testGetPgSQLDBService() {
|
||||
|
||||
DatabaseService dbService = DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
Assert.assertNotNull(dbService);
|
||||
Assert.assertEquals(dbService.getClass(), PgSQLDatabaseService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testGetMySQLDBService() {
|
||||
|
||||
DatabaseService dbService = DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
@ -79,7 +77,7 @@ public class DatabaseServiceTest extends DBExtensionTests{
|
||||
Assert.assertEquals(dbService.getClass(), MySQLDatabaseService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(groups = {"requiresMariaDB"})
|
||||
public void testGetMariaDBSQLDBService() {
|
||||
|
||||
DatabaseService dbService = DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
@ -87,64 +85,34 @@ public class DatabaseServiceTest extends DBExtensionTests{
|
||||
Assert.assertEquals(dbService.getClass(), MariaDBDatabaseService.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
|
||||
try {
|
||||
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
Connection conn = dbService.getConnection(testDbConfig);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
Connection conn = dbService.getConnection(testDbConfig);
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
|
||||
try {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
boolean result = dbService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
boolean result = dbService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnect() {
|
||||
|
||||
try {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
DatabaseInfo databaseInfo = dbService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testConnect() throws DatabaseServiceException {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
DatabaseInfo databaseInfo = dbService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteQuery() {
|
||||
|
||||
try {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
DatabaseInfo databaseInfo = dbService.testQuery(testDbConfig,
|
||||
"SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testExecuteQuery() throws DatabaseServiceException {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
DatabaseInfo databaseInfo = dbService.testQuery(testDbConfig,
|
||||
"SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -157,44 +125,26 @@ public class DatabaseServiceTest extends DBExtensionTests{
|
||||
Assert.assertEquals(limitQuery, "SELECT * FROM " + testTable + " LIMIT " + 100 + " OFFSET " + 0 + ";");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetColumns() {
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testGetColumns() throws DatabaseServiceException {
|
||||
List<DatabaseColumn> dbColumns;
|
||||
|
||||
try {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
dbColumns = dbService.getColumns(testDbConfig,"SELECT * FROM " + testTable);
|
||||
Assert.assertNotNull(dbColumns);
|
||||
|
||||
int cols = dbColumns.size();
|
||||
Assert.assertEquals(cols, 10);
|
||||
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
dbColumns = dbService.getColumns(testDbConfig,"SELECT * FROM " + testTable);
|
||||
Assert.assertNotNull(dbColumns);
|
||||
|
||||
int cols = dbColumns.size();
|
||||
Assert.assertEquals(cols, 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRows() {
|
||||
|
||||
try {
|
||||
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
List<DatabaseRow> dbRows = dbService.getRows(testDbConfig,
|
||||
"SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbRows);
|
||||
Assert.assertEquals(dbRows.size(), 1);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
@Test(groups = {"requiresMySQL"})
|
||||
public void testGetRows() throws DatabaseServiceException {
|
||||
DatabaseService dbService = DatabaseService.get(testDbConfig.getDatabaseType());
|
||||
List<DatabaseRow> dbRows = dbService.getRows(testDbConfig,
|
||||
"SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbRows);
|
||||
Assert.assertEquals(dbRows.size(), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.google.refine.extension.database;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.testng.annotations.AfterSuite;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Optional;
|
||||
@ -30,7 +32,8 @@ public class DatabaseTestConfig extends DBExtensionTests {
|
||||
|
||||
@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) {
|
||||
@Optional(DEFAULT_MARIADB_PASSWORD) String mariadbDbPassword, @Optional(DEFAULT_TEST_TABLE) String mariadbTestTable)
|
||||
throws DatabaseServiceException, SQLException {
|
||||
|
||||
//System.out.println("@BeforeSuite\n");
|
||||
mysqlDbConfig = new DatabaseConfiguration();
|
||||
|
@ -3,12 +3,15 @@ package com.google.refine.extension.database.cmd;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@ -24,6 +27,7 @@ import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class ConnectCommandTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@ -63,7 +67,7 @@ public class ConnectCommandTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoPost() {
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -75,26 +79,19 @@ public class ConnectCommandTest extends DBExtensionTests {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
ConnectCommand connectCommand = new ConnectCommand();
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
ConnectCommand connectCommand = new ConnectCommand();
|
||||
|
||||
connectCommand.doPost(request, response);
|
||||
connectCommand.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
String databaseInfo = json.getString("databaseInfo");
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
String databaseInfo = json.getString("databaseInfo");
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,12 +2,15 @@ package com.google.refine.extension.database.cmd;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@ -22,7 +25,7 @@ import com.google.refine.extension.database.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class ExecuteQueryCommandTest extends DBExtensionTests {
|
||||
|
||||
@Mock
|
||||
@ -60,7 +63,7 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPost() {
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -75,26 +78,19 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
|
||||
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
ExecuteQueryCommand executeQueryCommand = new ExecuteQueryCommand();
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
ExecuteQueryCommand executeQueryCommand = new ExecuteQueryCommand();
|
||||
|
||||
executeQueryCommand.doPost(request, response);
|
||||
executeQueryCommand.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
String queryResult = json.getString("QueryResult");
|
||||
Assert.assertNotNull(queryResult);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
String queryResult = json.getString("QueryResult");
|
||||
Assert.assertNotNull(queryResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@ -135,7 +136,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPost() {
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
|
||||
when(request.getParameter("connectionName")).thenReturn("test-db-name");
|
||||
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
|
||||
@ -148,33 +149,24 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
|
||||
SUT.doPost(request, response);
|
||||
SUT.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
|
||||
JSONObject json = new JSONObject(result);
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
|
||||
int len = savedConnections.length();
|
||||
|
||||
Assert.assertEquals(len, 1);
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
int len = savedConnections.length();
|
||||
|
||||
Assert.assertEquals(len, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoGet() {
|
||||
public void testDoGet() throws IOException, ServletException, JSONException {
|
||||
String testDbName = "testLocalDb";
|
||||
//add saved connection
|
||||
saveDatabaseConfiguration(testDbName);
|
||||
@ -191,32 +183,25 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
|
||||
SUT.doGet(request, response);
|
||||
SUT.doGet(request, response);
|
||||
|
||||
JSONObject json = new JSONObject(sw.getBuffer().toString().trim());
|
||||
JSONObject json = new JSONObject(sw.getBuffer().toString().trim());
|
||||
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
|
||||
Assert.assertEquals(savedConnections.length(), 1);
|
||||
Assert.assertEquals(savedConnections.length(), 1);
|
||||
|
||||
JSONObject sc = (JSONObject)savedConnections.get(0);
|
||||
// System.out.println("sc" + sc);
|
||||
String connName = sc.getString("connectionName");
|
||||
Assert.assertEquals(connName, testDbName);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject sc = (JSONObject)savedConnections.get(0);
|
||||
// System.out.println("sc" + sc);
|
||||
String connName = sc.getString("connectionName");
|
||||
Assert.assertEquals(connName, testDbName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPut() {
|
||||
public void testDoPut() throws IOException, ServletException, JSONException {
|
||||
String testDbName = "testLocalDb";
|
||||
saveDatabaseConfiguration(testDbName);
|
||||
|
||||
@ -224,37 +209,30 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
|
||||
//modify database config
|
||||
String newHost = "localhost";
|
||||
when(request.getParameter("connectionName")).thenReturn(testDbName);
|
||||
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
|
||||
when(request.getParameter("databaseServer")).thenReturn(newHost);
|
||||
when(request.getParameter("databasePort")).thenReturn("" + testDbConfig.getDatabasePort());
|
||||
when(request.getParameter("databaseUser")).thenReturn(testDbConfig.getDatabaseUser());
|
||||
when(request.getParameter("databasePassword")).thenReturn(testDbConfig.getDatabasePassword());
|
||||
when(request.getParameter("initialDatabase")).thenReturn(testDbConfig.getDatabaseName());
|
||||
//modify database config
|
||||
String newHost = "localhost";
|
||||
when(request.getParameter("connectionName")).thenReturn(testDbName);
|
||||
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
|
||||
when(request.getParameter("databaseServer")).thenReturn(newHost);
|
||||
when(request.getParameter("databasePort")).thenReturn("" + testDbConfig.getDatabasePort());
|
||||
when(request.getParameter("databaseUser")).thenReturn(testDbConfig.getDatabaseUser());
|
||||
when(request.getParameter("databasePassword")).thenReturn(testDbConfig.getDatabasePassword());
|
||||
when(request.getParameter("initialDatabase")).thenReturn(testDbConfig.getDatabaseName());
|
||||
|
||||
SUT.doPut(request, response);
|
||||
SUT.doPut(request, response);
|
||||
|
||||
JSONObject json = new JSONObject(sw.getBuffer().toString().trim());
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
JSONObject json = new JSONObject(sw.getBuffer().toString().trim());
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
|
||||
Assert.assertEquals(savedConnections.length(), 1);
|
||||
Assert.assertEquals(savedConnections.length(), 1);
|
||||
|
||||
JSONObject sc = (JSONObject)savedConnections.get(0);
|
||||
System.out.println("sc" + sc);
|
||||
String newDbHost = sc.getString("databaseHost");
|
||||
Assert.assertEquals(newDbHost, newHost);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
JSONObject sc = (JSONObject)savedConnections.get(0);
|
||||
System.out.println("sc" + sc);
|
||||
String newDbHost = sc.getString("databaseHost");
|
||||
Assert.assertEquals(newDbHost, newHost);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2,12 +2,15 @@ package com.google.refine.extension.database.cmd;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@ -23,7 +26,7 @@ import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class TestConnectCommandTest extends DBExtensionTests{
|
||||
|
||||
@Mock
|
||||
@ -63,7 +66,7 @@ public class TestConnectCommandTest extends DBExtensionTests{
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoPost() {
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -77,23 +80,16 @@ public class TestConnectCommandTest extends DBExtensionTests{
|
||||
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
TestConnectCommand connectCommand = new TestConnectCommand();
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
TestConnectCommand connectCommand = new TestConnectCommand();
|
||||
|
||||
connectCommand.doPost(request, response);
|
||||
connectCommand.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,12 +2,15 @@ package com.google.refine.extension.database.cmd;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@ -22,7 +25,7 @@ import com.google.refine.extension.database.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class TestQueryCommandTest extends DBExtensionTests {
|
||||
|
||||
@Mock
|
||||
@ -61,7 +64,7 @@ public class TestQueryCommandTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoPost() {
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -76,25 +79,19 @@ public class TestQueryCommandTest extends DBExtensionTests {
|
||||
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
|
||||
try {
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
TestQueryCommand executeQueryCommand = new TestQueryCommand();
|
||||
when(response.getWriter()).thenReturn(pw);
|
||||
TestQueryCommand executeQueryCommand = new TestQueryCommand();
|
||||
|
||||
executeQueryCommand.doPost(request, response);
|
||||
executeQueryCommand.doPost(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
String code = json.getString("code");
|
||||
Assert.assertEquals(code, "ok");
|
||||
|
||||
String queryResult = json.getString("QueryResult");
|
||||
Assert.assertNotNull(queryResult);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
String queryResult = json.getString("QueryResult");
|
||||
Assert.assertNotNull(queryResult);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.google.refine.extension.database.mariadb;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.testng.Assert;
|
||||
@ -14,7 +15,7 @@ import com.google.refine.extension.database.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.DatabaseServiceException;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMariaDB" })
|
||||
public class MariaDBConnectionManagerTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@ -48,48 +49,27 @@ public class MariaDBConnectionManagerTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
|
||||
try {
|
||||
boolean conn = MariaDBConnectionManager.getInstance().testConnection(testDbConfig);
|
||||
Assert.assertEquals(conn, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
boolean conn = MariaDBConnectionManager.getInstance().testConnection(testDbConfig);
|
||||
Assert.assertEquals(conn, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
|
||||
try {
|
||||
Connection conn = MariaDBConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
Connection conn = MariaDBConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShutdown() {
|
||||
public void testShutdown() throws DatabaseServiceException, SQLException {
|
||||
Connection conn = MariaDBConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
try {
|
||||
Connection conn = MariaDBConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
MariaDBConnectionManager.getInstance().shutdown();
|
||||
|
||||
MariaDBConnectionManager.getInstance().shutdown();
|
||||
|
||||
if(conn != null) {
|
||||
Assert.assertEquals(conn.isClosed(), true);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(conn != null) {
|
||||
Assert.assertEquals(conn.isClosed(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import com.google.refine.extension.database.model.DatabaseColumn;
|
||||
import com.google.refine.extension.database.model.DatabaseInfo;
|
||||
import com.google.refine.extension.database.model.DatabaseRow;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMariaDB" })
|
||||
public class MariaDBDatabaseServiceTest extends DBExtensionTests{
|
||||
|
||||
|
||||
@ -63,60 +63,35 @@ public class MariaDBDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
try {
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService)DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
Connection conn = pgSqlService.getConnection(testDbConfig);
|
||||
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService)DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
Connection conn = pgSqlService.getConnection(testDbConfig);
|
||||
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
try {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService)DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService)DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
|
||||
boolean result = pgSqlService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean result = pgSqlService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnect() {
|
||||
try {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService)DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void testConnect() throws DatabaseServiceException {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService)DatabaseService.get(MariaDBDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteQuery() {
|
||||
public void testExecuteQuery() throws DatabaseServiceException {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService) DatabaseService
|
||||
.get(MariaDBDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.testQuery(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
try {
|
||||
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService) DatabaseService
|
||||
.get(MariaDBDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.testQuery(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -130,18 +105,12 @@ public class MariaDBDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRows() {
|
||||
try {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService) DatabaseService
|
||||
public void testGetRows() throws DatabaseServiceException {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService) DatabaseService
|
||||
.get(MariaDBDatabaseService.DB_NAME);
|
||||
List<DatabaseRow> dbRows = pgSqlService.getRows(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbRows);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -151,21 +120,15 @@ public class MariaDBDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetColumns() {
|
||||
public void testGetColumns() throws DatabaseServiceException {
|
||||
List<DatabaseColumn> dbColumns;
|
||||
|
||||
try {
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService) DatabaseService
|
||||
.get(MariaDBDatabaseService.DB_NAME);
|
||||
MariaDBDatabaseService pgSqlService = (MariaDBDatabaseService) DatabaseService
|
||||
.get(MariaDBDatabaseService.DB_NAME);
|
||||
|
||||
dbColumns = pgSqlService.getColumns(testDbConfig, "SELECT * FROM " + testTable);
|
||||
dbColumns = pgSqlService.getColumns(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbColumns);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(dbColumns);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.google.refine.extension.database.mysql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.testng.Assert;
|
||||
@ -14,6 +15,7 @@ import com.google.refine.extension.database.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.DatabaseServiceException;
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class MySQLConnectionManagerTest extends DBExtensionTests {
|
||||
|
||||
private DatabaseConfiguration testDbConfig;
|
||||
@ -45,49 +47,30 @@ public class MySQLConnectionManagerTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
|
||||
try {
|
||||
boolean conn = MySQLConnectionManager.getInstance().testConnection(testDbConfig);
|
||||
Assert.assertEquals(conn, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean conn = MySQLConnectionManager.getInstance().testConnection(testDbConfig);
|
||||
Assert.assertEquals(conn, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
|
||||
try {
|
||||
Connection conn = MySQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Connection conn = MySQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShutdown() {
|
||||
public void testShutdown() throws DatabaseServiceException, SQLException {
|
||||
|
||||
try {
|
||||
Connection conn = MySQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
Connection conn = MySQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
MySQLConnectionManager.getInstance().shutdown();
|
||||
|
||||
if(conn != null) {
|
||||
Assert.assertEquals(conn.isClosed(), true);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
MySQLConnectionManager.getInstance().shutdown();
|
||||
|
||||
if(conn != null) {
|
||||
Assert.assertEquals(conn.isClosed(), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import com.google.refine.extension.database.model.DatabaseInfo;
|
||||
import com.google.refine.extension.database.model.DatabaseRow;
|
||||
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class MySQLDatabaseServiceTest extends DBExtensionTests{
|
||||
|
||||
private DatabaseConfiguration testDbConfig;
|
||||
@ -62,60 +62,36 @@ public class MySQLDatabaseServiceTest extends DBExtensionTests{
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
try {
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService)DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
Connection conn = pgSqlService.getConnection(testDbConfig);
|
||||
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService)DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
Connection conn = pgSqlService.getConnection(testDbConfig);
|
||||
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
try {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService)DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService)DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
|
||||
boolean result = pgSqlService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean result = pgSqlService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnect() {
|
||||
try {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService)DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void testConnect() throws DatabaseServiceException {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService)DatabaseService.get(MySQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteQuery() {
|
||||
public void testExecuteQuery() throws DatabaseServiceException {
|
||||
|
||||
try {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService) DatabaseService
|
||||
.get(MySQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.testQuery(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService) DatabaseService
|
||||
.get(MySQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.testQuery(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -129,18 +105,12 @@ public class MySQLDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRows() {
|
||||
try {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService) DatabaseService
|
||||
.get(MySQLDatabaseService.DB_NAME);
|
||||
List<DatabaseRow> dbRows = pgSqlService.getRows(testDbConfig, "SELECT * FROM " + testTable);
|
||||
public void testGetRows() throws DatabaseServiceException {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService) DatabaseService
|
||||
.get(MySQLDatabaseService.DB_NAME);
|
||||
List<DatabaseRow> dbRows = pgSqlService.getRows(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbRows);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(dbRows);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -150,21 +120,14 @@ public class MySQLDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetColumns() {
|
||||
public void testGetColumns() throws DatabaseServiceException {
|
||||
List<DatabaseColumn> dbColumns;
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService) DatabaseService
|
||||
.get(MySQLDatabaseService.DB_NAME);
|
||||
|
||||
try {
|
||||
MySQLDatabaseService pgSqlService = (MySQLDatabaseService) DatabaseService
|
||||
.get(MySQLDatabaseService.DB_NAME);
|
||||
dbColumns = pgSqlService.getColumns(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
dbColumns = pgSqlService.getColumns(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbColumns);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(dbColumns);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.google.refine.extension.database.pgsql;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.testng.Assert;
|
||||
@ -15,7 +16,7 @@ import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.DatabaseServiceException;
|
||||
|
||||
|
||||
|
||||
@Test(groups = { "requiresPgSQL" })
|
||||
public class PgSQLConnectionManagerTest extends DBExtensionTests {
|
||||
|
||||
private DatabaseConfiguration testDbConfig;
|
||||
@ -48,48 +49,30 @@ public class PgSQLConnectionManagerTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
|
||||
try {
|
||||
boolean isConnected = PgSQLConnectionManager.getInstance().testConnection(testDbConfig);
|
||||
Assert.assertEquals(isConnected, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean isConnected = PgSQLConnectionManager.getInstance().testConnection(testDbConfig);
|
||||
Assert.assertEquals(isConnected, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
|
||||
try {
|
||||
Connection conn = PgSQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Connection conn = PgSQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShutdown() {
|
||||
public void testShutdown() throws DatabaseServiceException, SQLException {
|
||||
|
||||
try {
|
||||
Connection conn = PgSQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
Connection conn = PgSQLConnectionManager.getInstance().getConnection(testDbConfig, true);
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
PgSQLConnectionManager.getInstance().shutdown();
|
||||
PgSQLConnectionManager.getInstance().shutdown();
|
||||
|
||||
if(conn != null) {
|
||||
Assert.assertEquals(conn.isClosed(), true);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(conn != null) {
|
||||
Assert.assertEquals(conn.isClosed(), true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ import com.google.refine.extension.database.model.DatabaseColumn;
|
||||
import com.google.refine.extension.database.model.DatabaseInfo;
|
||||
import com.google.refine.extension.database.model.DatabaseRow;
|
||||
|
||||
|
||||
@Test(groups = { "requiresPgSQL" })
|
||||
public class PgSQLDatabaseServiceTest extends DBExtensionTests{
|
||||
|
||||
private DatabaseConfiguration testDbConfig;
|
||||
@ -61,60 +61,38 @@ public class PgSQLDatabaseServiceTest extends DBExtensionTests{
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetConnection() {
|
||||
try {
|
||||
public void testGetConnection() throws DatabaseServiceException {
|
||||
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService)DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
Connection conn = pgSqlService.getConnection(testDbConfig);
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService)DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
Connection conn = pgSqlService.getConnection(testDbConfig);
|
||||
|
||||
Assert.assertNotNull(conn);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(conn);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestConnection() {
|
||||
try {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService)DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
public void testTestConnection() throws DatabaseServiceException {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService)DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
|
||||
boolean result = pgSqlService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
boolean result = pgSqlService.testConnection(testDbConfig);
|
||||
Assert.assertEquals(result, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConnect() {
|
||||
try {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService)DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
public void testConnect() throws DatabaseServiceException {
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService)DatabaseService.get(PgSQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.connect(testDbConfig);
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExecuteQuery() {
|
||||
public void testExecuteQuery() throws DatabaseServiceException {
|
||||
|
||||
try {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService) DatabaseService
|
||||
.get(PgSQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.testQuery(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService) DatabaseService
|
||||
.get(PgSQLDatabaseService.DB_NAME);
|
||||
DatabaseInfo databaseInfo = pgSqlService.testQuery(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -128,18 +106,12 @@ public class PgSQLDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRows() {
|
||||
try {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService) DatabaseService
|
||||
.get(PgSQLDatabaseService.DB_NAME);
|
||||
List<DatabaseRow> dbRows = pgSqlService.getRows(testDbConfig, "SELECT * FROM " + testTable);
|
||||
public void testGetRows() throws DatabaseServiceException {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService) DatabaseService
|
||||
.get(PgSQLDatabaseService.DB_NAME);
|
||||
List<DatabaseRow> dbRows = pgSqlService.getRows(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbRows);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Assert.assertNotNull(dbRows);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -149,21 +121,16 @@ public class PgSQLDatabaseServiceTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetColumns() {
|
||||
public void testGetColumns() throws DatabaseServiceException {
|
||||
List<DatabaseColumn> dbColumns;
|
||||
|
||||
try {
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService) DatabaseService
|
||||
.get(PgSQLDatabaseService.DB_NAME);
|
||||
PgSQLDatabaseService pgSqlService = (PgSQLDatabaseService) DatabaseService
|
||||
.get(PgSQLDatabaseService.DB_NAME);
|
||||
|
||||
dbColumns = pgSqlService.getColumns(testDbConfig, "SELECT * FROM " + testTable);
|
||||
dbColumns = pgSqlService.getColumns(testDbConfig, "SELECT * FROM " + testTable);
|
||||
|
||||
Assert.assertNotNull(dbColumns);
|
||||
Assert.assertNotNull(dbColumns);
|
||||
|
||||
} catch (DatabaseServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user