NIHVIVO-3746 Permit DataGetter classes to have 4 different types of constructor - make reflection logic more rigorous to avoid NoSuchMethodException.

This commit is contained in:
j2blake 2012-05-02 17:04:24 +00:00
parent 18e171e1b9
commit a26f0c2809
6 changed files with 55 additions and 30 deletions

View file

@ -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);
}

View file

@ -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(),