use of javax.ws.rs.core.MediaType.WILDCARD_TYPE in project trellis by trellis-ldp.
the class TrellisHttpResourceTest method testNoBaseURL.
@Test
void testNoBaseURL() throws Exception {
final TrellisHttpResource matcher = new TrellisHttpResource();
matcher.baseUrl = Optional.empty();
matcher.services = mockBundler;
matcher.request = mockRequest;
matcher.uriInfo = mockUriInfo;
matcher.headers = mockHttpHeaders;
when(mockUriInfo.getPathParameters()).thenReturn(new MultivaluedHashMap<>(singletonMap("path", "resource")));
when(mockUriInfo.getPath()).thenReturn("resource");
when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://my.example.com/"));
when(mockUriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap<>());
when(mockHttpHeaders.getRequestHeaders()).thenReturn(new MultivaluedHashMap<>());
when(mockTrellisRequest.getAcceptableMediaTypes()).thenReturn(singletonList(WILDCARD_TYPE));
try (final Response res = matcher.getResourceHeaders().toCompletableFuture().join()) {
assertTrue(getLinks(res).stream().anyMatch(l -> l.getRel().equals("self") && l.getUri().toString().startsWith("http://my.example.com/")), "Missing rel=self header with correct prefix!");
}
}
use of javax.ws.rs.core.MediaType.WILDCARD_TYPE in project trellis by trellis-ldp.
the class GetHandlerTest method testGetBinary.
@Test
void testGetBinary() {
when(mockResource.getBinaryMetadata()).thenReturn(of(testBinary));
when(mockResource.getInteractionModel()).thenReturn(LDP.NonRDFSource);
when(mockTrellisRequest.getAcceptableMediaTypes()).thenReturn(singletonList(WILDCARD_TYPE));
final GetConfiguration config = new GetConfiguration(false, true, true, null, baseUrl);
final GetHandler handler = new GetHandler(mockTrellisRequest, mockBundler, extensions, config);
try (final Response res = handler.getRepresentation(handler.standardHeaders(handler.initialize(mockResource))).toCompletableFuture().join().build()) {
assertEquals(OK, res.getStatusInfo(), ERR_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_LINK_TYPES, checkLdpType(res, LDP.NonRDFSource));
}
}
Aggregations