/** * {@inheritDoc} */ @Override public Resource getResource(String uri) { return super.object.getResource(uri); }
/** * {@inheritDoc} */ @Override public Resource getResource(String uri, ResourceF f) { return super.object.getResource(uri, f); }
/** * <p> * Answer true if this resource is a member of the class denoted by the * given URI.</p> * * @param uri Denotes the URI of a class to which this value may belong * @return True if this resource has the given class as one of its <code>rdf:type</code>'s. */ @Override public boolean hasRDFType( String uri ) { return hasRDFType( getModel().getResource( uri ) ); }
protected void modifyProperty(Model m, String resourceUri, String property) { Resource r = m.getResource(resourceUri); Property p = m.createProperty(property); r.removeAll(p); // Don't sweat the value or datatype since we expect the PUT to fail anyway. r.addProperty(p, "modified"); }
@Test public void testExtractsEnableForwardHeaders() { Model spec = ModelIOUtils.modelFromTurtle(new StringBuffer() .append(":s a api:API") .append("; api:sparqlEndpoint <http://example.com/none>") .append("; elda:enableForwardHeaders false") .append(".") .toString() ); Resource s = spec.getResource( spec.expandPrefix( ":s" ) ); APISpec a = SpecUtil.specFrom( s ); assertEquals( false, a.getEnableForwardHeaders() ); }
@Test public void testExtractsBase() { Model spec = ModelIOUtils.modelFromTurtle(new StringBuffer() .append(":s a api:API") .append("; api:sparqlEndpoint <http://example.com/none>") .append("; api:base 'to/be/expunged'") .append(".") .toString() ); Resource s = spec.getResource( spec.expandPrefix( ":s" ) ); APISpec a = SpecUtil.specFrom( s ); assertEquals( "to/be/expunged", a.getBase() ); }
@Test public void model_3() { Model assem = FileManager.get().loadModel(dir+"graph-assembler.ttl") ; Resource xDft = assem.getResource("http://example/test#graphDft") ; Resource xNamed = assem.getResource("http://example/test#graphNamed") ; Store store = create(assem) ; Model model1 = (Model)Assembler.general.open(xDft) ; Model model2 = (Model)Assembler.general.open(xNamed) ; assertNotNull(model1 != model2) ; }
@Test public void testExtractsPropertyTimes() { APISpec a = SpecUtil.specFrom(s); Resource P = spec.getResource(spec.expandPrefix(":P")); Resource Q = spec.getResource(spec.expandPrefix(":Q")); PropertyExpiryTimes pet = PropertyExpiryTimes.buildForTests(P, 10L, Q, 20L); assertEquals(pet, a.getPropertyExpiryTimes()); }
@Test public void testOverriddenEndpointExpiryTime() { Model spec = makeModel("elda:cacheExpiryTime 17", "elda:cacheExpiryTime 2000"); Resource s = spec.getResource( spec.expandPrefix( ":s" ) ); Resource e = spec.getResource( spec.expandPrefix( ":e" ) ); APISpec a = SpecUtil.specFrom( s ); APIEndpointSpec eps = new APIEndpointSpec( a, null, e ); assertEquals( 2000 * 1000, eps.getCacheExpiryMilliseconds() ); }
@Test public void testDefaultEndpointExpiryTime() { Model spec = makeModel("", ""); Resource s = spec.getResource( spec.expandPrefix( ":s" ) ); Resource e = spec.getResource( spec.expandPrefix( ":e" ) ); APISpec a = SpecUtil.specFrom( s ); APIEndpointSpec eps = new APIEndpointSpec( a, null, e ); assertTrue( eps.getCacheExpiryMilliseconds() < 0); }
@Test public void testInheritedEndpointExpiryTime() { Model spec = makeModel("elda:cacheExpiryTime 17", ""); Resource s = spec.getResource( spec.expandPrefix( ":s" ) ); Resource e = spec.getResource( spec.expandPrefix( ":e" ) ); APISpec a = SpecUtil.specFrom( s ); APIEndpointSpec eps = new APIEndpointSpec( a, null, e ); assertEquals( 17 * 1000, eps.getCacheExpiryMilliseconds() ); }
private boolean hasMembershipTriples(Model containerModel) { Resource container = containerModel.getResource(directContainer); Resource membershipResource = container.getPropertyResourceValue(containerModel.createProperty(LDP.membershipResource.stringValue())); Resource hasMemberRelation = container.getPropertyResourceValue(containerModel.createProperty(LDP.hasMemberRelation.stringValue())); assertNotNull(membershipResource, MSG_MBRRES_NOTFOUND); // First verify the membership triples exist if (hasMemberRelation != null) { return membershipResource.hasProperty(containerModel.createProperty(hasMemberRelation.getURI())); } // Not if membership triple is not of form: (container, membership predicate, member), it may be the inverse. Resource isMemberOfRelation = container.getPropertyResourceValue(containerModel.createProperty(LDP.isMemberOfRelation.stringValue())); return containerModel.contains(null, containerModel.createProperty(isMemberOfRelation.getURI()), membershipResource); }
@Test public void model_2() { Model assem = FileManager.get().loadModel(dir+"graph-assembler.ttl") ; Resource x = assem.getResource("http://example/test#graphNamed") ; // Model for default graph Model model = (Model)Assembler.general.open(x) ; assertNotNull(model) ; }
@Test public void model_1() { Model assem = FileManager.get().loadModel(dir+"graph-assembler.ttl") ; Resource x = assem.getResource("http://example/test#graphDft") ; // Model for default graph Model model = (Model)Assembler.general.open(x) ; assertNotNull(model) ; }
public void testExtractsExpiry(long expected, String timeSpec) { Model spec = ModelIOUtils.modelFromTurtle ( ":s a api:API" + "; " + timeSpec + "; api:sparqlEndpoint <http://example.com/none>" + "." ); Resource s = spec.getResource( spec.expandPrefix( ":s" ) ); APISpec a = SpecUtil.specFrom( s ); assertEquals( expected, a.getCacheExpiryMilliseconds()); } }
/***********************************/ @Test public void testOrderProperties() { Resource subj = m.getResource( "http://example/test#subj" ); ModelWrapper mw = new ModelWrapper( m ); RDFNodeWrapper subjw = new RDFNodeWrapper( mw, subj ); List<PropertyValue> triples = new DefaultPropertyOrderingStrategy().orderProperties( subjw ); assertEquals( "http://example/test#p2", triples.get(0).getProp().getURI() ); assertEquals( "http://example/test#p3", triples.get(1).getProp().getURI() ); assertEquals( "http://example/test#p1", triples.get(2).getProp().getURI() ); }
@Test public void testWithAPIGraphTemplate() { Resource root = specWithAPIGraphTemplate.getResource( specWithAPIGraphTemplate.expandPrefix(":root")); APISpec a = SpecUtil.specFrom(root); // APIEndpointSpec A = getEndpoint(a, "endpointA"); assertEquals("hello/world", A.getGraphTemplate()); // APIEndpointSpec B = getEndpoint(a, "endpointB"); assertEquals("api/graph/template", B.getGraphTemplate()); }
@Test public void testWithoutAPIGraphTemplate() { Resource root = specWithoutAPIGraphTemplate.getResource( specWithoutAPIGraphTemplate.expandPrefix(":root")); APISpec a = SpecUtil.specFrom(root); // APIEndpointSpec A = getEndpoint(a, "endpointA"); assertEquals("hello/world", A.getGraphTemplate()); // APIEndpointSpec B = getEndpoint(a, "endpointB"); assertEquals(null, B.getGraphTemplate()); }
@Test public void testResultsCountSummaryNonEmpty() { final Model apiMetadataModel = ModelIOUtils.modelFromTurtle( Fixtures.COMMON_PREFIXES + Fixtures.PAGE_METADATA_GAMES ); Resource pageRoot = apiMetadataModel.getResource( "http://localhost:8080/standalone/hello/games.vhtml?_metadata=all" ); pageRoot.addProperty( OpenSearch.totalResults, apiMetadataModel.createTypedLiteral( 99 ) ); final Model apiObjectModel = ModelIOUtils.modelFromTurtle( Fixtures.PAGE_OBJECT_GAMES ); final Model apiResultsModel = ModelFactory.createUnion( apiMetadataModel, apiObjectModel ); ResultsModel rm = new ResultsModel( Fixtures.mockResultSet( context, apiResultsModel, apiObjectModel, apiMetadataModel, "APIResultsModel2" ) ); Page page1 = rm.page(); assertEquals( "Showing items 1 to 10 of 99", page1.resultsCountSummary() ); }
@Test public void testResultsCountSummaryEmpty() { final Model apiMetadataModel = ModelIOUtils.modelFromTurtle( Fixtures.COMMON_PREFIXES + Fixtures.PAGE_METADATA_GAMES ); Resource pageRoot = apiMetadataModel.getResource( "http://localhost:8080/standalone/hello/games.vhtml?_metadata=all" ); pageRoot.addProperty( OpenSearch.totalResults, apiMetadataModel.createTypedLiteral( 0 ) ); final Model apiObjectModel = ModelIOUtils.modelFromTurtle( Fixtures.PAGE_OBJECT_GAMES ); final Model apiResultsModel = ModelFactory.createUnion( apiMetadataModel, apiObjectModel ); ResultsModel rm = new ResultsModel( Fixtures.mockResultSet( context, apiResultsModel, apiObjectModel, apiMetadataModel, "APIResultsModel3" ) ); Page page1 = rm.page(); assertEquals( "0 results", page1.resultsCountSummary() ); }