Modified JSONReconcileServlet and related test class to be the same as SolrJsonReconcileServlet. They are all identical now.
This commit is contained in:
parent
61f5d87331
commit
d98967a7e3
3 changed files with 312 additions and 184 deletions
|
@ -2,22 +2,27 @@
|
|||
|
||||
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 edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpServletResponseStub;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Tests on various methods in the class.
|
||||
* @author Eliza Chan (elc2013@med.cornell.edu)
|
||||
|
@ -25,9 +30,12 @@ import org.junit.Test;
|
|||
*/
|
||||
public class JSONReconcileServletTest extends AbstractTestClass {
|
||||
|
||||
|
||||
|
||||
|
||||
private HttpServletRequestStub request;
|
||||
private HttpServletResponseStub response;
|
||||
private JSONReconcileServlet reconcile;
|
||||
private SolrJsonReconcileServlet reconcile;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
|
@ -35,7 +43,7 @@ public class JSONReconcileServletTest extends AbstractTestClass {
|
|||
request.setRequestUrl(new URL("http://vivo.this.that/reconcile"));
|
||||
request.setMethod("POST");
|
||||
response = new HttpServletResponseStub();
|
||||
reconcile = new JSONReconcileServlet();
|
||||
reconcile = new SolrJsonReconcileServlet();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,11 +58,51 @@ public class JSONReconcileServletTest extends AbstractTestClass {
|
|||
jsonResult = reconcile.getMetadata(request, response, defaultNamespace, defaultTypeList, serverName, serverPort);
|
||||
schemaSpaceOutput = jsonResult.getString("schemaSpace");
|
||||
} catch (ServletException e) {
|
||||
System.err.println("JSONReconcileServletTest ServletException: " + e);
|
||||
System.err.println("SolrJsonReconcileServletTest getMetadata ServletException: " + e);
|
||||
} catch (JSONException e) {
|
||||
System.err.println("JSONReconcileServletTest 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 e) {
|
||||
// Syntax error in the regular expression
|
||||
System.err.println("SolrJsonReconcileServletTest testAssertTrue PatternSyntaxException: " + e);
|
||||
}
|
||||
assertNotNull("output should not be null", jsonResult);
|
||||
assertEquals("schemaSpaceOutput", defaultNamespace, schemaSpaceOutput);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue