예제 #1
0
  @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(
        "&lt;<a href=\"some-uri\">some-uri</a>&gt;",
        testObj.getObjectsAsString(mem, createURI("subject"), createResource("a-uri")));
    assertEquals(
        "",
        testObj.getObjectsAsString(mem, createURI("subject"), createResource("a-nonexistent-uri")));
  }
예제 #2
0
  @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"));
  }
예제 #3
0
  @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")));
  }
예제 #4
0
  @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());
  }
예제 #5
0
  @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());
  }
예제 #6
0
  @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);
  }
예제 #7
0
  @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);
  }
예제 #8
0
  @Test
  public void shouldUseTheObjectUriIfATitleIsNotAvailable() {
    final DatasetGraph mem = createMem();

    assertEquals("a/b/c", testObj.getObjectTitle(mem, createURI("a/b/c")));
  }
예제 #9
0
 @Before
 public void setUp() {
   testObj = ViewHelpers.getInstance();
 }
예제 #10
0
 @Test
 public void shouldConvertRdfResourcesToNodes() {
   assertEquals(CREATED_BY.asNode(), testObj.asNode(CREATED_BY));
 }
예제 #11
0
 @Test
 public void shouldJustUseTheStringIfItIsALiteral() {
   final DatasetGraph mem = createMem();
   final Node lit = createLiteral("xyz");
   assertEquals("\"xyz\"", testObj.getObjectTitle(mem, lit));
 }
예제 #12
0
 @Test
 public void shouldUsetheBNodeIdIfItIsABNode() {
   final DatasetGraph mem = createMem();
   final Node anon = createAnon();
   assertEquals(anon.getBlankNodeLabel(), testObj.getObjectTitle(mem, anon));
 }