SDB implementation of RDF API (and merge from trunk)
This commit is contained in:
parent
8aa257d564
commit
cead502f89
194 changed files with 10522 additions and 5324 deletions
|
@ -83,7 +83,7 @@ public class PolicyHelper_ModelsTest extends AbstractTestClass {
|
|||
setLoggerLevel(ServletPolicyList.class, Level.WARN);
|
||||
ServletPolicyList.addPolicy(ctx, new MySimplePolicy());
|
||||
|
||||
setLoggerLevel(PolicyHelper.class, Level.DEBUG);
|
||||
// setLoggerLevel(PolicyHelper.class, Level.DEBUG);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,250 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.json;
|
||||
|
||||
import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
|
||||
import static javax.servlet.http.HttpServletResponse.SC_OK;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.VClassDaoStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryStub;
|
||||
import stubs.javax.servlet.ServletConfigStub;
|
||||
import stubs.javax.servlet.ServletContextStub;
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
import stubs.javax.servlet.http.HttpServletResponseStub;
|
||||
import stubs.javax.servlet.http.HttpSessionStub;
|
||||
import stubs.org.apache.solr.client.solrj.SolrServerStub;
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.solr.SolrSetup;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
public class JsonServletTest extends AbstractTestClass {
|
||||
private static final String GET_SOLR_INDIVIDUALS_BY_VCLASS = "getSolrIndividualsByVClass";
|
||||
|
||||
private static final String GET_VCLASSES_FOR_VCLASS_GROUP = "getVClassesForVClassGroup";
|
||||
|
||||
private static final String VCLASS_ID = "vclassId";
|
||||
|
||||
/**
|
||||
* Test plan
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* GetEntitiesByVClass, GetEntitiesByVClassContinuation
|
||||
* from ents_edit.js
|
||||
* ents_edit_head.jsp
|
||||
* (there is an ents_edit.jsp, invoked from EntityEditController, which does not seem to invoke ents_edit.js)
|
||||
*
|
||||
* GetSolrIndividualsByVClass
|
||||
* Mock out SolrServer (from SolrSetup) and IndividualDao
|
||||
* invoked by BrowseDataGetter.java
|
||||
* home page
|
||||
* invoked by ClassGroupPageData.java
|
||||
* >>>> Bring up "People" tab.
|
||||
* invoked by BrowseWidget.java
|
||||
*
|
||||
* GetSolrIndividualsByVClasses
|
||||
* Mock out SolrServer (from SolrSetup) and IndividualDao
|
||||
* invoked by IndividualsForClassesDataGetter.java
|
||||
* ProcessIndividualsForClasses
|
||||
* extended in vivo by ProcessInternalClasses
|
||||
* SelectDataGetterUtils.java
|
||||
* SelectDataGetterUtils
|
||||
* MenuManagementEdit.java
|
||||
* MenuManagementController.java
|
||||
* extended in vivo by InternalClassesDataGetter, also invoked by SelectDataGetterUtils
|
||||
*
|
||||
* GetDataForPage
|
||||
* Mock out PageDao
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
private JsonServlet servlet;
|
||||
private ServletConfigStub config;
|
||||
private ServletContextStub ctx;
|
||||
private HttpSessionStub session;
|
||||
private HttpServletRequestStub req;
|
||||
private HttpServletResponseStub resp;
|
||||
|
||||
private WebappDaoFactoryStub wadf;
|
||||
private VClassDaoStub vcDao;
|
||||
|
||||
private SolrServerStub solr;
|
||||
|
||||
@Before
|
||||
public void setup() throws ServletException {
|
||||
ctx = new ServletContextStub();
|
||||
|
||||
session = new HttpSessionStub();
|
||||
session.setServletContext(ctx);
|
||||
|
||||
config = new ServletConfigStub();
|
||||
config.setServletContext(ctx);
|
||||
|
||||
servlet = new JsonServlet();
|
||||
servlet.init(config);
|
||||
|
||||
req = new HttpServletRequestStub();
|
||||
req.setMethod("GET");
|
||||
req.setSession(session);
|
||||
|
||||
resp = new HttpServletResponseStub();
|
||||
|
||||
wadf = new WebappDaoFactoryStub();
|
||||
req.setAttribute("webappDaoFactory", wadf);
|
||||
ctx.setAttribute("webappDaoFactory", wadf);
|
||||
|
||||
vcDao = new VClassDaoStub();
|
||||
wadf.setVClassDao(vcDao);
|
||||
|
||||
solr = new SolrServerStub();
|
||||
ctx.setAttribute(SolrSetup.SOLR_SERVER, solr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noRecognizedRequestParameters() throws ServletException,
|
||||
IOException {
|
||||
servlet.service(req, resp);
|
||||
assertEquals("empty response", "", resp.getOutput());
|
||||
assertEquals("status=ok", SC_OK, resp.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vclassesNoClassgroup() throws ServletException, IOException {
|
||||
setLoggerLevel(JsonServlet.class, Level.FATAL);
|
||||
setLoggerLevel(JsonObjectProducer.class, Level.FATAL);
|
||||
req.addParameter(GET_VCLASSES_FOR_VCLASS_GROUP, "true");
|
||||
servlet.service(req, resp);
|
||||
assertFailureWithErrorMessage("java.lang.Exception: no URI passed for classgroupUri");
|
||||
assertEquals("status=failure", SC_INTERNAL_SERVER_ERROR,
|
||||
resp.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Modify VClassGroupCache so it can be stubbed out. JsonServlet asks
|
||||
* VClassGroupCache for the current instance, and VClassGroupCache is a
|
||||
* concrete class instead of an interface, so we can't replace the instance
|
||||
* with one we like better. Furthermore, VClassGroupCache has a private
|
||||
* constructor, so we can't change its behavior at all.
|
||||
*
|
||||
* Also test: success but no VClasses found, success with one VClass,
|
||||
* success with multiple VClasses. In each case, confirm proper status,
|
||||
* character encoding, and content type on the response.
|
||||
*/
|
||||
@Ignore
|
||||
@Test
|
||||
public void vclassesClassgroupNotRecognized() throws ServletException,
|
||||
IOException {
|
||||
req.addParameter(GET_VCLASSES_FOR_VCLASS_GROUP, "true");
|
||||
req.addParameter("classgroupUri", "http://bogusUri");
|
||||
servlet.service(req, resp);
|
||||
assertEquals("empty response", "", resp.getOutput());
|
||||
assertEquals("status=failure", SC_INTERNAL_SERVER_ERROR,
|
||||
resp.getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void individualsByClassNoVClass() throws ServletException,
|
||||
IOException {
|
||||
setLoggerLevel(JsonServlet.class, Level.FATAL);
|
||||
setLoggerLevel(JsonObjectProducer.class, Level.FATAL);
|
||||
req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true");
|
||||
servlet.service(req, resp);
|
||||
assertFailureWithErrorMessage("java.lang.Exception: "
|
||||
+ "parameter vclassId URI parameter expected ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void individualsByClassUnrecognizedVClass() throws ServletException,
|
||||
IOException {
|
||||
setLoggerLevel(JsonServlet.class, Level.FATAL);
|
||||
setLoggerLevel(JsonObjectProducer.class, Level.FATAL);
|
||||
String vclassId = "http://bogusVclass";
|
||||
req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true");
|
||||
req.addParameter(VCLASS_ID, vclassId);
|
||||
|
||||
servlet.service(req, resp);
|
||||
assertFailureWithErrorMessage("java.lang.Exception: " + "Class "
|
||||
+ vclassId + " not found");
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO test successful responses. This will require figuring out how to
|
||||
* stub SolrServer. It's an abstract class, so we just need to figure out
|
||||
* what sort of NamedList is required as a response to a request.
|
||||
*/
|
||||
@Test
|
||||
public void individualsByClassNoIndividuals() throws ServletException,
|
||||
IOException {
|
||||
setLoggerLevel(JsonServlet.class, Level.FATAL);
|
||||
String vclassId = "http://myVclass";
|
||||
vcDao.setVClass(vclassId, new VClass(vclassId));
|
||||
req.addParameter(GET_SOLR_INDIVIDUALS_BY_VCLASS, "true");
|
||||
req.addParameter(VCLASS_ID, vclassId);
|
||||
|
||||
servlet.service(req, resp);
|
||||
assertSuccessWithIndividuals(vclassId, 0);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* The response should be a JSONObject that contained this error-message,
|
||||
* and the status should be set to INTERNAL_SERVER_ERROR.
|
||||
*/
|
||||
private void assertFailureWithErrorMessage(String expected) {
|
||||
try {
|
||||
JSONObject result = new JSONObject(resp.getOutput());
|
||||
assertEquals("errorMessage", expected,
|
||||
getFieldValue(result, "errorMessage"));
|
||||
assertEquals("status", SC_INTERNAL_SERVER_ERROR, resp.getStatus());
|
||||
} catch (JSONException e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void assertSuccessWithIndividuals(String vclassId, int count) {
|
||||
try {
|
||||
JSONObject actual = new JSONObject(resp.getOutput());
|
||||
assertEquals("errorMessage", "",
|
||||
getFieldValue(actual, "errorMessage"));
|
||||
assertEquals("count", count, getFieldValue(actual, "totalCount"));
|
||||
|
||||
JSONObject vclassObj = (JSONObject) getFieldValue(actual, "vclass");
|
||||
assertEquals("vclass name", vclassId.split("://")[1], getFieldValue(vclassObj, "name"));
|
||||
assertEquals("vclass uri", vclassId, getFieldValue(vclassObj, "URI"));
|
||||
|
||||
assertEquals("status", SC_OK, resp.getStatus());
|
||||
} catch (JSONException e) {
|
||||
fail(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFieldValue(JSONObject json, String fieldName) {
|
||||
try {
|
||||
assertEquals("find " + fieldName, true, json.has(fieldName));
|
||||
return json.get(fieldName);
|
||||
} catch (JSONException e) {
|
||||
fail(e.toString());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,423 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;
|
||||
import com.hp.hpl.jena.datatypes.xsd.XSDDateTime;
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditSubmission;
|
||||
|
||||
|
||||
@RunWith(value= Parameterized.class)
|
||||
public class DateTimeWithPrecisionTest {
|
||||
|
||||
TimeZone orginalTimeZone;
|
||||
TimeZone testZone;
|
||||
|
||||
public DateTimeWithPrecisionTest(TimeZone tz){
|
||||
orginalTimeZone = TimeZone.getDefault();
|
||||
testZone = tz;
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> data(){
|
||||
String allZones[] = TimeZone.getAvailableIDs();
|
||||
ArrayList<Object[]> data = new ArrayList<Object[]>( allZones.length );
|
||||
for( String zoneId : allZones ){
|
||||
Object v[] = new Object[1];
|
||||
v[0] = TimeZone.getTimeZone(zoneId);
|
||||
try{
|
||||
DateTimeZone dtz = DateTimeZone.forID(zoneId);
|
||||
if( dtz != null ){
|
||||
data.add(v);
|
||||
}
|
||||
}catch(IllegalArgumentException ex){
|
||||
//cannot convert to joda datetimezone.
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest(){
|
||||
TimeZone.setDefault( testZone );
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
if( orginalTimeZone != null){
|
||||
TimeZone.setDefault(orginalTimeZone);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldNameTemplateVariableTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
EditSubmission editSub = null;
|
||||
EditConfiguration editConfig = new EditConfiguration();
|
||||
editConfig.setUrisInScope(Collections.EMPTY_MAP);
|
||||
editConfig.setLiteralsInScope(Collections.EMPTY_MAP);
|
||||
|
||||
Map templateVars = dtwp.getMapForTemplate(editConfig, editSub);
|
||||
Assert.assertNotNull(templateVars);
|
||||
|
||||
Assert.assertTrue( templateVars.containsKey("fieldName") );
|
||||
Assert.assertEquals(templateVars.get("fieldName"), "testfield");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionSecondsValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"01"});
|
||||
queryParameters.put(FIELDNAME+"-hour", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-minute", new String[]{"00"});
|
||||
queryParameters.put(FIELDNAME+"-second", new String[]{"00"});
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.SECOND.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionMinutesValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"01"});
|
||||
queryParameters.put(FIELDNAME+"-hour", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-minute", new String[]{"00"});
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.MINUTE.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionHoursValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"01"});
|
||||
queryParameters.put(FIELDNAME+"-hour", new String[]{"12"});
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.HOUR.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionDaysValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"01"});
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionMonthsValidationTest()throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.MONTH.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionYearValidationTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
//no months
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.YEAR.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionNoValueTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
//field is not filled out at all
|
||||
//no year
|
||||
//no months
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters );
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(dtwp.BLANK_SENTINEL, precisionURI);
|
||||
|
||||
Literal date = dtwp.getDateTime( queryParameters);
|
||||
Assert.assertNull(date);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDateLiteralTest(){
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
//no months
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
Literal date = dtwp.getDateTime( queryParameters);
|
||||
Assert.assertNotNull(date);
|
||||
Assert.assertEquals( XSDDatatype.XSDdateTime.getURI() ,date.getDatatypeURI() );
|
||||
|
||||
Object obj = date.getValue();
|
||||
Assert.assertNotNull(obj);
|
||||
Assert.assertEquals(XSDDateTime.class, obj.getClass());
|
||||
|
||||
DateTime result = new DateTime( date.getLexicalForm());
|
||||
DateTime expected = new DateTime(1999,1,1,0,0,0,0 );
|
||||
Assert.assertEquals(expected.toInstant() , result.toInstant());
|
||||
|
||||
Assert.assertEquals("1999-01-01T00:00:00" , date.getLexicalForm() );
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void day30Test() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
|
||||
/* Check if it works with day number under 29 */
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"28"});
|
||||
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||
|
||||
/* Check for days greater than 28 */
|
||||
queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"12"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"30"});
|
||||
|
||||
validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||
|
||||
/* Check for leap year */
|
||||
queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"2000" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"2"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"29"});
|
||||
|
||||
validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||
|
||||
/* check for non leap year */
|
||||
queryParameters = new HashMap<String, String[]>();
|
||||
queryParameters.put(FIELDNAME+"-year", new String[]{"1999" });
|
||||
queryParameters.put(FIELDNAME+"-month", new String[]{"2"});
|
||||
queryParameters.put(FIELDNAME+"-day", new String[]{"29"});
|
||||
|
||||
validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() > 0 );
|
||||
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void basicGetMapForTemplateTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
EditConfiguration config = new EditConfiguration();
|
||||
EditSubmission sub = null;
|
||||
|
||||
Map<String,String> urisInScope = new HashMap<String,String>();
|
||||
urisInScope.put(dtwp.getPrecisionVariableName(),
|
||||
VitroVocabulary.Precision.MINUTE.uri());
|
||||
config.setUrisInScope(urisInScope);
|
||||
|
||||
Map<String,Literal> literalsInScope = new HashMap<String,Literal>();
|
||||
literalsInScope.put(dtwp.getValueVariableName(),
|
||||
ResourceFactory.createTypedLiteral("1999-02-15T10:00",XSDDatatype.XSDdateTime) );
|
||||
config.setLiteralsInScope(literalsInScope);
|
||||
|
||||
Map<String,Object> map = dtwp.getMapForTemplate(config,sub);
|
||||
Assert.assertEquals("year wrong", "1999", map.get("year"));
|
||||
Assert.assertEquals("month wrong", "2", map.get("month"));
|
||||
Assert.assertEquals("day wrong", "15", map.get("day"));
|
||||
Assert.assertEquals("hour wrong", "10", map.get("hour"));
|
||||
Assert.assertEquals("minute wrong", "0", map.get("minute"));
|
||||
Assert.assertEquals("second wrong", "", map.get("second"));
|
||||
|
||||
Assert.assertEquals("precision wrong", VitroVocabulary.Precision.MINUTE.uri(), map.get("existingPrecision"));
|
||||
|
||||
Assert.assertEquals("fieldname wrong", FIELDNAME, map.get("fieldName"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,15 +1,17 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.ResourceFactory;
|
||||
|
@ -18,6 +20,7 @@ import com.hp.hpl.jena.vocabulary.RDFS;
|
|||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfigurationConstants;
|
||||
|
||||
public class ProcessRdfFormTest extends AbstractTestClass{
|
||||
|
|
|
@ -10,8 +10,8 @@ import org.junit.Assert;
|
|||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.FieldVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.MultiValueEditSubmission;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||
|
||||
public class AntiXssValidationTest {
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.dataGetter;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
@ -13,6 +11,8 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
@ -20,10 +20,12 @@ import com.hp.hpl.jena.rdf.model.ModelFactory;
|
|||
import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
|
||||
public class DataGetterUtilsTest extends AbstractTestClass{
|
||||
|
||||
OntModel displayModel;
|
||||
VitroRequest vreq;
|
||||
String testDataGetterURI_1 = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#query1data";
|
||||
String pageURI_1 = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#SPARQLPage";
|
||||
String pageX = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#pageX";
|
||||
|
@ -38,6 +40,8 @@ public class DataGetterUtilsTest extends AbstractTestClass{
|
|||
InputStream in = DataGetterUtilsTest.class.getResourceAsStream("resources/dataGetterTest.n3");
|
||||
model.read(in,"","N3");
|
||||
displayModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM,model);
|
||||
|
||||
vreq = new VitroRequest(new HttpServletRequestStub());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -50,14 +54,14 @@ public class DataGetterUtilsTest extends AbstractTestClass{
|
|||
|
||||
@Test
|
||||
public void testDataGetterForURI() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException {
|
||||
DataGetter dg = DataGetterUtils.dataGetterForURI(displayModel, testDataGetterURI_1);
|
||||
DataGetter dg = DataGetterUtils.dataGetterForURI(vreq, displayModel, testDataGetterURI_1);
|
||||
Assert.assertNotNull(dg);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDataGettersForPage() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException {
|
||||
List<DataGetter> dgList =
|
||||
DataGetterUtils.getDataGettersForPage(displayModel, pageURI_1);
|
||||
DataGetterUtils.getDataGettersForPage(vreq, displayModel, pageURI_1);
|
||||
Assert.assertNotNull(dgList);
|
||||
Assert.assertTrue("List of DataGetters was empty, it should not be.", dgList.size() > 0);
|
||||
}
|
||||
|
@ -65,11 +69,11 @@ public class DataGetterUtilsTest extends AbstractTestClass{
|
|||
|
||||
@Test
|
||||
public void testNonPageDataGetter() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException{
|
||||
DataGetter dg = DataGetterUtils.dataGetterForURI(displayModel,dataGetterX);
|
||||
DataGetter dg = DataGetterUtils.dataGetterForURI(vreq, displayModel,dataGetterX);
|
||||
Assert.assertNull(dg);
|
||||
|
||||
List<DataGetter> dgList =
|
||||
DataGetterUtils.getDataGettersForPage(displayModel, pageX);
|
||||
DataGetterUtils.getDataGettersForPage(vreq, displayModel, pageX);
|
||||
Assert.assertNotNull(dgList);
|
||||
Assert.assertTrue("List should be, it was not", dgList.size() == 0);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.javax.servlet.http.HttpServletRequestStub;
|
||||
|
||||
import com.hp.hpl.jena.ontology.OntModel;
|
||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
|
@ -21,6 +23,7 @@ import com.hp.hpl.jena.rdf.model.impl.RDFDefaultErrorHandler;
|
|||
import com.hp.hpl.jena.vocabulary.RDF;
|
||||
|
||||
import edu.cornell.mannlib.vitro.testing.AbstractTestClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||
|
@ -30,6 +33,7 @@ public class SparqlQueryDataGetterTest extends AbstractTestClass{
|
|||
OntModel displayModel;
|
||||
String testDataGetterURI_1 = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#query1data";
|
||||
WebappDaoFactory wdf;
|
||||
VitroRequest vreq;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
@ -43,12 +47,14 @@ public class SparqlQueryDataGetterTest extends AbstractTestClass{
|
|||
|
||||
SimpleOntModelSelector sos = new SimpleOntModelSelector( ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM));
|
||||
sos.setDisplayModel(displayModel);
|
||||
wdf = new WebappDaoFactoryJena(sos);
|
||||
wdf = new WebappDaoFactoryJena(sos);
|
||||
|
||||
vreq = new VitroRequest(new HttpServletRequestStub());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicGetData() throws IllegalArgumentException, SecurityException, InstantiationException, IllegalAccessException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException {
|
||||
DataGetter dg = DataGetterUtils.dataGetterForURI(displayModel, testDataGetterURI_1);
|
||||
DataGetter dg = DataGetterUtils.dataGetterForURI(vreq, displayModel, testDataGetterURI_1);
|
||||
Assert.assertNotNull(dg);
|
||||
Assert.assertTrue(
|
||||
"DataGetter should be of type " + SparqlQueryDataGetter.class.getName(),
|
||||
|
|
|
@ -37,10 +37,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.BaseTemplateModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.InvalidConfigurationException;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.templatemodels.customlistview.PropertyListConfig;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.cache.TemplateLoader;
|
||||
|
||||
public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
||||
AbstractTestClass {
|
||||
|
@ -83,22 +82,15 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
createConfigFile("constructQueryMissing");
|
||||
createConfigFile("constructQueryMultiple");
|
||||
createConfigFile("default");
|
||||
createConfigFile("notValidXml");
|
||||
createConfigFile("postProcessorClassNotFound");
|
||||
createConfigFile("postProcessorClassNotSuitable");
|
||||
createConfigFile("postProcessorConstructorThrowsException");
|
||||
createConfigFile("postProcessorNameEmpty");
|
||||
createConfigFile("postProcessorOK");
|
||||
createConfigFile("postProcessorWrongConstructor");
|
||||
createConfigFile("selectQueryNodeBlank");
|
||||
createConfigFile("selectQueryNodeNotFound");
|
||||
createConfigFile("selectQuerySubNodes");
|
||||
createConfigFile("selectQueryNoSubNodes");
|
||||
createConfigFile("selectQueryCollatedValid");
|
||||
createConfigFile("selectQueryCollatedNoSelect");
|
||||
createConfigFile("selectQueryCollatedNoOrder");
|
||||
createConfigFile("templateNodeIsEmpty");
|
||||
createConfigFile("templateNodeNotFound");
|
||||
createConfigFile("templateDoesNotExist");
|
||||
}
|
||||
|
||||
|
@ -135,11 +127,11 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
|
||||
subject = new IndividualImpl();
|
||||
|
||||
Configuration fmConfig = new Configuration();
|
||||
vreq.setAttribute("freemarkerConfig", fmConfig);
|
||||
// We need a stub TemplateLoader because PropertyListConfig will check
|
||||
// to see whether the template name is recognized. How can we get around
|
||||
// that? This will do for now.
|
||||
tl = new TemplateLoaderStub();
|
||||
tl.createTemplate("propStatement-default.ftl", "");
|
||||
fmConfig.setTemplateLoader(tl);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
|
@ -153,12 +145,13 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
// TODO - baseTemplateModel shouldn't require the servlet context to be set
|
||||
// statically!!! ServletContext shouldn't be a static field.
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// The tests
|
||||
//
|
||||
// TODO - remove any tests that are covered by the newer
|
||||
// CustomListViewConfigFileTest.
|
||||
// ----------------------------------------------------------------------
|
||||
/*
|
||||
* These tests were removed because the newer CustomListViewConfigTest
|
||||
* covered them: configFileNotValidXml(), selectQueryNodeIsNotFound(),
|
||||
* selectQueryNodeIsBlank(), selectSubNodesCollatedCritical(),
|
||||
* selectSubNodesCollatedUncritical(), selectSubNodesUncollatedCritical(),
|
||||
* selectSubNodesUncollatedUncritical(), selectNoSubNodesCollatedCritical()
|
||||
*/
|
||||
|
||||
//
|
||||
// Null arguments
|
||||
|
@ -228,68 +221,9 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
assertLogMessagesContains("file not found", "Can't find config file");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configFileNotValidXml() throws InvalidConfigurationException {
|
||||
suppressSyserr();
|
||||
captureLogsFromPropertyListConfig();
|
||||
|
||||
op = buildOperation("notValidXml");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, false);
|
||||
|
||||
assertLogMessagesContains("not valid XML", "SAXParseException");
|
||||
}
|
||||
|
||||
//
|
||||
// Problems with the <query-select> node
|
||||
//
|
||||
|
||||
@Test
|
||||
public void selectQueryNodeIsNotFound()
|
||||
throws InvalidConfigurationException {
|
||||
captureLogsFromPropertyListConfig();
|
||||
|
||||
op = buildOperation("selectQueryNodeNotFound");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, false);
|
||||
|
||||
assertLogMessagesContains("no select query",
|
||||
"Missing select query specification");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectQueryNodeIsBlank() throws InvalidConfigurationException {
|
||||
captureLogsFromPropertyListConfig();
|
||||
|
||||
op = buildOperation("selectQueryNodeBlank");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, false);
|
||||
|
||||
assertLogMessagesContains("blank select query",
|
||||
"Missing select query specification");
|
||||
}
|
||||
|
||||
//
|
||||
// Problems with the <template> node
|
||||
//
|
||||
@Test
|
||||
public void templateNodeNotFound() throws InvalidConfigurationException {
|
||||
captureLogsFromPropertyListConfig();
|
||||
|
||||
op = buildOperation("templateNodeNotFound");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, false);
|
||||
|
||||
assertLogMessagesContains("no template node",
|
||||
"Config file must contain a template element");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void templateNodeIsEmpty() throws InvalidConfigurationException {
|
||||
captureLogsFromPropertyListConfig();
|
||||
|
||||
op = buildOperation("templateNodeIsEmpty");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, false);
|
||||
|
||||
assertLogMessagesContains("empty template node",
|
||||
"In a config file, the <template> element must not be empty.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void templateDoesNotExist() throws InvalidConfigurationException {
|
||||
|
@ -303,52 +237,9 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
}
|
||||
|
||||
//
|
||||
// Optional tags in the select query.
|
||||
// Check for valid query.
|
||||
//
|
||||
|
||||
@Test
|
||||
public void selectSubNodesCollatedCritical()
|
||||
throws InvalidConfigurationException {
|
||||
op = buildOperation("selectQuerySubNodes");
|
||||
optm = new SimpleCollatingOPTM(op, subject, vreq, false);
|
||||
assertSelectQuery("collated, critical",
|
||||
"Plain collated plain critical plain collated plain.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectSubNodesCollatedUncritical()
|
||||
throws InvalidConfigurationException {
|
||||
op = buildOperation("selectQuerySubNodes");
|
||||
optm = new SimpleCollatingOPTM(op, subject, vreq, true);
|
||||
assertSelectQuery("collated, UNcritical",
|
||||
"Plain collated plain plain collated plain.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectSubNodesUncollatedCritical()
|
||||
throws InvalidConfigurationException {
|
||||
op = buildOperation("selectQuerySubNodes");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, false);
|
||||
assertSelectQuery("UNcollated, critical",
|
||||
"Plain plain critical plain plain.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectSubNodesUncollatedUncritical()
|
||||
throws InvalidConfigurationException {
|
||||
op = buildOperation("selectQuerySubNodes");
|
||||
optm = new NonCollatingOPTM(op, subject, vreq, true);
|
||||
assertSelectQuery("UNcollated, UNcritical", "Plain plain plain plain.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectNoSubNodesCollatedCritical()
|
||||
throws InvalidConfigurationException {
|
||||
op = buildOperation("selectQueryNoSubNodes");
|
||||
optm = new SimpleCollatingOPTM(op, subject, vreq, false);
|
||||
assertSelectQuery("simple collated, critical", "Plain.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collatedNoSubclassSelector()
|
||||
throws InvalidConfigurationException {
|
||||
|
@ -510,20 +401,6 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
+ expected);
|
||||
}
|
||||
|
||||
private void assertSelectQuery(String message, String expected) {
|
||||
String actual = "BOGUS";
|
||||
try {
|
||||
Method m = ObjectPropertyTemplateModel.class.getDeclaredMethod(
|
||||
"getSelectQuery", new Class<?>[0]);
|
||||
m.setAccessible(true);
|
||||
actual = (String) m.invoke(optm, new Object[0]);
|
||||
} catch (Exception e) {
|
||||
fail(message + " - " + e);
|
||||
}
|
||||
|
||||
assertEquals(message, expected, actual);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void assertConstructQueries(String message, String... expectedArray) {
|
||||
Set<String> expected = new HashSet<String>(Arrays.asList(expectedArray));
|
||||
|
@ -564,7 +441,7 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
// Supporting classes
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private static class NonCollatingOPTM extends ObjectPropertyTemplateModel {
|
||||
private class NonCollatingOPTM extends ObjectPropertyTemplateModel {
|
||||
NonCollatingOPTM(ObjectProperty op, Individual subject,
|
||||
VitroRequest vreq, boolean editing)
|
||||
throws InvalidConfigurationException {
|
||||
|
@ -581,15 +458,17 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TemplateLoader getFreemarkerTemplateLoader() {
|
||||
return ObjectPropertyTemplateModel_PropertyListConfigTest.this.tl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* No populated properties and we don't do syntax checking on the select
|
||||
* query.
|
||||
*/
|
||||
private static class SimpleCollatingOPTM extends
|
||||
/** No populated properties but we do check the syntax of the select query. */
|
||||
private class CheckingCollatingOPTM extends
|
||||
CollatedObjectPropertyTemplateModel {
|
||||
SimpleCollatingOPTM(ObjectProperty op, Individual subject,
|
||||
CheckingCollatingOPTM(ObjectProperty op, Individual subject,
|
||||
VitroRequest vreq, boolean editing)
|
||||
throws InvalidConfigurationException {
|
||||
super(op, subject, vreq, editing, Collections
|
||||
|
@ -597,20 +476,8 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
}
|
||||
|
||||
@Override
|
||||
public ConfigError checkQuery(String queryString) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** No populated properties but we do check the syntax of the select query. */
|
||||
private static class CheckingCollatingOPTM extends
|
||||
CollatedObjectPropertyTemplateModel {
|
||||
CheckingCollatingOPTM(ObjectProperty op, Individual subject,
|
||||
VitroRequest vreq, boolean editing)
|
||||
throws InvalidConfigurationException {
|
||||
super(op, subject, vreq, editing, Collections
|
||||
.<ObjectProperty> emptyList());
|
||||
protected TemplateLoader getFreemarkerTemplateLoader() {
|
||||
return ObjectPropertyTemplateModel_PropertyListConfigTest.this.tl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
This would be valid except for the XML error.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-select>
|
||||
SELECT <collated> ?subclass </collated>
|
||||
?object
|
||||
WHERE {
|
||||
?subject ?property ?object
|
||||
<collated>
|
||||
?object a ?subclass.
|
||||
</collated>
|
||||
}
|
||||
</query-select>
|
||||
|
||||
<query-construct/>
|
||||
CONSTRUCT {
|
||||
?subject ?property ?object .
|
||||
} WHERE {
|
||||
?subject ?property ?object
|
||||
}
|
||||
</query-construct>
|
||||
|
||||
<template>propStatement-default.ftl</template>
|
||||
</list-view-config>
|
|
@ -1,13 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
Test this with collated and uncollated, critical and uncritical, to insure that we don't need the nested tags.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-select>Plain.</query-select>
|
||||
<query-construct> Construct </query-construct>
|
||||
<template>propStatement-default.ftl</template>
|
||||
</list-view-config>
|
|
@ -1,22 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
Invalid - <query-select> is blank.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-select>
|
||||
</query-select>
|
||||
|
||||
<query-construct>
|
||||
CONSTRUCT {
|
||||
?subject ?property ?object .
|
||||
} WHERE {
|
||||
?subject ?property ?object
|
||||
}
|
||||
</query-construct>
|
||||
|
||||
<template>propStatement-default.ftl</template>
|
||||
</list-view-config>
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
Invalid - no <query-select> node.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-construct>
|
||||
CONSTRUCT {
|
||||
?subject ?property ?object .
|
||||
} WHERE {
|
||||
?subject ?property ?object
|
||||
}
|
||||
</query-construct>
|
||||
|
||||
<template>propStatement-default.ftl</template>
|
||||
</list-view-config>
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
Test this with collated and uncollated, critical and non-critical,
|
||||
to be sure that we include or omit the appropriate text.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-select>Plain <collated>collated </collated>plain <critical-data-required>critical </critical-data-required>plain <collated>collated </collated>plain.</query-select>
|
||||
<query-construct> Construct </query-construct>
|
||||
<template>propStatement-default.ftl</template>
|
||||
</list-view-config>
|
|
@ -1,30 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
Template node is empty - should throw an exception.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-select>
|
||||
SELECT <collated> ?subclass </collated>
|
||||
?object
|
||||
WHERE {
|
||||
?subject ?property ?object
|
||||
<collated>
|
||||
?object a ?subclass.
|
||||
</collated>
|
||||
}
|
||||
</query-select>
|
||||
|
||||
<query-construct>
|
||||
CONSTRUCT {
|
||||
?subject ?property ?object .
|
||||
} WHERE {
|
||||
?subject ?property ?object
|
||||
}
|
||||
</query-construct>
|
||||
|
||||
<template/>
|
||||
</list-view-config>
|
|
@ -1,29 +0,0 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
|
||||
<!-- $This file is distributed under the terms of the license in /doc/license.txt$ -->
|
||||
|
||||
<!--
|
||||
No template node. Should throw an exception.
|
||||
-->
|
||||
|
||||
<list-view-config>
|
||||
<query-select>
|
||||
SELECT <collated> ?subclass </collated>
|
||||
?object
|
||||
WHERE {
|
||||
?subject ?property ?object
|
||||
<collated>
|
||||
?object a ?subclass.
|
||||
</collated>
|
||||
}
|
||||
</query-select>
|
||||
|
||||
<query-construct>
|
||||
CONSTRUCT {
|
||||
?subject ?property ?object .
|
||||
} WHERE {
|
||||
?subject ?property ?object
|
||||
}
|
||||
</query-construct>
|
||||
|
||||
</list-view-config>
|
|
@ -21,7 +21,6 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
|
||||
|
||||
/**
|
||||
* Mock the basic functions of Individual for unit tests.
|
||||
|
@ -380,12 +379,6 @@ public class IndividualStub implements Individual {
|
|||
throw new RuntimeException("Individual.setVClasses() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMemberOfClassProhibitedFromSearch(ProhibitedFromSearch pfs) {
|
||||
throw new RuntimeException(
|
||||
"Individual.isMemberOfClassProhibitedFromSearch() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setObjectPropertyStatements(List<ObjectPropertyStatement> list) {
|
||||
throw new RuntimeException(
|
||||
|
|
|
@ -0,0 +1,264 @@
|
|||
package stubs.edu.cornell.mannlib.vitro.webapp.dao;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClass;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.InsertException;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
|
||||
|
||||
public class VClassDaoStub implements VClassDao {
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private final Map<String, VClass> vclassesByUri = new HashMap<String, VClass>();
|
||||
|
||||
public void setVClass(String uri, VClass vclass) {
|
||||
vclassesByUri.put(uri, vclass);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
public VClass getVClassByURI(String URI) {
|
||||
return vclassesByUri.get(URI);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
|
||||
@Override
|
||||
public List<VClass> getRootClasses() {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getRootClasses() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VClass> getOntologyRootClasses(String ontologyURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getOntologyRootClasses() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VClass> getAllVclasses() {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getAllVclasses() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDisjointWithClassURIs(String vclassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getDisjointWithClassURIs() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSuperclass(VClass subclass, VClass superclass) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addSuperclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSuperclass(String classURI, String superclassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addSuperclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSuperclass(VClass vclass, VClass superclass) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.removeSuperclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSuperclass(String classURI, String superclassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.removeSuperclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubclass(VClass vclass, VClass subclass) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addSubclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSubclass(String classURI, String subclassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addSubclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSubclass(VClass vclass, VClass subclass) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.removeSubclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSubclass(String classURI, String subclassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.removeSubclass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDisjointWithClass(String classURI, String disjointCLassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addDisjointWithClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeDisjointWithClass(String classURI, String disjointClassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.removeDisjointWithClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getEquivalentClassURIs(String classURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getEquivalentClassURIs() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEquivalentClass(String classURI, String equivalentClassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addEquivalentClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEquivalentClass(String classURI, String equivalentClassURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.removeEquivalentClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSubClassURIs(String classURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getSubClassURIs() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllSubClassURIs(String classURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getAllSubClassURIs() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuperClassURIs(String classURI, boolean direct) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getSuperClassURIs() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAllSuperClassURIs(String classURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getAllSuperClassURIs() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertNewVClass(VClass cls) throws InsertException {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.insertNewVClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateVClass(VClass cls) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.updateVClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVClass(String URI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.deleteVClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteVClass(VClass cls) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.deleteVClass() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VClass> getVClassesForProperty(String propertyURI,
|
||||
boolean domainSide) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getVClassesForProperty() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VClass> getVClassesForProperty(String vclassURI,
|
||||
String propertyURI) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getVClassesForProperty() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVClassesToGroup(VClassGroup group) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addVClassesToGroup() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertNewClasses2Classes(Classes2Classes c2c) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.insertNewClasses2Classes() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteClasses2Classes(Classes2Classes c2c) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.deleteClasses2Classes() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVClassesToGroup(VClassGroup group,
|
||||
boolean includeUninstantiatedClasses) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addVClassesToGroup() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVClassesToGroup(VClassGroup group,
|
||||
boolean includeUninstantiatedClasses, boolean getIndividualCount) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addVClassesToGroup() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addVClassesToGroups(List<VClassGroup> groups) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.addVClassesToGroups() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubClassOf(VClass vc1, VClass vc2) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.isSubClassOf() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSubClassOf(String vclassURI1, String vclassURI2) {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.isSubClassOf() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public VClass getTopConcept() {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getTopConcept() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public VClass getBottomConcept() {
|
||||
throw new RuntimeException(
|
||||
"VClassDaoStub.getBottomConcept() not implemented.");
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,8 @@ import java.io.StringWriter;
|
|||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.Cookie;
|
||||
|
@ -29,6 +31,7 @@ public class HttpServletResponseStub implements HttpServletResponse {
|
|||
private String errorMessage;
|
||||
private Map<String, String> headers = new HashMap<String, String>();
|
||||
private String contentType;
|
||||
private String charset = "";
|
||||
|
||||
private ByteArrayOutputStream outputStream;
|
||||
private StringWriter outputWriter;
|
||||
|
@ -129,9 +132,19 @@ public class HttpServletResponseStub implements HttpServletResponse {
|
|||
return headers.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calling setContentType("this/type;charset=UTF-8") is the same as calling
|
||||
* setContentType("this/type;charset=UTF-8"); setCharacterEncoding("UTF-8")
|
||||
*/
|
||||
@Override
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
|
||||
Pattern p = Pattern.compile(";\\scharset=([^;]+)");
|
||||
Matcher m = p.matcher(contentType);
|
||||
if (m.find()) {
|
||||
this.charset = m.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,6 +152,16 @@ public class HttpServletResponseStub implements HttpServletResponse {
|
|||
return contentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterEncoding(String charset) {
|
||||
this.charset = charset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCharacterEncoding() {
|
||||
return charset;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
@ -155,12 +178,6 @@ public class HttpServletResponseStub implements HttpServletResponse {
|
|||
"HttpServletResponseStub.getBufferSize() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCharacterEncoding() {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.getCharacterEncoding() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Locale getLocale() {
|
||||
throw new RuntimeException(
|
||||
|
@ -191,12 +208,6 @@ public class HttpServletResponseStub implements HttpServletResponse {
|
|||
"HttpServletResponseStub.setBufferSize() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCharacterEncoding(String arg0) {
|
||||
throw new RuntimeException(
|
||||
"HttpServletResponseStub.setCharacterEncoding() not implemented.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentLength(int arg0) {
|
||||
throw new RuntimeException(
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package stubs.org.apache.solr.client.solrj;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.solr.client.solrj.SolrRequest;
|
||||
import org.apache.solr.client.solrj.SolrServer;
|
||||
import org.apache.solr.client.solrj.SolrServerException;
|
||||
import org.apache.solr.common.util.NamedList;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
public class SolrServerStub extends SolrServer {
|
||||
private static final Log log = LogFactory.getLog(SolrServerStub.class);
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub infrastructure
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Stub methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.apache.solr.client.solrj.SolrServer#request(org.apache.solr.client
|
||||
* .solrj.SolrRequest)
|
||||
*/
|
||||
@Override
|
||||
public NamedList<Object> request(SolrRequest request)
|
||||
throws SolrServerException, IOException {
|
||||
// TODO not really an implementation.
|
||||
return new NamedList<Object>();
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Un-implemented methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue