Remove all mentions of org.json in database extension
This commit is contained in:
parent
142a2d8beb
commit
916ede440b
@ -39,8 +39,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -141,8 +139,8 @@ public class DatabaseImportController implements ImportingController {
|
||||
}
|
||||
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
JSONObject options = new JSONObject();
|
||||
ObjectNode result = ParsingUtilities.mapper.createObjectNode();
|
||||
ObjectNode options = ParsingUtilities.mapper.createObjectNode();
|
||||
JSONUtilities.safePut(result, "status", "ok");
|
||||
JSONUtilities.safePut(result, OPTIONS_KEY, options);
|
||||
|
||||
@ -220,7 +218,7 @@ public class DatabaseImportController implements ImportingController {
|
||||
writer.writeStringField("message", getExceptionString(exceptions));
|
||||
}
|
||||
writer.writeEndObject();
|
||||
} catch (JSONException e) {
|
||||
} catch (IOException e) {
|
||||
throw new ServletException(e);
|
||||
} finally {
|
||||
writer.flush();
|
||||
@ -229,7 +227,7 @@ public class DatabaseImportController implements ImportingController {
|
||||
w.close();
|
||||
}
|
||||
|
||||
} catch (JSONException e) {
|
||||
} catch (IOException e) {
|
||||
throw new ServletException(e);
|
||||
} finally {
|
||||
job.touch();
|
||||
@ -372,7 +370,7 @@ public class DatabaseImportController implements ImportingController {
|
||||
}.start();
|
||||
|
||||
HttpUtilities.respond(response, "ok", "done");
|
||||
} catch (JSONException e) {
|
||||
} catch (IOException e) {
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -119,7 +118,7 @@ public class SavedConnectionCommand extends DatabaseCommand {
|
||||
* @throws IOException
|
||||
* @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();
|
||||
try {
|
||||
JsonGenerator writer = ParsingUtilities.mapper.getFactory().createGenerator(w);
|
||||
@ -167,7 +166,7 @@ public class SavedConnectionCommand extends DatabaseCommand {
|
||||
* @throws IOException
|
||||
* @throws JSONException
|
||||
*/
|
||||
private void writeSavedConnectionResponse(HttpServletResponse response) throws IOException, JSONException {
|
||||
private void writeSavedConnectionResponse(HttpServletResponse response) throws IOException {
|
||||
Writer w = response.getWriter();
|
||||
try {
|
||||
|
||||
|
@ -12,8 +12,6 @@ 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;
|
||||
import org.testng.Assert;
|
||||
@ -24,6 +22,7 @@ import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import com.google.refine.ProjectManager;
|
||||
import com.google.refine.ProjectMetadata;
|
||||
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.io.FileProjectManager;
|
||||
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;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() throws JSONException, IOException {
|
||||
public void setUp() throws IOException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir");
|
||||
@ -102,10 +102,9 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
SUT.doGet(request, response);
|
||||
|
||||
String result = sw.getBuffer().toString().trim();
|
||||
JSONObject json = new JSONObject(result);
|
||||
|
||||
String code = json.getString("status");
|
||||
String message = json.getString("message");
|
||||
ObjectNode json = ParsingUtilities.mapper.readValue(result, ObjectNode.class);
|
||||
String code = json.get("status").asText();
|
||||
String message = json.get("message").asText();
|
||||
Assert.assertNotNull(code);
|
||||
Assert.assertNotNull(message);
|
||||
Assert.assertEquals(code, "error");
|
||||
@ -119,7 +118,7 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPostInvalidSubCommand() throws IOException, ServletException, JSONException {
|
||||
public void testDoPostInvalidSubCommand() throws IOException, ServletException {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
when(request.getQueryString()).thenReturn(
|
||||
@ -130,10 +129,10 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
SUT.doPost(request, response);
|
||||
|
||||
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 message = json.getString("message");
|
||||
String code = json.get("status").asText();
|
||||
String message = json.get("message").asText();
|
||||
Assert.assertNotNull(code);
|
||||
Assert.assertNotNull(message);
|
||||
Assert.assertEquals(code, "error");
|
||||
@ -143,7 +142,7 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoPostInitializeParser() throws ServletException, IOException, JSONException {
|
||||
public void testDoPostInitializeParser() throws ServletException, IOException {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
@ -155,15 +154,15 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
SUT.doPost(request, response);
|
||||
|
||||
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);
|
||||
Assert.assertEquals(status, "ok");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPostParsePreview() throws IOException, ServletException, JSONException {
|
||||
public void testDoPostParsePreview() throws IOException, ServletException {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
@ -188,15 +187,15 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
SUT.doPost(request, response);
|
||||
|
||||
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);
|
||||
Assert.assertEquals(status, "ok");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPostCreateProject() throws IOException, ServletException, JSONException {
|
||||
public void testDoPostCreateProject() throws IOException, ServletException {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
@ -222,9 +221,9 @@ public class DatabaseImportControllerTest extends DBExtensionTests{
|
||||
SUT.doPost(request, response);
|
||||
|
||||
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);
|
||||
Assert.assertEquals(status, "ok");
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ 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;
|
||||
import org.testng.Assert;
|
||||
@ -21,10 +19,12 @@ import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
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.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
@ -67,7 +67,7 @@ public class ConnectCommandTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@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("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -85,12 +85,12 @@ public class ConnectCommandTest extends DBExtensionTests {
|
||||
connectCommand.doPost(request, response);
|
||||
|
||||
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");
|
||||
|
||||
String databaseInfo = json.getString("databaseInfo");
|
||||
String databaseInfo = json.get("databaseInfo").asText();
|
||||
Assert.assertNotNull(databaseInfo);
|
||||
}
|
||||
|
||||
|
@ -10,8 +10,6 @@ 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;
|
||||
import org.testng.Assert;
|
||||
@ -20,10 +18,12 @@ import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
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.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class ExecuteQueryCommandTest extends DBExtensionTests {
|
||||
@ -63,7 +63,7 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
public void testDoPost() throws IOException, ServletException {
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -84,12 +84,12 @@ public class ExecuteQueryCommandTest extends DBExtensionTests {
|
||||
executeQueryCommand.doPost(request, response);
|
||||
|
||||
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");
|
||||
|
||||
String queryResult = json.getString("QueryResult");
|
||||
String queryResult = json.get("QueryResult").asText();
|
||||
Assert.assertNotNull(queryResult);
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.testng.Assert;
|
||||
@ -24,6 +21,8 @@ import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
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.ProjectMetadata;
|
||||
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.io.FileProjectManager;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
|
||||
@ -59,7 +59,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
private SavedConnectionCommand SUT = null;
|
||||
|
||||
@BeforeMethod
|
||||
public void setUp() throws JSONException, IOException {
|
||||
public void setUp() throws IOException {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
File dir = DBExtensionTestUtils.createTempDirectory("OR_DBExtension_Test_WorkspaceDir");
|
||||
@ -136,7 +136,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
}
|
||||
|
||||
@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("databaseType")).thenReturn(MySQLDatabaseService.DB_NAME);
|
||||
@ -155,18 +155,18 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
|
||||
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);
|
||||
|
||||
int len = savedConnections.length();
|
||||
int len = savedConnections.size();
|
||||
|
||||
Assert.assertEquals(len, 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoGet() throws IOException, ServletException, JSONException {
|
||||
public void testDoGet() throws IOException, ServletException {
|
||||
String testDbName = "testLocalDb";
|
||||
//add saved connection
|
||||
saveDatabaseConfiguration(testDbName);
|
||||
@ -187,21 +187,20 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
|
||||
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.assertEquals(savedConnections.length(), 1);
|
||||
Assert.assertEquals(savedConnections.size(), 1);
|
||||
|
||||
JSONObject sc = (JSONObject)savedConnections.get(0);
|
||||
// System.out.println("sc" + sc);
|
||||
String connName = sc.getString("connectionName");
|
||||
ObjectNode sc = (ObjectNode)savedConnections.get(0);
|
||||
String connName = sc.get("connectionName").asText();
|
||||
Assert.assertEquals(connName, testDbName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoPut() throws IOException, ServletException, JSONException {
|
||||
public void testDoPut() throws IOException, ServletException {
|
||||
String testDbName = "testLocalDb";
|
||||
saveDatabaseConfiguration(testDbName);
|
||||
|
||||
@ -223,15 +222,15 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
|
||||
SUT.doPut(request, response);
|
||||
|
||||
JSONObject json = new JSONObject(sw.getBuffer().toString().trim());
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
ObjectNode json = ParsingUtilities.mapper.readValue(sw.getBuffer().toString().trim(), ObjectNode.class);
|
||||
ArrayNode savedConnections = (ArrayNode) json.get("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 newDbHost = sc.getString("databaseHost");
|
||||
String newDbHost = sc.get("databaseHost").asText();
|
||||
Assert.assertEquals(newDbHost, newHost);
|
||||
}
|
||||
|
||||
@ -249,11 +248,11 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
when(request.getParameter("connectionName")).thenReturn(testDbName);
|
||||
SUT.doDelete(request, response);
|
||||
|
||||
JSONObject json = new JSONObject(sw.getBuffer().toString().trim());
|
||||
JSONArray savedConnections = json.getJSONArray("savedConnections");
|
||||
ObjectNode json = ParsingUtilities.mapper.readValue(sw.getBuffer().toString().trim(), ObjectNode.class);
|
||||
ArrayNode savedConnections = (ArrayNode) json.get("savedConnections");
|
||||
Assert.assertNotNull(savedConnections);
|
||||
|
||||
Assert.assertEquals(savedConnections.length(), 0);
|
||||
Assert.assertEquals(savedConnections.size(), 0);
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
@ -279,7 +278,7 @@ public class SavedConnectionCommandTest extends DBExtensionTests{
|
||||
|
||||
// String result = sw.getBuffer().toString().trim();
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
ObjectNode json = ParsingUtilities.mapper.createObjectNode();
|
||||
|
||||
Assert.assertNotNull(json);
|
||||
|
||||
|
@ -10,8 +10,6 @@ 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;
|
||||
import org.testng.Assert;
|
||||
@ -20,10 +18,12 @@ import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
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.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
@ -66,7 +66,7 @@ public class TestConnectCommandTest extends DBExtensionTests{
|
||||
|
||||
|
||||
@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("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -86,9 +86,9 @@ public class TestConnectCommandTest extends DBExtensionTests{
|
||||
connectCommand.doPost(request, response);
|
||||
|
||||
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");
|
||||
|
||||
}
|
||||
|
@ -10,8 +10,6 @@ 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;
|
||||
import org.testng.Assert;
|
||||
@ -20,10 +18,12 @@ import org.testng.annotations.Optional;
|
||||
import org.testng.annotations.Parameters;
|
||||
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.DatabaseConfiguration;
|
||||
import com.google.refine.extension.database.DatabaseService;
|
||||
import com.google.refine.extension.database.mysql.MySQLDatabaseService;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
@Test(groups = { "requiresMySQL" })
|
||||
public class TestQueryCommandTest extends DBExtensionTests {
|
||||
@ -64,7 +64,7 @@ public class TestQueryCommandTest extends DBExtensionTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoPost() throws IOException, ServletException, JSONException {
|
||||
public void testDoPost() throws IOException, ServletException {
|
||||
|
||||
when(request.getParameter("databaseType")).thenReturn(testDbConfig.getDatabaseType());
|
||||
when(request.getParameter("databaseServer")).thenReturn(testDbConfig.getDatabaseHost());
|
||||
@ -85,12 +85,12 @@ public class TestQueryCommandTest extends DBExtensionTests {
|
||||
executeQueryCommand.doPost(request, response);
|
||||
|
||||
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");
|
||||
|
||||
String queryResult = json.getString("QueryResult");
|
||||
String queryResult = json.get("QueryResult").asText();
|
||||
Assert.assertNotNull(queryResult);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user