@Test public void shouldConvertRdfObjectsToStrings() { final DatasetGraph mem = createMem(); mem.add( createAnon(), createURI("subject"), createURI("a/b/c"), NodeFactory.createLiteral("abc")); mem.add( createAnon(), createURI("subject"), createURI("a-numeric-type"), createTypedLiteral(0).asNode()); mem.add( createAnon(), createURI("subject"), createURI("an-empty-string"), createLiteral("")); mem.add(createAnon(), createURI("subject"), createURI("a-uri"), createURI("some-uri")); assertEquals( "abc", testObj.getObjectsAsString(mem, createURI("subject"), createResource("a/b/c"))); assertEquals( "0", testObj.getObjectsAsString(mem, createURI("subject"), createResource("a-numeric-type"))); assertEquals( "<empty>", testObj.getObjectsAsString(mem, createURI("subject"), createResource("an-empty-string"))); assertEquals( "<<a href=\"some-uri\">some-uri</a>>", testObj.getObjectsAsString(mem, createURI("subject"), createResource("a-uri"))); assertEquals( "", testObj.getObjectsAsString(mem, createURI("subject"), createResource("a-nonexistent-uri"))); }
@Test public void shouldExtractNamespaceAndPrefix() { final Model model = createDefaultModel(); model.setNsPrefix("prefix", "namespace"); assertEquals("prefix:", testObj.getNamespacePrefix(model, "namespace")); assertEquals("some-other-namespace", testObj.getNamespacePrefix(model, "some-other-namespace")); }
@Test public void shouldTryToExtractDublinCoreTitleFromNode() { final DatasetGraph mem = createMem(); mem.add(createAnon(), createURI("a/b/c"), DC_TITLE.asNode(), createLiteral("abc")); assertEquals("abc", testObj.getObjectTitle(mem, createURI("a/b/c"))); }
@Test public void shouldSortTriplesForDisplay() { final Model model = createDefaultModel(); model.setNsPrefix("prefix", "namespace"); final Property propertyA = model.createProperty("namespace", "a"); final Property propertyB = model.createProperty("namespace", "b"); final Property propertyC = model.createProperty("c"); final Literal literalA = model.createLiteral("a"); final Literal literalB = model.createLiteral("b"); final Resource resourceB = model.createResource("b"); model.add(resourceB, propertyA, literalA); final Resource a = model.createResource("a"); model.add(a, propertyC, literalA); model.add(a, propertyB, literalA); model.add(a, propertyA, literalA); model.add(a, propertyA, literalB); final Iterator<Quad> iterator = DatasetFactory.create(model).asDatasetGraph().find(); final List<Quad> sortedTriples = testObj.getSortedTriples(model, iterator); sortedTriples.get(0).matches(ANY, a.asNode(), propertyA.asNode(), literalA.asNode()); sortedTriples.get(1).matches(ANY, a.asNode(), propertyA.asNode(), literalB.asNode()); sortedTriples.get(2).matches(ANY, a.asNode(), propertyB.asNode(), literalA.asNode()); sortedTriples.get(3).matches(ANY, a.asNode(), propertyC.asNode(), literalA.asNode()); sortedTriples.get(4).matches(ANY, resourceB.asNode(), propertyC.asNode(), literalA.asNode()); }
@Test public void shouldRefuseToConvertAForeignUriToNodeBreadcrumbs() { final UriInfo mockUriInfo = getUriInfoImpl(); final Map<String, String> nodeBreadcrumbs = testObj.getNodeBreadcrumbs( mockUriInfo, createResource("http://somewhere/else/a/b/c").asNode()); assertTrue(nodeBreadcrumbs.isEmpty()); }
@Test public void shouldConvertPrefixMappingToSparqlUpdatePrefixPreamble() { final Model model = createDefaultModel(); model.setNsPrefix("prefix", "namespace"); final String prefixPreamble = testObj.getPrefixPreamble(model); assertEquals("PREFIX prefix: <namespace>\n\n", prefixPreamble); }
@Test public void shouldConvertAUriToNodeBreadcrumbs() { final UriInfo mockUriInfo = getUriInfoImpl(); final Map<String, String> nodeBreadcrumbs = testObj.getNodeBreadcrumbs( mockUriInfo, createResource("http://localhost/fcrepo/a/b/c").asNode()); assertEquals( of( "http://localhost/fcrepo/a", "a", "http://localhost/fcrepo/a/b", "b", "http://localhost/fcrepo/a/b/c", "c"), nodeBreadcrumbs); }
@Test public void shouldUseTheObjectUriIfATitleIsNotAvailable() { final DatasetGraph mem = createMem(); assertEquals("a/b/c", testObj.getObjectTitle(mem, createURI("a/b/c"))); }
@Before public void setUp() { testObj = ViewHelpers.getInstance(); }
@Test public void shouldConvertRdfResourcesToNodes() { assertEquals(CREATED_BY.asNode(), testObj.asNode(CREATED_BY)); }
@Test public void shouldJustUseTheStringIfItIsALiteral() { final DatasetGraph mem = createMem(); final Node lit = createLiteral("xyz"); assertEquals("\"xyz\"", testObj.getObjectTitle(mem, lit)); }
@Test public void shouldUsetheBNodeIdIfItIsABNode() { final DatasetGraph mem = createMem(); final Node anon = createAnon(); assertEquals(anon.getBlankNodeLabel(), testObj.getObjectTitle(mem, anon)); }