use of org.trellisldp.api.MementoService in project trellis by trellis-ldp.
the class DBWrappedMementoServiceTest method testMementoService.
@Test
void testMementoService() {
final Resource mockResource = mock(Resource.class);
when(mockMementoService.put(any(Resource.class))).thenAnswer(inv -> completedFuture(null));
when(mockMementoService.get(any(IRI.class), any(Instant.class))).thenAnswer(inv -> completedFuture(mockResource));
final MementoService svc = new DBWrappedMementoService(ds, mockMementoService);
final Instant time = now();
final IRI identifier = rdf.createIRI("trellis:data/resource");
when(mockResource.getIdentifier()).thenReturn(identifier);
when(mockResource.getModified()).thenReturn(time);
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
when(mockResource.getModified()).thenReturn(time.plusSeconds(2L));
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
when(mockResource.getModified()).thenReturn(time.plusSeconds(4L));
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
final SortedSet<Instant> mementos = svc.mementos(identifier).toCompletableFuture().join();
assertTrue(mementos.contains(time.truncatedTo(SECONDS)));
assertTrue(mementos.contains(time.plusSeconds(2L).truncatedTo(SECONDS)));
assertTrue(mementos.contains(time.plusSeconds(4L).truncatedTo(SECONDS)));
when(mockResource.getModified()).thenReturn(time);
final Resource res = svc.get(identifier, time).toCompletableFuture().join();
assertEquals(time, res.getModified());
}
use of org.trellisldp.api.MementoService in project trellis by trellis-ldp.
the class DBWrappedMementoServiceTest method testMementoUtils.
@Test
void testMementoUtils() {
final Resource mockResource = mock(Resource.class);
when(mockMementoService.put(any(Resource.class))).thenAnswer(inv -> completedFuture(null));
when(mockMementoService.get(any(IRI.class), any(Instant.class))).thenAnswer(inv -> completedFuture(mockResource));
final MementoService svc = new DBWrappedMementoService(ds, mockMementoService);
final Instant time = now();
final IRI identifier = rdf.createIRI("trellis:data/resource");
when(mockResource.getIdentifier()).thenReturn(identifier);
when(mockResource.getModified()).thenReturn(time);
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
when(mockResource.getModified()).thenReturn(time.plusSeconds(2L));
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
when(mockResource.getModified()).thenReturn(time.plusSeconds(4L));
assertDoesNotThrow(svc.put(mockResource).toCompletableFuture()::join);
final SortedSet<Instant> mementos = svc.mementos(identifier).toCompletableFuture().join();
assertTrue(mementos.contains(time.truncatedTo(SECONDS)));
assertTrue(mementos.contains(time.plusSeconds(2L).truncatedTo(SECONDS)));
assertTrue(mementos.contains(time.plusSeconds(4L).truncatedTo(SECONDS)));
when(mockResource.getModified()).thenReturn(time);
final Resource res = svc.get(identifier, time).toCompletableFuture().join();
assertEquals(time, res.getModified());
}
use of org.trellisldp.api.MementoService in project trellis-extensions by trellis-ldp.
the class S3MementoServiceTest method testMementoRDFSource.
@Test
void testMementoRDFSource() {
final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + "mementos/" + base + "/resource");
final Resource res = mock(Resource.class);
final Instant time = now();
final Quad quad = rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Title"));
final Quad acl = rdf.createQuad(Trellis.PreferAccessControl, identifier, ACL.mode, ACL.Read);
when(res.getModified()).thenReturn(time);
when(res.getIdentifier()).thenReturn(identifier);
when(res.getContainer()).thenReturn(of(root));
when(res.getInteractionModel()).thenReturn(LDP.RDFSource);
when(res.getBinaryMetadata()).thenReturn(empty());
when(res.getMembershipResource()).thenReturn(empty());
when(res.getMemberRelation()).thenReturn(empty());
when(res.getMemberOfRelation()).thenReturn(empty());
when(res.getInsertedContentRelation()).thenReturn(empty());
when(res.stream()).thenAnswer(inv -> Stream.of(quad, acl));
final MementoService svc = new S3MementoService();
assertDoesNotThrow(svc.put(res).toCompletableFuture()::join);
svc.get(identifier, time).thenAccept(r -> {
assertEquals(identifier, r.getIdentifier());
assertEquals(LDP.RDFSource, r.getInteractionModel());
assertEquals(time, r.getModified());
assertEquals(of(root), r.getContainer());
assertTrue(r.stream().anyMatch(isEqual(quad)));
assertFalse(r.getBinaryMetadata().isPresent());
assertFalse(r.getMembershipResource().isPresent());
assertFalse(r.getMemberRelation().isPresent());
assertFalse(r.getMemberOfRelation().isPresent());
assertFalse(r.getInsertedContentRelation().isPresent());
assertTrue(r.getMetadataGraphNames().contains(Trellis.PreferAccessControl));
assertEquals(1L, r.stream(Trellis.PreferServerManaged).count());
}).toCompletableFuture().join();
final Resource res2 = mock(Resource.class);
final Instant time2 = time.plusSeconds(10L);
final Quad quad2 = rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Better Title"));
when(res2.getModified()).thenReturn(time2);
when(res2.getIdentifier()).thenReturn(identifier);
when(res2.getContainer()).thenReturn(of(root));
when(res2.getInteractionModel()).thenReturn(LDP.RDFSource);
when(res2.getBinaryMetadata()).thenReturn(empty());
when(res2.getMembershipResource()).thenReturn(empty());
when(res2.getMemberRelation()).thenReturn(empty());
when(res2.getMemberOfRelation()).thenReturn(empty());
when(res2.getInsertedContentRelation()).thenReturn(empty());
when(res2.stream()).thenAnswer(inv -> Stream.of(quad2, acl));
assertDoesNotThrow(svc.put(res2).toCompletableFuture()::join);
svc.mementos(identifier).thenAccept(mementos -> {
assertTrue(mementos.contains(time.truncatedTo(SECONDS)));
assertTrue(mementos.contains(time2.truncatedTo(SECONDS)));
});
svc.get(identifier, time.plusSeconds(5L)).thenAccept(r -> assertEquals(time, r.getModified()));
svc.get(identifier, time2.plusSeconds(5L)).thenAccept(r -> assertEquals(time2, r.getModified()));
}
use of org.trellisldp.api.MementoService in project trellis-extensions by trellis-ldp.
the class S3MementoServiceTest method testMementoIndirectContainer.
@Test
void testMementoIndirectContainer() {
final IRI identifier = rdf.createIRI(TRELLIS_DATA_PREFIX + "mementos/" + base + "/container");
final IRI member = rdf.createIRI(TRELLIS_DATA_PREFIX + "mementos/" + base + "/resource");
final Resource res = mock(Resource.class);
final Instant time = now();
final Quad quad = rdf.createQuad(Trellis.PreferUserManaged, identifier, DC.title, rdf.createLiteral("Title"));
final Quad acl = rdf.createQuad(Trellis.PreferAccessControl, identifier, ACL.mode, ACL.Write);
when(res.getModified()).thenReturn(time);
when(res.getIdentifier()).thenReturn(identifier);
when(res.getContainer()).thenReturn(of(root));
when(res.getInteractionModel()).thenReturn(LDP.IndirectContainer);
when(res.getBinaryMetadata()).thenReturn(empty());
when(res.getMembershipResource()).thenReturn(of(member));
when(res.getMemberRelation()).thenReturn(of(LDP.member));
when(res.getMemberOfRelation()).thenReturn(of(DC.isPartOf));
when(res.getInsertedContentRelation()).thenReturn(of(LDP.MemberSubject));
when(res.stream()).thenAnswer(inv -> Stream.of(quad, acl));
final MementoService svc = new S3MementoService();
assertDoesNotThrow(svc.put(res).toCompletableFuture()::join);
svc.get(identifier, time).thenAccept(r -> {
assertEquals(identifier, r.getIdentifier());
assertEquals(LDP.IndirectContainer, r.getInteractionModel());
assertEquals(time, r.getModified());
assertEquals(of(root), r.getContainer());
assertTrue(r.stream().anyMatch(isEqual(quad)));
assertFalse(r.getBinaryMetadata().isPresent());
assertEquals(of(member), r.getMembershipResource());
assertEquals(of(LDP.member), r.getMemberRelation());
assertEquals(of(DC.isPartOf), r.getMemberOfRelation());
assertEquals(of(LDP.MemberSubject), r.getInsertedContentRelation());
assertTrue(r.getMetadataGraphNames().contains(Trellis.PreferAccessControl));
assertFalse(r.getMetadataGraphNames().contains(Trellis.PreferAudit));
}).toCompletableFuture().join();
svc.mementos(identifier).thenAccept(mementos -> assertTrue(mementos.contains(time)));
}
use of org.trellisldp.api.MementoService in project trellis-extensions by trellis-ldp.
the class S3MementoServiceTest method testMementoError.
@Test
void testMementoError() {
final Resource res = mock(Resource.class);
when(res.getInteractionModel()).thenAnswer(inv -> {
throw new IOException("Expected");
});
final MementoService svc = new S3MementoService();
assertThrows(CompletionException.class, svc.put(res).toCompletableFuture()::join);
}
Aggregations