Search in sources :

Example 1 with SUCCESSFUL

use of javax.ws.rs.core.Response.Status.Family.SUCCESSFUL in project trellis by trellis-ldp.

the class MementoTimeGateTests method testOriginalLinkHeader.

/**
 * Test the presence of a rel=original Link header.
 */
default void testOriginalLinkHeader() {
    try (final Response res = target(getResourceLocation()).request().get()) {
        assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response");
        assertTrue(getLinks(res).stream().anyMatch(l -> l.getRels().contains("original") && l.getUri().toString().equals(getResourceLocation())), "Check for a rel=original Link header");
    }
}
Also used : Response(javax.ws.rs.core.Response) Instant.from(java.time.Instant.from) Instant.now(java.time.Instant.now) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Instant(java.time.Instant) ACCEPT_DATETIME(org.trellisldp.common.HttpConstants.ACCEPT_DATETIME) MEMENTO_DATETIME(org.trellisldp.common.HttpConstants.MEMENTO_DATETIME) VARY(javax.ws.rs.core.HttpHeaders.VARY) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Executable(org.junit.jupiter.api.function.Executable) UTC(java.time.ZoneOffset.UTC) Assertions(org.junit.jupiter.api.Assertions) TestUtils.getLinks(org.trellisldp.test.TestUtils.getLinks) RFC_1123_DATE_TIME(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME) REDIRECTION(javax.ws.rs.core.Response.Status.Family.REDIRECTION)

Example 2 with SUCCESSFUL

use of javax.ws.rs.core.Response.Status.Family.SUCCESSFUL in project trellis by trellis-ldp.

the class MementoBinaryTests method testCanonicalHeaderDescriptions.

/**
 * Check the link headers on a binary description Memento.
 */
default void testCanonicalHeaderDescriptions() {
    getMementos().forEach((memento, date) -> {
        final String description = getDescription(memento);
        if (description == null) {
            fail("Could not find description link header!");
        }
        try (final Response res = target(description).request().accept("text/turtle").head()) {
            assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response");
            assertTrue(getLinks(res).stream().filter(link -> link.getRels().contains("canonical")).anyMatch(link -> link.getUri().toString().equals(memento + "&ext=description")), "Check for a rel=canonical Link header");
            assertTrue(getLinks(res).stream().filter(link -> link.getRels().contains("describes")).anyMatch(link -> link.getUri().toString().equals(memento)), "Check for a rel=describes Link header");
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) HashSet(java.util.HashSet) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Executable(org.junit.jupiter.api.function.Executable) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) TestUtils.getLinks(org.trellisldp.test.TestUtils.getLinks) Set(java.util.Set) TestUtils.readEntityAsString(org.trellisldp.test.TestUtils.readEntityAsString) HashMap(java.util.HashMap) LDP(org.trellisldp.vocabulary.LDP) TestUtils.readEntityAsString(org.trellisldp.test.TestUtils.readEntityAsString)

Example 3 with SUCCESSFUL

use of javax.ws.rs.core.Response.Status.Family.SUCCESSFUL in project trellis by trellis-ldp.

the class MementoBinaryTests method testCanonicalHeader.

/**
 * Check the link headers on a binary Memento.
 */
default void testCanonicalHeader() {
    getMementos().forEach((memento, date) -> {
        try (final Response res = target(memento).request().head()) {
            assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a valid response");
            assertTrue(getLinks(res).stream().filter(link -> link.getRels().contains("canonical")).anyMatch(link -> link.getUri().toString().equals(memento)), "Check for a rel=canonical Link header");
            assertTrue(getLinks(res).stream().filter(link -> link.getRels().contains("describedby")).anyMatch(link -> link.getUri().toString().equals(memento + "&ext=description")), "Check for a rel=describedby Link header");
        }
    });
}
Also used : Response(javax.ws.rs.core.Response) HashSet(java.util.HashSet) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Executable(org.junit.jupiter.api.function.Executable) Map(java.util.Map) Assertions(org.junit.jupiter.api.Assertions) TestUtils.getLinks(org.trellisldp.test.TestUtils.getLinks) Set(java.util.Set) TestUtils.readEntityAsString(org.trellisldp.test.TestUtils.readEntityAsString) HashMap(java.util.HashMap) LDP(org.trellisldp.vocabulary.LDP)

Example 4 with SUCCESSFUL

use of javax.ws.rs.core.Response.Status.Family.SUCCESSFUL in project trellis by trellis-ldp.

the class MementoTimeGateTests method testTimeGateLinkHeader.

/**
 * Test the presence of a rel=timegate Link header.
 */
default void testTimeGateLinkHeader() {
    try (final Response res = target(getResourceLocation()).request().get()) {
        assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful response");
        assertTrue(getLinks(res).stream().anyMatch(l -> l.getRels().contains("timegate") && l.getUri().toString().equals(getResourceLocation())), "Check for a rel=timegate Link header");
    }
}
Also used : Response(javax.ws.rs.core.Response) Instant.from(java.time.Instant.from) Instant.now(java.time.Instant.now) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Instant(java.time.Instant) ACCEPT_DATETIME(org.trellisldp.common.HttpConstants.ACCEPT_DATETIME) MEMENTO_DATETIME(org.trellisldp.common.HttpConstants.MEMENTO_DATETIME) VARY(javax.ws.rs.core.HttpHeaders.VARY) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) Executable(org.junit.jupiter.api.function.Executable) UTC(java.time.ZoneOffset.UTC) Assertions(org.junit.jupiter.api.Assertions) TestUtils.getLinks(org.trellisldp.test.TestUtils.getLinks) RFC_1123_DATE_TIME(java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME) REDIRECTION(javax.ws.rs.core.Response.Status.Family.REDIRECTION)

Example 5 with SUCCESSFUL

use of javax.ws.rs.core.Response.Status.Family.SUCCESSFUL in project trellis by trellis-ldp.

the class MementoTimeMapTests method testTimeMapLinkHeader.

/**
 * Test the presence of a rel=timemap Link header.
 */
default void testTimeMapLinkHeader() {
    try (final Response res = target(getResourceLocation()).request().get()) {
        assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful timemap response");
        assertTrue(getLinks(res).stream().anyMatch(l -> l.getRels().contains("timemap") && l.getUri().toString().equals(getResourceLocation() + TIMEMAP_QUERY_ARG)), "Check for a rel=timemap Link header");
    }
}
Also used : Response(javax.ws.rs.core.Response) APPLICATION_LD_JSON_TYPE(org.trellisldp.common.RdfMediaType.APPLICATION_LD_JSON_TYPE) RDFFactory(org.trellisldp.api.RDFFactory) TEXT_TURTLE_TYPE(org.trellisldp.common.RdfMediaType.TEXT_TURTLE_TYPE) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) APPLICATION_LINK_FORMAT(org.trellisldp.common.HttpConstants.APPLICATION_LINK_FORMAT) APPLICATION_N_TRIPLES_TYPE(org.trellisldp.common.RdfMediaType.APPLICATION_N_TRIPLES_TYPE) RDF(org.apache.commons.rdf.api.RDF) MediaType(javax.ws.rs.core.MediaType) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) TURTLE(org.apache.commons.rdf.api.RDFSyntax.TURTLE) Executable(org.junit.jupiter.api.function.Executable) Assertions(org.junit.jupiter.api.Assertions) TestUtils.getLinks(org.trellisldp.test.TestUtils.getLinks) NTRIPLES(org.apache.commons.rdf.api.RDFSyntax.NTRIPLES) TestUtils.readEntityAsGraph(org.trellisldp.test.TestUtils.readEntityAsGraph) LDP(org.trellisldp.vocabulary.LDP) JSONLD(org.apache.commons.rdf.api.RDFSyntax.JSONLD)

Aggregations

SUCCESSFUL (javax.ws.rs.core.Response.Status.Family.SUCCESSFUL)7 Stream (java.util.stream.Stream)6 Response (javax.ws.rs.core.Response)6 Assertions (org.junit.jupiter.api.Assertions)6 Executable (org.junit.jupiter.api.function.Executable)6 TestUtils.getLinks (org.trellisldp.test.TestUtils.getLinks)6 LDP (org.trellisldp.vocabulary.LDP)4 Map (java.util.Map)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 MediaType (javax.ws.rs.core.MediaType)2 RDF (org.apache.commons.rdf.api.RDF)2 JSONLD (org.apache.commons.rdf.api.RDFSyntax.JSONLD)2 NTRIPLES (org.apache.commons.rdf.api.RDFSyntax.NTRIPLES)2 TURTLE (org.apache.commons.rdf.api.RDFSyntax.TURTLE)2 RDFFactory (org.trellisldp.api.RDFFactory)2 APPLICATION_LINK_FORMAT (org.trellisldp.common.HttpConstants.APPLICATION_LINK_FORMAT)2 APPLICATION_LD_JSON_TYPE (org.trellisldp.common.RdfMediaType.APPLICATION_LD_JSON_TYPE)2 APPLICATION_N_TRIPLES_TYPE (org.trellisldp.common.RdfMediaType.APPLICATION_N_TRIPLES_TYPE)2