@Test public void testErrorSearchRdfWithoutSearchTerm() throws Exception { // prepare: final InferredOWLOntologyID testArtifact = this.loadTestArtifact( TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE); final ClientResource searchClientResource = new ClientResource(this.getUrl(PoddWebConstants.PATH_SEARCH)); // there is no need to authenticate or have a test artifact as the // search term is checked // for first try { // no search term! searchClientResource.addQueryParameter( PoddWebConstants.KEY_ARTIFACT_IDENTIFIER, testArtifact.getOntologyIRI().toString()); searchClientResource.addQueryParameter( PoddWebConstants.KEY_SEARCH_TYPES, "http://purl.org/podd/ns/poddScience#Platform"); searchClientResource.get(MediaType.APPLICATION_RDF_XML); Assert.fail("Should have thrown a ResourceException"); } catch (final ResourceException e) { Assert.assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, e.getStatus()); } finally { this.releaseClient(searchClientResource); } }
@Test public void testErrorSearchRdfWithoutAuthentication() throws Exception { // prepare: final InferredOWLOntologyID testArtifact = this.loadTestArtifact( TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE); final ClientResource searchClientResource = new ClientResource(this.getUrl(PoddWebConstants.PATH_SEARCH)); // request without authentication try { searchClientResource.addQueryParameter(PoddWebConstants.KEY_SEARCHTERM, "Scan"); searchClientResource.addQueryParameter( PoddWebConstants.KEY_ARTIFACT_IDENTIFIER, testArtifact.getOntologyIRI().toString()); searchClientResource.addQueryParameter( PoddWebConstants.KEY_SEARCH_TYPES, "http://purl.org/podd/ns/poddScience#Platform"); searchClientResource.get(MediaType.APPLICATION_RDF_XML); Assert.fail("Should have thrown a ResourceException"); } catch (final ResourceException e) { Assert.assertEquals(Status.CLIENT_ERROR_UNAUTHORIZED, e.getStatus()); } finally { this.releaseClient(searchClientResource); } }
/** Test successful search for a custom Platform in RDF/XML */ @Test public void testSearchRdfForCustomPlatforms() throws Exception { // prepare: final InferredOWLOntologyID testArtifact = this.loadTestArtifact( TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE); final String[] searchTypes = {"http://purl.org/podd/ns/poddScience#Platform"}; final MediaType requestMediaType = MediaType.APPLICATION_RDF_XML; final Model resultModel = this.internalTestSearchRdf( "lat", searchTypes, requestMediaType, testArtifact.getOntologyIRI().toString()); // verify: Assert.assertEquals("Not the expected number of results", 1, resultModel.size()); Assert.assertEquals( "Expected Platform 1 not found", 1, resultModel.filter(null, null, PODD.VF.createLiteral("Platform 1")).size()); }
/** Test successful search for a PODD Project in RDF/XML */ @Test public void testSearchRdfForProjects() throws Exception { // prepare: final InferredOWLOntologyID testArtifact = this.loadTestArtifact( TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE); final String[] searchTypes = {"http://purl.org/podd/ns/poddScience#Project"}; final MediaType requestMediaType = MediaType.APPLICATION_RDF_XML; final Model resultModel = this.internalTestSearchRdf( "Cot", searchTypes, requestMediaType, testArtifact.getOntologyIRI().toString()); // verify: Assert.assertEquals("Not the expected number of results", 1, resultModel.size()); Assert.assertTrue( "Expected Project not found", resultModel .filter(null, RDFS.LABEL, null) .objectString() .contains("Cotton Leaf Morphology")); }
/** Test successful search for PoddScience:Sex values in RDF/XML */ @Test public void testSearchRdfForSex() throws Exception { // prepare: add an artifact final InferredOWLOntologyID testArtifact = this.loadTestArtifact( TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE); final String[] searchTypes = {"http://purl.org/podd/ns/poddScience#Sex"}; final MediaType requestMediaType = MediaType.APPLICATION_RDF_XML; final Model resultModel = this.internalTestSearchRdf( "", searchTypes, requestMediaType, testArtifact.getOntologyIRI().toString()); Assert.assertEquals("Not the expected number of results", 5, resultModel.size()); Assert.assertEquals( "Value Hermaphrodite not found", 1, resultModel.filter(null, null, PODD.VF.createLiteral("Hermaphrodite")).size()); Assert.assertEquals( "Value Male not found", 1, resultModel.filter(null, null, PODD.VF.createLiteral("Male")).size()); }
@Test public void testPostRdfBasic() throws Exception { // prepare: add an artifact final InferredOWLOntologyID testArtifact = this.loadTestArtifact( TestConstants.TEST_ARTIFACT_20130206, MediaType.APPLICATION_RDF_TURTLE); final ClientResource searchClientResource = new ClientResource(this.getUrl(PoddWebConstants.PATH_SEARCH)); try { searchClientResource.addQueryParameter( PoddWebConstants.KEY_ARTIFACT_IDENTIFIER, testArtifact.getOntologyIRI().toString()); // prepare: the test input final String[] objectUris = { "http://purl.org/podd/basic-1-20130206/object:2966", "http://purl.org/podd/basic-2-20130206/artifact:1#Demo-Genotype", "http://purl.org/podd/basic-2-20130206/artifact:1#SqueekeeMaterial", "http://purl.org/podd/ns/poddScience#WildType_NotApplicable", "http://purl.org/podd/ns/poddPlant#DeltaTporometer-63", "http://purl.org/podd/ns/poddBase#DisplayType_LongText" }; final String[] expectedLabels = { "Project#2012-0006_ Cotton Leaf Morphology", "Demo genotype", "Squeekee material", "Not Applicable", "Delta-T porometer", null }; final Model testModel = new LinkedHashModel(); for (final String s : objectUris) { testModel.add(PODD.VF.createURI(s), RDFS.LABEL, PODD.VF.createLiteral("?blank")); } final RDFFormat inputFormat = RDFFormat.RDFXML; final MediaType inputMediaType = MediaType.valueOf(inputFormat.getDefaultMIMEType()); // build input representation final ByteArrayOutputStream output = new ByteArrayOutputStream(8096); Rio.write(testModel, output, inputFormat); final Representation input = new StringRepresentation(output.toString(), inputMediaType); // invoke service final Representation results = this.doTestAuthenticatedRequest( searchClientResource, Method.POST, input, inputMediaType, Status.SUCCESS_OK, AbstractResourceImplTest.WITH_ADMIN); // verify: response final Model resultModel = this.assertRdf(results, RDFFormat.RDFXML, 5); // verify: each URI has the expected label for (int i = 0; i < objectUris.length; i++) { final String objectString = resultModel.filter(PODD.VF.createURI(objectUris[i]), RDFS.LABEL, null).objectString(); Assert.assertEquals("Not the expected label", expectedLabels[i], objectString); } } finally { this.releaseClient(searchClientResource); } }