Ejemplo n.º 1
0
  @Test
  public void testReplaceObjectGraphWithErrors() {
    final String pid = getRandomPid();
    final Container object = containerService.findOrCreate(session, pid);

    final Model model =
        createDefaultModel()
            .read(
                toInputStream(
                    "<> <info:some-property> <relative-url> . \n"
                        + "<> <info:some-other-property> <another-relative-url>"),
                subjects.reverse().convert(object).toString(),
                "TTL");
    MalformedRdfException e = null;
    try {
      object.replaceProperties(subjects, model, object.getTriples(subjects, emptySet()));
    } catch (final MalformedRdfException ex) {
      e = ex;
    }

    assertNotNull("Expected an exception to get thrown", e);
    assertEquals("Excepted two nested exceptions", 2, e.getMessage().split("\n").length);
    assertTrue(e.getMessage().contains("/relative-url"));
    assertTrue(e.getMessage().contains("/another-relative-url"));
  }
Ejemplo n.º 2
0
  @Test(expected = MalformedRdfException.class)
  public void testUpdatingObjectGraphWithOutOfDomainSubjects() throws MalformedRdfException {
    final Container object = containerService.findOrCreate(session, "/graphObject");

    object.updateProperties(
        subjects,
        "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "INSERT { <http://example/egbook> dc:title "
            + "\"This is an example of an update that will be "
            + "ignored\" } WHERE {}",
        object.getTriples(subjects, PROPERTIES));
  }
Ejemplo n.º 3
0
  @Test
  public void testUpdatingObjectGraphWithErrors() {
    final String pid = getRandomPid();
    final Container object = containerService.findOrCreate(session, pid);

    MalformedRdfException e = null;
    try {
      object.updateProperties(
          subjects,
          "INSERT DATA { <> <info:some-property> <relative-url> . \n"
              + "<> <info:some-other-property> <another-relative-url> }",
          object.getTriples(subjects, emptySet()));
    } catch (final MalformedRdfException ex) {
      e = ex;
    }

    assertNotNull("Expected an exception to get thrown", e);
    assertEquals("Excepted two nested exceptions", 2, e.getMessage().split("\n").length);
    assertTrue(e.getMessage().contains("/relative-url"));
    assertTrue(e.getMessage().contains("/another-relative-url"));
  }
Ejemplo n.º 4
0
  @Test
  public void testObjectGraph() throws Exception {
    final Container object = containerService.findOrCreate(session, "/graphObject");
    final Model model = object.getTriples(subjects, PROPERTIES).collect(toModel());

    final Resource graphSubject = subjects.reverse().convert(object);

    assertFalse(
        "Graph store should not contain JCR prefixes",
        compile("jcr").matcher(model.toString()).find());
    assertFalse(
        "Graph store should contain our fcrepo prefix",
        compile("fcrepo").matcher(model.toString()).find());

    object.updateProperties(
        subjects,
        "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "INSERT { <"
            + graphSubject
            + "> dc:title "
            + "\"This is an example title\" } WHERE {}",
        object.getTriples(subjects, PROPERTIES));

    final Value[] values = getJcrNode(object).getProperty("dc:title").getValues();
    assertTrue(values.length > 0);

    assertTrue(values[0].getString(), values[0].getString().equals("This is an example title"));

    object.updateProperties(
        subjects,
        "PREFIX myurn: <info:myurn/>\n"
            + "INSERT { <"
            + graphSubject
            + "> myurn:info "
            + "\"This is some example data\"} WHERE {}",
        object.getTriples(subjects, PROPERTIES));

    final Value value =
        getJcrNode(object)
            .getProperty(
                getJcrNode(object).getSession().getNamespacePrefix("info:myurn/") + ":info")
            .getValues()[0];

    assertEquals("This is some example data", value.getString());

    object.updateProperties(
        subjects,
        "PREFIX dcterms: <http://purl.org/dc/terms/>\n"
            + "INSERT { <"
            + graphSubject
            + "> dcterms:"
            + "isPartOf <"
            + graphSubject
            + "> } WHERE {}",
        object.getTriples(subjects, PROPERTIES));

    final Value refValue = getJcrNode(object).getProperty("dcterms:isPartOf_ref").getValues()[0];
    assertTrue(
        refValue.getString(), refValue.getString().equals(getJcrNode(object).getIdentifier()));

    object.updateProperties(
        subjects,
        "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n"
            + "DELETE { <"
            + graphSubject
            + "> dc:title "
            + "\"This is an example title\" } WHERE {}",
        object.getTriples(subjects, PROPERTIES));

    assertFalse("Found unexpected dc:title", getJcrNode(object).hasProperty("dc:title"));

    object.updateProperties(
        subjects,
        "PREFIX dcterms: <http://purl.org/dc/terms/>\n"
            + "DELETE { <"
            + graphSubject
            + "> "
            + "dcterms:isPartOf <"
            + graphSubject
            + "> "
            + "} WHERE {}",
        object.getTriples(subjects, PROPERTIES));
    assertFalse("found unexpected reference", getJcrNode(object).hasProperty("dcterms:isPartOf"));

    session.save();
  }
Ejemplo n.º 5
0
  @Test
  public void testObjectGraphWithUriProperty() throws RepositoryException {
    final Container object = containerService.findOrCreate(session, "/graphObject");
    final Resource graphSubject = subjects.reverse().convert(object);

    object.updateProperties(
        subjects,
        "PREFIX some: <info:some#>\n"
            + "INSERT { <"
            + graphSubject
            + "> some:urlProperty "
            + "<"
            + graphSubject
            + "> } WHERE {}",
        object.getTriples(subjects, PROPERTIES));

    final String prefix = session.getWorkspace().getNamespaceRegistry().getPrefix("info:some#");
    final String propertyName = prefix + ":urlProperty";
    final String referencePropertyName = getReferencePropertyName(propertyName);

    assertTrue(getJcrNode(object).hasProperty(referencePropertyName));
    assertFalse(getJcrNode(object).hasProperty(propertyName));

    assertEquals(
        getJcrNode(object),
        session.getNodeByIdentifier(
            getJcrNode(object)
                .getProperty(prefix + ":urlProperty_ref")
                .getValues()[0]
                .getString()));

    object.updateProperties(
        subjects,
        "PREFIX some: <info:some#>\n"
            + "DELETE { <"
            + graphSubject
            + "> some:urlProperty "
            + "<"
            + graphSubject
            + "> } WHERE {}",
        object.getTriples(subjects, PROPERTIES));

    assertFalse(getJcrNode(object).hasProperty(referencePropertyName));
    assertFalse(getJcrNode(object).hasProperty(propertyName));

    object.updateProperties(
        subjects,
        "PREFIX some: <info:some#>\n"
            + "INSERT DATA { <"
            + graphSubject
            + "> some:urlProperty <"
            + graphSubject
            + ">;\n"
            + "       some:urlProperty <info:somewhere/else> . }",
        object.getTriples(subjects, PROPERTIES));

    assertTrue(getJcrNode(object).hasProperty(referencePropertyName));
    assertTrue(getJcrNode(object).hasProperty(propertyName));

    assertEquals(1, getJcrNode(object).getProperty(prefix + ":urlProperty_ref").getValues().length);
    assertEquals(
        getJcrNode(object),
        session.getNodeByIdentifier(
            getJcrNode(object)
                .getProperty(prefix + ":urlProperty_ref")
                .getValues()[0]
                .getString()));
  }