Remove all mentions of org.json in database extension

This commit is contained in:
Antonin Delpeuch 2018-11-21 11:12:26 +00:00
parent 142a2d8beb
commit 916ede440b
8 changed files with 73 additions and 78 deletions

View File

@ -39,8 +39,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -141,8 +139,8 @@ public class DatabaseImportController implements ImportingController {
} }
JSONObject result = new JSONObject(); ObjectNode result = ParsingUtilities.mapper.createObjectNode();
JSONObject options = new JSONObject(); ObjectNode options = ParsingUtilities.mapper.createObjectNode();
JSONUtilities.safePut(result, "status", "ok"); JSONUtilities.safePut(result, "status", "ok");
JSONUtilities.safePut(result, OPTIONS_KEY, options); JSONUtilities.safePut(result, OPTIONS_KEY, options);
@ -220,7 +218,7 @@ public class DatabaseImportController implements ImportingController {
writer.writeStringField("message", getExceptionString(exceptions)); writer.writeStringField("message", getExceptionString(exceptions));
} }
writer.writeEndObject(); writer.writeEndObject();
} catch (JSONException e) { } catch (IOException e) {
throw new ServletException(e); throw new ServletException(e);
} finally { } finally {
writer.flush(); writer.flush();
@ -229,7 +227,7 @@ public class DatabaseImportController implements ImportingController {
w.close(); w.close();
} }
} catch (JSONException e) { } catch (IOException e) {
throw new ServletException(e); throw new ServletException(e);
} finally { } finally {
job.touch(); job.touch();
@ -372,7 +370,7 @@ public class DatabaseImportController implements ImportingController {
}.start(); }.start();
HttpUtilities.respond(response, "ok", "done"); HttpUtilities.respond(response, "ok", "done");
} catch (JSONException e) { } catch (IOException e) {
throw new ServletException(e); throw new ServletException(e);
} }
} }

View File

@ -37,7 +37,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.json.JSONException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -119,7 +118,7 @@ public class SavedConnectionCommand extends DatabaseCommand {
* @throws IOException * @throws IOException
* @throws JSONException * @throws JSONException
*/ */
private void writeSavedConnectionResponse(HttpServletResponse response, DatabaseConfiguration savedConnection) throws IOException, JSONException { private void writeSavedConnectionResponse(HttpServletResponse response, DatabaseConfiguration savedConnection) throws IOException {
Writer w = response.getWriter(); Writer w = response.getWriter();
try { try {
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w); JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
@ -167,7 +166,7 @@ public class SavedConnectionCommand extends DatabaseCommand {
* @throws IOException * @throws IOException
* @throws JSONException * @throws JSONException
*/ */
private void writeSavedConnectionResponse(HttpServletResponse response) throws IOException, JSONException { private void writeSavedConnectionResponse(HttpServletResponse response) throws IOException {
Writer w = response.getWriter(); Writer w = response.getWriter();
try { try {

View File

@ -12,8 +12,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.Assert; import org.testng.Assert;
@ -24,6 +22,7 @@ import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.refine.ProjectManager; import com.google.refine.ProjectManager;
import com.google.refine.ProjectMetadata; import com.google.refine.ProjectMetadata;
import com.google.refine.RefineServlet; import com.google.refine.RefineServlet;
@ -33,6 +32,7 @@ import com.google.refine.importing.ImportingJob;
import com.google.refine.importing.ImportingManager; import com.google.refine.importing.ImportingManager;
import com.google.refine.io.FileProjectManager; import com.google.refine.io.FileProjectManager;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.util.ParsingUtilities;
@ -60,7 +60,7 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
private DatabaseImportController SUT = null; private DatabaseImportController SUT = null;
@BeforeMethod @BeforeMethod
public void setUp() throws JSONException, IOException { public void setUp() throws IOException {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir"); File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir");
@ -102,10 +102,9 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
SUT.doGet(request, response); SUT.doGet(request, response);
String result = sw.getBuffer().toString().trim(); String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(result); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String code = json.get("status").asText();
String code = json.getString("status"); String message = json.get("message").asText();
String message = json.getString("message");
Assert.assertNotNull(code); Assert.assertNotNull(code);
Assert.assertNotNull(message); Assert.assertNotNull(message);
Assert.assertEquals(code, "error"); Assert.assertEquals(code, "error");
@ -119,7 +118,7 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
} }
@Test @Test
public void testDoPostInvalidSubCommand() throws IOException, ServletException, JSONException { public void testDoPostInvalidSubCommand() throws IOException, ServletException {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
when(request.getQueryString()).thenReturn( when(request.getQueryString()).thenReturn(
@ -130,10 +129,10 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
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); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String code = json.getString("status"); String code = json.get("status").asText();
String message = json.getString("message"); String message = json.get("message").asText();
Assert.assertNotNull(code); Assert.assertNotNull(code);
Assert.assertNotNull(message); Assert.assertNotNull(message);
Assert.assertEquals(code, "error"); Assert.assertEquals(code, "error");
@ -143,7 +142,7 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
@Test @Test
public void testDoPostInitializeParser() throws ServletException, IOException, JSONException { public void testDoPostInitializeParser() throws ServletException, IOException {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
@ -155,15 +154,15 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
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); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String status = json.getString("status"); String status = json.get("status").asText();
//System.out.println("json::" + json); //System.out.println("json::" + json);
Assert.assertEquals(status, "ok"); Assert.assertEquals(status, "ok");
} }
@Test @Test
public void testDoPostParsePreview() throws IOException, ServletException, JSONException { public void testDoPostParsePreview() throws IOException, ServletException {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
@ -188,15 +187,15 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
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); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String status = json.getString("status"); String status = json.get("status").asText();
//System.out.println("json::" + json); //System.out.println("json::" + json);
Assert.assertEquals(status, "ok"); Assert.assertEquals(status, "ok");
} }
@Test @Test
public void testDoPostCreateProject() throws IOException, ServletException, JSONException { public void testDoPostCreateProject() throws IOException, ServletException {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
@ -222,9 +221,9 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
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); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String status = json.getString("status"); String status = json.get("status").asText();
//System.out.println("json::" + json); //System.out.println("json::" + json);
Assert.assertEquals(status, "ok"); Assert.assertEquals(status, "ok");
} }

View File

@ -11,8 +11,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.Assert; import org.testng.Assert;
@ -21,10 +19,12 @@ import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.refine.extension.database.DBExtensionTests; import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration; import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService; import com.google.refine.extension.database.DatabaseService;
import com.google.refine.extension.database.mysql.MySQLDatabaseService; import com.google.refine.extension.database.mysql.MySQLDatabaseService;
import com.google.refine.util.ParsingUtilities;
@Test(groups = { "requiresMySQL" }) @Test(groups = { "requiresMySQL" })
@ -67,7 +67,7 @@ public class ConnectCommandTest extends DBExtensionTests {
@Test @Test
public void testDoPost() throws IOException, ServletException, JSONException { public void testDoPost() throws IOException, ServletException {
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME); when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost()); when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
@ -85,12 +85,12 @@ public class ConnectCommandTest extends DBExtensionTests {
connectCommand.doPost(request, response); connectCommand.doPost(request, response);
String result = sw.getBuffer().toString().trim(); String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(result); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String code = json.getString("code"); String code = json.get("code").asText();
Assert.assertEquals(code, "ok"); Assert.assertEquals(code, "ok");
String databaseInfo = json.getString("databaseInfo"); String databaseInfo = json.get("databaseInfo").asText();
Assert.assertNotNull(databaseInfo); Assert.assertNotNull(databaseInfo);
} }

View File

@ -10,8 +10,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.Assert; import org.testng.Assert;
@ -20,10 +18,12 @@ import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.refine.extension.database.DBExtensionTests; import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration; import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService; import com.google.refine.extension.database.DatabaseService;
import com.google.refine.extension.database.mysql.MySQLDatabaseService; import com.google.refine.extension.database.mysql.MySQLDatabaseService;
import com.google.refine.util.ParsingUtilities;
@Test(groups = { "requiresMySQL" }) @Test(groups = { "requiresMySQL" })
public class ExecuteQueryCommandTest extends DBExtensionTests { public class ExecuteQueryCommandTest extends DBExtensionTests {
@ -63,7 +63,7 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
} }
@Test @Test
public void testDoPost() throws IOException, ServletException, JSONException { public void testDoPost() throws IOException, ServletException {
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType()); when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost()); when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
@ -84,12 +84,12 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
executeQueryCommand.doPost(request, response); executeQueryCommand.doPost(request, response);
String result = sw.getBuffer().toString().trim(); String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(result); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String code = json.getString("code"); String code = json.get("code").asText();
Assert.assertEquals(code, "ok"); Assert.assertEquals(code, "ok");
String queryResult = json.getString("QueryResult"); String queryResult = json.get("QueryResult").asText();
Assert.assertNotNull(queryResult); Assert.assertNotNull(queryResult);
} }

View File

@ -11,9 +11,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.Assert; import org.testng.Assert;
@ -24,6 +21,8 @@ import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.refine.ProjectManager; import com.google.refine.ProjectManager;
import com.google.refine.ProjectMetadata; import com.google.refine.ProjectMetadata;
import com.google.refine.RefineServlet; import com.google.refine.RefineServlet;
@ -36,6 +35,7 @@ import com.google.refine.extension.database.stub.RefineDbServletStub;
import com.google.refine.importing.ImportingManager; import com.google.refine.importing.ImportingManager;
import com.google.refine.io.FileProjectManager; import com.google.refine.io.FileProjectManager;
import com.google.refine.model.Project; import com.google.refine.model.Project;
import com.google.refine.util.ParsingUtilities;
public class SavedConnectionCommandTest extends DBExtensionTests{ public class SavedConnectionCommandTest extends DBExtensionTests{
@ -59,7 +59,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
private SavedConnectionCommand SUT = null; private SavedConnectionCommand SUT = null;
@BeforeMethod @BeforeMethod
public void setUp() throws JSONException, IOException { public void setUp() throws IOException {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir"); File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir");
@ -136,7 +136,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
} }
@Test @Test
public void testDoPost() throws IOException, ServletException, JSONException { public void testDoPost() throws IOException, ServletException {
when(request.getParameter("connectionName")).thenReturn("test-db-name"); when(request.getParameter("connectionName")).thenReturn("test-db-name");
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME); when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
@ -155,18 +155,18 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
String result = sw.getBuffer().toString().trim(); String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(result); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
JSONArray savedConnections = json.getJSONArray("savedConnections"); ArrayNode savedConnections = (ArrayNode) json.get("savedConnections");
Assert.assertNotNull(savedConnections); Assert.assertNotNull(savedConnections);
int len = savedConnections.length(); int len = savedConnections.size();
Assert.assertEquals(len, 1); Assert.assertEquals(len, 1);
} }
@Test @Test
public void testDoGet() throws IOException, ServletException, JSONException { public void testDoGet() throws IOException, ServletException {
String testDbName = "testLocalDb"; String testDbName = "testLocalDb";
//add saved connection //add saved connection
saveDatabaseConfiguration(testDbName); saveDatabaseConfiguration(testDbName);
@ -187,21 +187,20 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
SUT.doGet(request, response); SUT.doGet(request, response);
JSONObject json = new JSONObject(sw.getBuffer().toString().trim()); ObjectNode json = ParsingUtilities.mapper.readValue(sw.getBuffer().toString().trim(), ObjectNode.class);
JSONArray savedConnections = json.getJSONArray("savedConnections"); ArrayNode savedConnections = (ArrayNode) json.get("savedConnections");
Assert.assertNotNull(savedConnections); Assert.assertNotNull(savedConnections);
Assert.assertEquals(savedConnections.length(), 1); Assert.assertEquals(savedConnections.size(), 1);
JSONObject sc = (JSONObject)savedConnections.get(0); ObjectNode sc = (ObjectNode)savedConnections.get(0);
// System.out.println("sc" + sc); String connName = sc.get("connectionName").asText();
String connName = sc.getString("connectionName");
Assert.assertEquals(connName, testDbName); Assert.assertEquals(connName, testDbName);
} }
@Test @Test
public void testDoPut() throws IOException, ServletException, JSONException { public void testDoPut() throws IOException, ServletException {
String testDbName = "testLocalDb"; String testDbName = "testLocalDb";
saveDatabaseConfiguration(testDbName); saveDatabaseConfiguration(testDbName);
@ -223,15 +222,15 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
SUT.doPut(request, response); SUT.doPut(request, response);
JSONObject json = new JSONObject(sw.getBuffer().toString().trim()); ObjectNode json = ParsingUtilities.mapper.readValue(sw.getBuffer().toString().trim(), ObjectNode.class);
JSONArray savedConnections = json.getJSONArray("savedConnections"); ArrayNode savedConnections = (ArrayNode) json.get("savedConnections");
Assert.assertNotNull(savedConnections); Assert.assertNotNull(savedConnections);
Assert.assertEquals(savedConnections.length(), 1); Assert.assertEquals(savedConnections.size(), 1);
JSONObject sc = (JSONObject)savedConnections.get(0); ObjectNode sc = (ObjectNode)savedConnections.get(0);
System.out.println("sc" + sc); System.out.println("sc" + sc);
String newDbHost = sc.getString("databaseHost"); String newDbHost = sc.get("databaseHost").asText();
Assert.assertEquals(newDbHost, newHost); Assert.assertEquals(newDbHost, newHost);
} }
@ -249,11 +248,11 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
when(request.getParameter("connectionName")).thenReturn(testDbName); when(request.getParameter("connectionName")).thenReturn(testDbName);
SUT.doDelete(request, response); SUT.doDelete(request, response);
JSONObject json = new JSONObject(sw.getBuffer().toString().trim()); ObjectNode json = ParsingUtilities.mapper.readValue(sw.getBuffer().toString().trim(), ObjectNode.class);
JSONArray savedConnections = json.getJSONArray("savedConnections"); ArrayNode savedConnections = (ArrayNode) json.get("savedConnections");
Assert.assertNotNull(savedConnections); Assert.assertNotNull(savedConnections);
Assert.assertEquals(savedConnections.length(), 0); Assert.assertEquals(savedConnections.size(), 0);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -279,7 +278,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
// String result = sw.getBuffer().toString().trim(); // String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(); ObjectNode json = ParsingUtilities.mapper.createObjectNode();
Assert.assertNotNull(json); Assert.assertNotNull(json);

View File

@ -10,8 +10,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.Assert; import org.testng.Assert;
@ -20,10 +18,12 @@ import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.refine.extension.database.DBExtensionTests; import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration; import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService; import com.google.refine.extension.database.DatabaseService;
import com.google.refine.extension.database.mysql.MySQLDatabaseService; import com.google.refine.extension.database.mysql.MySQLDatabaseService;
import com.google.refine.util.ParsingUtilities;
@Test(groups = { "requiresMySQL" }) @Test(groups = { "requiresMySQL" })
@ -66,7 +66,7 @@ public class TestConnectCommandTest extends DBExtensionTests{
@Test @Test
public void testDoPost() throws IOException, ServletException, JSONException { public void testDoPost() throws IOException, ServletException {
when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME); when(request.getParameter("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost()); when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
@ -86,9 +86,9 @@ public class TestConnectCommandTest extends DBExtensionTests{
connectCommand.doPost(request, response); connectCommand.doPost(request, response);
String result = sw.getBuffer().toString().trim(); String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(result); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String code = json.getString("code"); String code = json.get("code").asText();
Assert.assertEquals(code, "ok"); Assert.assertEquals(code, "ok");
} }

View File

@ -10,8 +10,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.testng.Assert; import org.testng.Assert;
@ -20,10 +18,12 @@ import org.testng.annotations.Optional;
import org.testng.annotations.Parameters; import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.refine.extension.database.DBExtensionTests; import com.google.refine.extension.database.DBExtensionTests;
import com.google.refine.extension.database.DatabaseConfiguration; import com.google.refine.extension.database.DatabaseConfiguration;
import com.google.refine.extension.database.DatabaseService; import com.google.refine.extension.database.DatabaseService;
import com.google.refine.extension.database.mysql.MySQLDatabaseService; import com.google.refine.extension.database.mysql.MySQLDatabaseService;
import com.google.refine.util.ParsingUtilities;
@Test(groups = { "requiresMySQL" }) @Test(groups = { "requiresMySQL" })
public class TestQueryCommandTest extends DBExtensionTests { public class TestQueryCommandTest extends DBExtensionTests {
@ -64,7 +64,7 @@ public class TestQueryCommandTest extends DBExtensionTests {
@Test @Test
public void testDoPost() throws IOException, ServletException, JSONException { public void testDoPost() throws IOException, ServletException {
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType()); when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost()); when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
@ -85,12 +85,12 @@ public class TestQueryCommandTest extends DBExtensionTests {
executeQueryCommand.doPost(request, response); executeQueryCommand.doPost(request, response);
String result = sw.getBuffer().toString().trim(); String result = sw.getBuffer().toString().trim();
JSONObject json = new JSONObject(result); ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
String code = json.getString("code"); String code = json.get("code").asText();
Assert.assertEquals(code, "ok"); Assert.assertEquals(code, "ok");
String queryResult = json.getString("QueryResult"); String queryResult = json.get("QueryResult").asText();
Assert.assertNotNull(queryResult); Assert.assertNotNull(queryResult);
} }