Search in sources :

Example 1 with DocumentLoader

use of com.github.jsonldjava.core.DocumentLoader in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method testAdditionsWithMultiValues.

@Test
public void testAdditionsWithMultiValues() throws Exception {
    String testMultiValueAdditions = "{\n" + "  \"@type\": \"prov:Activity\",\n" + "  \"generates\": [{\n" + "\t  \"@type\": \"prov:Entity\",\n" + "    \"specializationOf\": {\"@id\": \"http://example.com/the/actual/entitys\"},\n" + "    \"additions\": [\n" + "      {\"@type\": \"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\", " + "\"predicate\": \"http://example.org/pred1\", \"value\": \"value1\"},\n" + "      {\"@type\": \"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\"," + " \"predicate\": \"http://example.org/pred1\", \"value\": \"value2\"},\n" + "      {\"@type\": \"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\", " + "\"predicate\": \"http://example.org/pred2\", \"value\": \"value3\"},\n" + "      {\"@type\": \"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\", " + "\"predicate\": \"http://example.org/pred2\", \"value\": \"value4\"}\n" + "    ]\n" + "  }],\n" + context + "}";
    JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testMultiValueAdditions, new DummyQuadStore(), EDITOR_URI, "test", CLOCK);
    creator.sendQuads(basicRdfPatchSerializer, s -> {
    }, null);
    List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("http://example.org/pred")));
    assertThat(filteredResult, hasItems("+<http://example.com/the/actual/entitys> <http://example.org/pred1> \"value1\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <http://example.org/pred1> \"value2\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <http://example.org/pred2> \"value3\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <http://example.org/pred2> \"value4\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n"));
}
Also used : DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 2 with DocumentLoader

use of com.github.jsonldjava.core.DocumentLoader in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method testMultiAddition.

@Test
public void testMultiAddition() throws Exception {
    String testMultiAddition = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entitys\"\n" + "         },\n" + "         \"additions\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            },\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred2\",\n" + "               \"value\":\"value2\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testMultiAddition, new DummyQuadStore(), EDITOR_URI, "test", CLOCK);
    creator.sendQuads(basicRdfPatchSerializer, s -> {
    }, null);
    List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("http://example.org/pred")));
    assertThat(filteredResult, hasItems("+<http://example.com/the/actual/entitys> <http://example.org/pred1> \"value1\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <http://example.org/pred2> \"value2\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n"));
}
Also used : DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 3 with DocumentLoader

use of com.github.jsonldjava.core.DocumentLoader in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method retractsPreviousRevision.

@Test
public void retractsPreviousRevision() throws Exception {
    String testRetractsRevision = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"@id\":\"_:b2\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entitys\"\n" + "         },\n" + "         \"wasRevisionOf\":{\n" + "            \"@id\":\"http://example.org/revision1\"\n" + "         },\n" + "         \"replacements\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/revision1", PROV_SPECIALIZATION_OF, "http://example.com/the/actual/entitys", null).with("http://example.com/the/actual/entitys", TIM_LATEST_REVISION, "http://example.org/revision1");
    JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testRetractsRevision, testQuadStore, EDITOR_URI, "test", CLOCK);
    creator.sendQuads(basicRdfPatchSerializer, s -> {
    }, null);
    List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("latestRevision")));
    assertThat(filteredResult, containsInAnyOrder("-<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://example.org/revision1" + "> <" + defaultGraph + "> .\n", "+<http://example.com/the/actual/entitys> <" + TIM_LATEST_REVISION + "> <http://timbuctoo.huygens.knaw.nl/static/v5/skolemized/test/b1> <" + defaultGraph + "> .\n"));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 4 with DocumentLoader

use of com.github.jsonldjava.core.DocumentLoader in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method testDeletions.

@Test
public void testDeletions() throws Exception {
    String testDeletions = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entitys\"\n" + "         },\n" + "         \"deletions\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            },\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred2\",\n" + "               \"value\":\"value2\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    JsonProvenanceToRdfPatch creator = fromCurrentState(new DocumentLoader(), testDeletions, new DummyQuadStore(), EDITOR_URI, "test", CLOCK);
    creator.sendQuads(basicRdfPatchSerializer, s -> {
    }, null);
    List<String> filteredResult = Lists.newArrayList(Collections2.filter(result, Predicates.containsPattern("http://example.org/pred")));
    assertThat(filteredResult, hasItems("-<http://example.com/the/actual/entitys> <http://example.org/pred1> \"value1\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n", "-<http://example.com/the/actual/entitys> <http://example.org/pred2> \"value2\"" + "^^<http://www.w3.org/2001/XMLSchema#string> <" + defaultGraph + "> .\n"));
}
Also used : DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Example 5 with DocumentLoader

use of com.github.jsonldjava.core.DocumentLoader in project timbuctoo by HuygensING.

the class JsonProvenanceToRdfPatchTest method doesOptimisticLocking.

@Test
public void doesOptimisticLocking() throws Exception {
    String examplePatch = "{\n" + "   \"@type\":\"prov:Activity\",\n" + "   \"http://www.w3.org/ns/prov#generates\":[\n" + "      {\n" + "         \"@type\":\"prov:Entity\",\n" + "         \"specializationOf\":{\n" + "            \"@id\":\"http://example.com/the/actual/entity1\"\n" + "         },\n" + "        \"wasRevisionOf\":{\n" + "            \"@id\":\"http://example.org/revision1\"\n" + "         },\n" + "         \"additions\":[\n" + "            {\n" + "               \"@type\":\"http://timbuctoo.huygens.knaw.nl/v5/vocabulary#mutation\",\n" + "               \"predicate\":\"http://example.org/pred1\",\n" + "               \"value\":\"value1\"\n" + "            }\n" + "         ]\n" + "      }\n" + "   ],\n" + context + "}";
    QuadStore testQuadStore = new DummyQuadStore().with("http://example.org/entity1", RdfConstants.TIM_LATEST_REVISION, "http://example.org/revision2", null);
    boolean exceptionWasThrown = false;
    try {
        fromCurrentState(new DocumentLoader(), examplePatch, testQuadStore, "http://example.org/users/myUser", UUID.randomUUID().toString(), CLOCK);
    } catch (ConcurrentUpdateException e) {
        exceptionWasThrown = true;
    }
    assertThat(exceptionWasThrown, is(true));
}
Also used : QuadStore(nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore) DocumentLoader(com.github.jsonldjava.core.DocumentLoader) Test(org.junit.Test)

Aggregations

DocumentLoader (com.github.jsonldjava.core.DocumentLoader)7 Test (org.junit.Test)7 QuadStore (nl.knaw.huygens.timbuctoo.v5.datastores.quadstore.QuadStore)3