Added more tests on SolrJsonReconcileServlet.
This commit is contained in:
parent
8c73bd95ba
commit
a839bdcc02
2 changed files with 56 additions and 9 deletions
|
@ -97,7 +97,7 @@ public class SolrJsonReconcileServlet extends VitroHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
protected JSONObject getResult(VitroRequest vreq, HttpServletRequest req,
|
||||
private JSONObject getResult(VitroRequest vreq, HttpServletRequest req,
|
||||
HttpServletResponse resp) throws ServletException {
|
||||
|
||||
HashMap<String, JSONObject> searchWithTypeMap = new HashMap<String, JSONObject>();
|
||||
|
@ -363,7 +363,7 @@ public class SolrJsonReconcileServlet extends VitroHttpServlet {
|
|||
return qJson;
|
||||
}
|
||||
|
||||
private SolrQuery getQuery(String queryStr, String searchType, int limit, ArrayList<String[]> propertiesList) {
|
||||
protected SolrQuery getQuery(String queryStr, String searchType, int limit, ArrayList<String[]> propertiesList) {
|
||||
|
||||
if ( queryStr == null) {
|
||||
log.error("There was no parameter '"+ PARAM_QUERY
|
||||
|
|
|
@ -2,20 +2,25 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.solr.client.solrj.SolrQuery;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpServletResponseStub;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
|
||||
/**
|
||||
|
@ -25,6 +30,9 @@ import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
|||
*/
|
||||
public class SolrJsonReconcileServletTest extends AbstractTestClass {
|
||||
|
||||
|
||||
|
||||
|
||||
private HttpServletRequestStub request;
|
||||
private HttpServletResponseStub response;
|
||||
private SolrJsonReconcileServlet reconcile;
|
||||
|
@ -50,11 +58,50 @@ public class SolrJsonReconcileServletTest extends AbstractTestClass {
|
|||
jsonResult = reconcile.getMetadata(request, response, defaultNamespace, defaultTypeList, serverName, serverPort);
|
||||
schemaSpaceOutput = jsonResult.getString("schemaSpace");
|
||||
} catch (ServletException e) {
|
||||
System.err.println("SolrJsonReconcileServletTest ServletException: " + e);
|
||||
System.err.println("SolrJsonReconcileServletTest getMetadata ServletException: " + e);
|
||||
} catch (JSONException e) {
|
||||
System.err.println("SolrJsonReconcileServletTest JSONException: " + e);
|
||||
System.err.println("SolrJsonReconcileServletTest getMetadata JSONException: " + e);
|
||||
}
|
||||
Assert.assertNotNull("output should not be null", jsonResult);
|
||||
Assert.assertEquals("schemaSpaceOutput", defaultNamespace, schemaSpaceOutput);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getQuery() {
|
||||
// contruct query
|
||||
int rowNum = 3;
|
||||
|
||||
String nameStr = "Joe";
|
||||
String nameType = "http://xmlns.com/foaf/0.1/Person";
|
||||
|
||||
ArrayList<String[]> propertiesList = new ArrayList<String[]>();
|
||||
String orgStr = "Something";
|
||||
String orgType = "http://xmlns.com/foaf/0.1/Organization";
|
||||
String[] properties = {orgType, orgStr};
|
||||
propertiesList.add(properties);
|
||||
|
||||
// test getQuery
|
||||
SolrQuery solrQuery = reconcile.getQuery(nameStr, nameType, rowNum, propertiesList);
|
||||
String messagePrefix = "Query should contain the text: ";
|
||||
testAssertTrue(messagePrefix + orgStr, orgStr, solrQuery.toString());
|
||||
testAssertTrue(messagePrefix + nameStr, nameStr, solrQuery.toString());
|
||||
testAssertTrue(messagePrefix + orgType, orgType, solrQuery.toString());
|
||||
testAssertTrue(messagePrefix + nameType, orgType, solrQuery.toString());
|
||||
}
|
||||
|
||||
private void testAssertTrue(String message, String inputStr, String resultStr) {
|
||||
try {
|
||||
String modStr = null;
|
||||
if (inputStr.contains(":") && inputStr.contains("/")) {
|
||||
modStr = inputStr.replaceAll(":", "%3A").replaceAll("/", "%2F");
|
||||
} else {
|
||||
modStr = inputStr;
|
||||
}
|
||||
Pattern regex = Pattern.compile(modStr);
|
||||
Matcher regexMatcher = regex.matcher(resultStr);
|
||||
Assert.assertTrue(message, regexMatcher.find());
|
||||
} catch (PatternSyntaxException ex) {
|
||||
// Syntax error in the regular expression
|
||||
}
|
||||
assertNotNull("output should not be null", jsonResult);
|
||||
assertEquals("schemaSpaceOutput", defaultNamespace, schemaSpaceOutput);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue