Search in sources :

Example 6 with SUCCESSFUL

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

the class MementoTimeMapTests method testTimeMapResponseHasTimeMapLink.

/**
 * Test the timemap response for a rel=timemap.
 */
default void testTimeMapResponseHasTimeMapLink() {
    try (final Response res = target(getResourceLocation() + TIMEMAP_QUERY_ARG).request().get()) {
        assertEquals(SUCCESSFUL, res.getStatusInfo().getFamily(), "Check for a successful 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)

Example 7 with SUCCESSFUL

use of javax.ws.rs.core.Response.Status.Family.SUCCESSFUL in project notifications-backend by RedHatInsights.

the class CrudTestHelpers method getAccessList.

public static Optional<List<InternalApplicationUserPermission>> getAccessList(Header identity, int expected) {
    String responseBody = given().header(identity).when().get("internal/access").then().statusCode(expected).extract().asString();
    if (familyOf(expected) == SUCCESSFUL) {
        JsonArray json = new JsonArray(responseBody);
        List<InternalApplicationUserPermission> accessList = json.stream().map(o -> {
            JsonObject jsonObject = (JsonObject) o;
            assertNotNull(jsonObject.getString("application_id"));
            assertNotNull(jsonObject.getString("application_display_name"));
            assertNotNull(jsonObject.getString("role"));
            return jsonObject.mapTo(InternalApplicationUserPermission.class);
        }).collect(Collectors.toList());
        return Optional.of(accessList);
    }
    return Optional.empty();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ValidatableResponse(io.restassured.response.ValidatableResponse) AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) SUCCESSFUL(javax.ws.rs.core.Response.Status.Family.SUCCESSFUL) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Header(io.restassured.http.Header) API_INTERNAL(com.redhat.cloud.notifications.Constants.API_INTERNAL) EventType(com.redhat.cloud.notifications.models.EventType) Template(com.redhat.cloud.notifications.models.Template) BehaviorGroup(com.redhat.cloud.notifications.models.BehaviorGroup) RequestSpecification(io.restassured.specification.RequestSpecification) Map(java.util.Map) InstantEmailTemplate(com.redhat.cloud.notifications.models.InstantEmailTemplate) JsonObject(io.vertx.core.json.JsonObject) InternalRoleAccess(com.redhat.cloud.notifications.models.InternalRoleAccess) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nullable(javax.annotation.Nullable) Application(com.redhat.cloud.notifications.models.Application) JSON(io.restassured.http.ContentType.JSON) TEXT(io.restassured.http.ContentType.TEXT) OK(org.jboss.resteasy.reactive.RestResponse.StatusCode.OK) AddApplicationRequest(com.redhat.cloud.notifications.routers.internal.models.AddApplicationRequest) Family.familyOf(javax.ws.rs.core.Response.Status.Family.familyOf) Bundle(com.redhat.cloud.notifications.models.Bundle) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AddAccessRequest(com.redhat.cloud.notifications.routers.internal.models.AddAccessRequest) Matchers.any(org.hamcrest.Matchers.any) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Optional(java.util.Optional) RestAssured.given(io.restassured.RestAssured.given) Matchers.is(org.hamcrest.Matchers.is) InternalApplicationUserPermission(com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission) Matchers.containsString(org.hamcrest.Matchers.containsString) InternalApplicationUserPermission(com.redhat.cloud.notifications.routers.internal.models.InternalApplicationUserPermission) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString)

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