@Override public Set<Link> getLinks() { return delegate.getLinks(); }
@Override public Set<Link> getLinks() { return rawResponse.getLinks(); }
public Set<Link> getLinks() { return r.getLinks(); }
protected Stream<Executable> checkLdpType(final Response res, final IRI type) { final Set<String> types = HttpUtils.ldpResourceTypes(type).map(IRI::getIRIString).collect(toSet()); final Set<String> responseTypes = res.getLinks().stream().filter(link -> TYPE.equals(link.getRel())) .map(link -> link.getUri().toString()).collect(toSet()); return of(LDP.Resource, LDP.RDFSource, LDP.NonRDFSource, LDP.Container, LDP.BasicContainer, LDP.DirectContainer, LDP.IndirectContainer).map(t -> checkLdpType(types, responseTypes, t)); }
private Stream<Executable> checkBinaryDescription(final Response res) { return Stream.of( () -> assertEquals(OK, res.getStatusInfo(), "Incorrect response code!"), () -> assertEquals(-1, res.getLength(), "Incorrect response size!"), () -> assertEquals(from(time), res.getLastModified(), "Incorrect modified date!"), () -> assertTrue(res.getMediaType().isCompatible(TEXT_TURTLE_TYPE), "Incompatible content-type!"), () -> assertTrue(res.getLinks().stream() .anyMatch(link -> link.getRel().equals("describes") && !link.getUri().toString().endsWith("?ext=description")), "MIssing rel=describes header!"), () -> assertTrue(res.getLinks().stream() .anyMatch(link -> link.getRel().equals("canonical") && link.getUri().toString().endsWith("?ext=description")), "Missing rel=canonical header!"), () -> assertAll("Check LDP type link headers", checkLdpType(res, LDP.RDFSource))); }
@Test public void testExtraLinks() { final String inbox = "http://ldn.example.com/inbox"; final String annService = "http://annotation.example.com/resource"; when(mockResource.getExtraLinkRelations()).thenAnswer(inv -> Stream.of( new SimpleEntry<>(annService, OA.annotationService.getIRIString()), new SimpleEntry<>(SKOS.Concept.getIRIString(), "type"), new SimpleEntry<>(inbox, "inbox"))); final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, false, true, true, null, baseUrl); final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource))) .toCompletableFuture().join().build(); assertEquals(OK, res.getStatusInfo(), "Incorrect response code!"); assertTrue(res.getLinks().stream().anyMatch(hasType(SKOS.Concept)), "Missing extra type link header!"); assertTrue(res.getLinks().stream().anyMatch(hasLink(rdf.createIRI(inbox), "inbox")), "No ldp:inbox header!"); assertTrue(res.getLinks().stream().anyMatch(hasLink(rdf.createIRI(annService), OA.annotationService.getIRIString())), "Missing extra annotationService link header!"); }
@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 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 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!"); }
@Test public void testGetBinary() throws IOException { when(mockResource.getBinaryMetadata()).thenReturn(of(testBinary)); when(mockResource.getInteractionModel()).thenReturn(LDP.NonRDFSource); when(mockTrellisRequest.getAcceptableMediaTypes()).thenReturn(singletonList(WILDCARD_TYPE)); final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, false, true, true, null, baseUrl); final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource))) .toCompletableFuture().join().build(); assertEquals(OK, res.getStatusInfo(), "Incorrect response code!"); assertEquals(-1, res.getLength(), "Incorrect response length!"); assertEquals(from(time), res.getLastModified(), "Incorrect content-type header!"); assertTrue(res.getMediaType().isCompatible(TEXT_PLAIN_TYPE), "Incorrect content-type header!"); assertTrue(res.getLinks().stream() .anyMatch(link -> link.getRel().equals("describedby") && link.getUri().toString().endsWith("?ext=description")), "Missing rel=describedby header!"); assertTrue(res.getLinks().stream() .anyMatch(link -> link.getRel().equals("canonical") && !link.getUri().toString().endsWith("?ext=description")), "Missing rel=canonical header!"); assertAll("Check LDP type link headers", checkLdpType(res, LDP.NonRDFSource)); }
assertTrue(APPLICATION_LD_JSON_TYPE.isCompatible(res.getMediaType()), "Incompatible content-type header!"); assertTrue(res.getMediaType().isCompatible(APPLICATION_LD_JSON_TYPE), "Incompatible content-type header!"); assertFalse(res.getLinks().stream().map(Link::getRel).anyMatch(isEqual("describes")), "Unexpected rel=describes"); assertFalse(res.getLinks().stream().map(Link::getRel).anyMatch(isEqual("describedby")), "Unexpected rel=describedby"); assertFalse(res.getLinks().stream().map(Link::getRel).anyMatch(isEqual("canonical")), "Unexpected rel=canonical"); assertNull(res.getHeaderString(PREFERENCE_APPLIED), "Unexpected Preference-Applied header!");