VIVO-870 Move the DocumentModifiers into the configuration.
This commit is contained in:
parent
4fac4b7576
commit
8c3e06fc78
7 changed files with 100 additions and 268 deletions
|
@ -1,109 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.searchindex.documentBuilding;
|
||||
|
||||
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
|
||||
import static edu.cornell.mannlib.vitro.webapp.search.VitroSearchTermNames.NAME_RAW;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.beans.IndividualStub;
|
||||
import stubs.edu.cornell.mannlib.vitro.webapp.modelaccess.ContextModelAccessStub;
|
||||
|
||||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.Statement;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.modules.searchEngine.SearchInputDocument;
|
||||
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
|
||||
import edu.cornell.mannlib.vitro.webapp.searchengine.base.BaseSearchInputDocument;
|
||||
|
||||
/**
|
||||
* TODO NameFields should add the values as separate objects.
|
||||
*/
|
||||
public class NameFieldsTest {
|
||||
private static final String INDIVIDUAL_URI = "http://mydomain.edu/individual/n3012";
|
||||
private static final String LABEL_PROPERTY_URI = "http://www.w3.org/2000/01/rdf-schema#label";
|
||||
private Model baseModel;
|
||||
private NameFields nameFields;
|
||||
private BaseSearchInputDocument doc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
baseModel = ModelFactory.createDefaultModel();
|
||||
|
||||
doc = new BaseSearchInputDocument();
|
||||
|
||||
RDFServiceModel rdfService = new RDFServiceModel(baseModel);
|
||||
ContextModelAccessStub models = new ContextModelAccessStub();
|
||||
models.setRDFService(CONTENT, rdfService);
|
||||
|
||||
nameFields = new NameFields();
|
||||
nameFields.setContextModels(models);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullIndividual() {
|
||||
SearchInputDocument expected = new BaseSearchInputDocument(doc);
|
||||
|
||||
assertResultingSearchDocument(null, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullUri() {
|
||||
SearchInputDocument expected = new BaseSearchInputDocument(doc);
|
||||
|
||||
assertResultingSearchDocument(new IndividualStub(null), expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void foundNoLabels() {
|
||||
SearchInputDocument expected = new BaseSearchInputDocument(doc);
|
||||
expected.addField(NAME_RAW, "");
|
||||
|
||||
assertResultingSearchDocument(new IndividualStub(INDIVIDUAL_URI),
|
||||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void foundOneLabel() {
|
||||
baseModel.add(stmt(INDIVIDUAL_URI, LABEL_PROPERTY_URI, "label1"));
|
||||
|
||||
SearchInputDocument expected = new BaseSearchInputDocument(doc);
|
||||
expected.addField(NAME_RAW, "label1 ");
|
||||
|
||||
assertResultingSearchDocument(new IndividualStub(INDIVIDUAL_URI),
|
||||
expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void foundTwoLabels() {
|
||||
baseModel.add(stmt(INDIVIDUAL_URI, LABEL_PROPERTY_URI, "label1"));
|
||||
baseModel.add(stmt(INDIVIDUAL_URI, LABEL_PROPERTY_URI, "label2"));
|
||||
|
||||
SearchInputDocument expected = new BaseSearchInputDocument(doc);
|
||||
expected.addField(NAME_RAW, "label2 label1 ");
|
||||
|
||||
assertResultingSearchDocument(new IndividualStub(INDIVIDUAL_URI),
|
||||
expected);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
private Statement stmt(String subjectUri, String propertyUri, String literal) {
|
||||
return baseModel.createStatement(baseModel.createResource(subjectUri),
|
||||
baseModel.createProperty(propertyUri),
|
||||
baseModel.createLiteral(literal));
|
||||
}
|
||||
|
||||
private void assertResultingSearchDocument(Individual ind,
|
||||
SearchInputDocument expected) {
|
||||
nameFields.modifyDocument(ind, doc);
|
||||
assertEquals(expected, doc);
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ package edu.cornell.mannlib.vitro.webapp.searchindex.exclusions;
|
|||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
@ -22,8 +23,9 @@ public class ExcludeBasedOnTypeTest {
|
|||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/n2343");
|
||||
|
||||
VClass personClass = new VClass("http://xmlns.com/foaf/0.1/Person");
|
||||
ind.setVClass(personClass);
|
||||
ind.setVClasses(Collections.singletonList(personClass), false);
|
||||
|
||||
String excludeResult = ebot.checkForExclusion(ind);
|
||||
assertNotNull( excludeResult );
|
||||
|
@ -37,10 +39,9 @@ public class ExcludeBasedOnTypeTest {
|
|||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/n2343");
|
||||
VClass personClass = new VClass("http://xmlns.com/foaf/0.1/Agent");
|
||||
ind.setVClass(personClass);
|
||||
|
||||
List<VClass> vClassList = new ArrayList<VClass>();
|
||||
vClassList.add( new VClass("http://xmlns.com/foaf/0.1/Agent"));
|
||||
vClassList.add( new VClass("http://example.com/Robot"));
|
||||
vClassList.add( new VClass("http://example.com/KillerRobot"));
|
||||
vClassList.add( new VClass("http://example.com/Droid"));
|
||||
|
@ -52,14 +53,13 @@ public class ExcludeBasedOnTypeTest {
|
|||
|
||||
@Test
|
||||
public void testCheckForNonExclusion() {
|
||||
|
||||
ExcludeBasedOnType ebot = new ExcludeBasedOnType();
|
||||
ebot.addTypeToExclude("http://xmlns.com/foaf/0.1/Person");
|
||||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/n2343");
|
||||
VClass personClass = new VClass("http://xmlns.com/foaf/0.1/Robot");
|
||||
ind.setVClass(personClass);
|
||||
ind.setVClasses(Collections.singletonList(personClass), false);
|
||||
|
||||
String excludeResult = ebot.checkForExclusion(ind);
|
||||
assertNull( excludeResult );
|
||||
|
@ -72,10 +72,9 @@ public class ExcludeBasedOnTypeTest {
|
|||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
ind.setURI("http://example.com/n2343");
|
||||
VClass personClass = new VClass("http://xmlns.com/foaf/0.1/Agent");
|
||||
ind.setVClass(personClass);
|
||||
|
||||
List<VClass> vClassList = new ArrayList<VClass>();
|
||||
vClassList.add( new VClass("http://xmlns.com/foaf/0.1/Agent"));
|
||||
vClassList.add( new VClass("http://example.com/Robot"));
|
||||
vClassList.add( new VClass("http://example.com/KillerRobot"));
|
||||
vClassList.add( new VClass("http://example.com/Droid"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue