/** * Check that the given interaction model is supported by the * underlying persistence layer. * * @param interactionModel the interaction model * @return true if the interaction model is supported; false otherwise */ protected boolean supportsInteractionModel(final IRI interactionModel) { return getServices().getResourceService().supportedInteractionModels().contains(interactionModel); }
private void setUpResourceService() { when(mockResourceService.get(eq(nonexistentIRI))).thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); when(mockResourceService.supportedInteractionModels()).thenReturn(allModels); when(mockResourceService.get(eq(resourceIRI))).thenAnswer(inv -> completedFuture(mockResource)); when(mockResourceService.get(eq(childIRI))).thenAnswer(inv -> completedFuture(mockChildResource)); when(mockResourceService.get(eq(parentIRI))).thenAnswer(inv -> completedFuture(mockParentResource)); when(mockResourceService.get(eq(rootIRI))).thenAnswer(inv -> completedFuture(mockRootResource)); when(mockResourceService.get(eq(groupIRI))).thenAnswer(inv -> completedFuture(mockGroupResource)); when(mockResourceService.get(eq(memberIRI))).thenAnswer(inv -> completedFuture(mockMemberResource)); }
@Test public void testCanRead4() { when(mockSession.getAgent()).thenReturn(agentIRI); when(mockParentResource.getInteractionModel()).thenReturn(LDP.DirectContainer); when(mockResourceService.supportedInteractionModels()).thenReturn(singleton(LDP.DirectContainer)); when(mockParentResource.getMembershipResource()).thenReturn(of(memberIRI)); assertAll("Check user can read all resources", checkAllCanRead()); }
@Test public void testCanRead5() { when(mockSession.getAgent()).thenReturn(addisonIRI); when(mockResourceService.supportedInteractionModels()).thenReturn(singleton(LDP.IndirectContainer)); when(mockParentResource.getInteractionModel()).thenReturn(LDP.IndirectContainer); when(mockParentResource.getMembershipResource()).thenReturn(of(memberIRI)); assertAll("Check user can read all resources", checkAllCanRead()); }
private void setUpResourceService() { when(mockResourceService.supportedInteractionModels()).thenReturn(allInteractionModels); when(mockResourceService.get(any(IRI.class))).thenAnswer(inv -> completedFuture(mockResource)); when(mockResourceService.create(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null)); when(mockResourceService.replace(any(Metadata.class), any(Dataset.class))).thenReturn(completedFuture(null)); when(mockResourceService.delete(any(Metadata.class))).thenReturn(completedFuture(null)); when(mockResourceService.add(any(IRI.class), any(Dataset.class))).thenReturn(completedFuture(null)); when(mockResourceService.skolemize(any(Literal.class))).then(returnsFirstArg()); when(mockResourceService.skolemize(any(IRI.class))).then(returnsFirstArg()); when(mockResourceService.skolemize(any(BlankNode.class))).thenAnswer(inv -> rdf.createIRI(TRELLIS_BNODE_PREFIX + ((BlankNode) inv.getArgument(0)).uniqueReference())); when(mockResourceService.toInternal(any(RDFTerm.class), any())).thenCallRealMethod(); when(mockResourceService.toExternal(any(RDFTerm.class), any())).thenCallRealMethod(); when(mockResourceService.touch(any(IRI.class))).thenReturn(completedFuture(null)); }
@Test public void testDeletePersistenceSupport() { when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet()); final DeleteHandler handler = new DeleteHandler(mockTrellisRequest, mockBundler, baseUrl); final Response res = assertThrows(WebApplicationException.class, () -> handler.initialize(mockParent, mockResource)).getResponse(); assertTrue(res.getLinks().stream().anyMatch(link -> link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) && link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing Link headers"); assertEquals(TEXT_PLAIN_TYPE, res.getMediaType(), "Incorrect media type"); }
@Test public void testNoLdpRsSupport() { when(mockTrellisRequest.getContentType()).thenReturn(APPLICATION_SPARQL_UPDATE); when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet()); final PatchHandler patchHandler = new PatchHandler(mockTrellisRequest, insert, mockBundler, null, null); final Response res = assertThrows(BadRequestException.class, () -> patchHandler.initialize(mockParent, mockResource), "No exception for an unsupported IXN model!").getResponse(); assertEquals(BAD_REQUEST, res.getStatusInfo(), "Incorrect response code!"); assertTrue(res.getLinks().stream().anyMatch(link -> link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) && link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing Link header with constraint!"); }
@Test public void testCanWrite2() { when(mockSession.getAgent()).thenReturn(addisonIRI); when(mockResourceService.supportedInteractionModels()).thenReturn(singleton(LDP.Container)); assertAll("Check writability for " + addisonIRI, checkCanWrite(nonexistentIRI), checkCanWrite(resourceIRI), checkCanWrite(childIRI), checkCannotWrite(parentIRI), checkCannotWrite(rootIRI)); }
when(mockResourceService.get(eq(root))).thenAnswer(inv -> completedFuture(mockRootResource)); when(mockResourceService.get(eq(childIdentifier))).thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); when(mockResourceService.supportedInteractionModels()).thenReturn(allInteractionModels); when(mockResourceService.get(eq(newresourceIdentifier))).thenAnswer(inv -> completedFuture(MISSING_RESOURCE)); when(mockResourceService.get(eq(binaryIdentifier))).thenAnswer(inv -> completedFuture(mockBinaryResource));
@Test public void testUnsupportedType() throws IOException { when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet()); when(mockTrellisRequest.getLink()).thenReturn(fromUri(LDP.Container.getIRIString()).rel("type").build()); final PostHandler handler = buildPostHandler("/emptyData.txt", "newresource", null); final Response res = assertThrows(BadRequestException.class, () -> handler.createResource(handler.initialize(mockParent, MISSING_RESOURCE)) .toCompletableFuture().join(), "No exception thrown when the IXN model isn't supported!").getResponse(); assertEquals(BAD_REQUEST, res.getStatusInfo(), "Incorrect response code!"); assertTrue(res.getLinks().stream().anyMatch(link -> link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) && link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing constraint Link header!"); }
@Test public void testUnsupportedType() { when(mockResourceService.supportedInteractionModels()).thenReturn(emptySet()); when(mockTrellisRequest.getContentType()).thenReturn(TEXT_TURTLE); when(mockTrellisRequest.getLink()).thenReturn(fromUri(LDP.Resource.getIRIString()).rel("type").build()); final PutHandler handler = buildPutHandler("/simpleTriple.ttl", null); final Response res = assertThrows(BadRequestException.class, () -> handler.setResource(handler.initialize(mockParent, mockResource)).toCompletableFuture().join(), "No exception when the interaction model isn't supported!").getResponse(); assertEquals(BAD_REQUEST, res.getStatusInfo(), "Incorrect response code!"); assertTrue(res.getLinks().stream().anyMatch(link -> link.getUri().toString().equals(UnsupportedInteractionModel.getIRIString()) && link.getRel().equals(LDP.constrainedBy.getIRIString())), "Missing constraint header!"); }
default void testLdpDC() throws Exception { assumeTrue(getResourceService().supportedInteractionModels().contains(LDP.DirectContainer));
default void testLdpDC() throws Exception { assumeTrue(getResourceService().supportedInteractionModels().contains(LDP.DirectContainer));
default void testLdpIC() throws Exception { assumeTrue(getResourceService().supportedInteractionModels().contains(LDP.IndirectContainer));
default void testLdpIC() throws Exception { assumeTrue(getResourceService().supportedInteractionModels().contains(LDP.IndirectContainer));