Search in sources :

Example 6 with StatusType

use of jakarta.ws.rs.core.Response.StatusType in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method setStatusInfoTest.

/*
   * @testName: setStatusInfoTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:478; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Set the complete status information associated with the
   * response.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void setStatusInfoTest() throws Fault {
    ContextProvider in = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            StatusType info = new StatusType() {

                @Override
                public int getStatusCode() {
                    return Status.FOUND.getStatusCode();
                }

                @Override
                public String getReasonPhrase() {
                    return null;
                }

                @Override
                public Family getFamily() {
                    return null;
                }
            };
            responseContext.setStatusInfo(info);
        }
    };
    Response response = Response.ok().build();
    invokeWithResponseAndAssertStatus(response, Status.FOUND, in);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) Test(org.junit.jupiter.api.Test)

Example 7 with StatusType

use of jakarta.ws.rs.core.Response.StatusType in project jaxrs-api by eclipse-ee4j.

the class ResponseFilter method setStatusInfo.

public void setStatusInfo() {
    String entity = (String) responseContext.getEntity();
    final int status = Integer.parseInt(entity);
    StatusType type = new StatusType() {

        @Override
        public int getStatusCode() {
            return status;
        }

        @Override
        public String getReasonPhrase() {
            return null;
        }

        @Override
        public Family getFamily() {
            return Family.familyOf(status);
        }
    };
    responseContext.setStatusInfo(type);
    resetStatusEntity(status);
}
Also used : StatusType(jakarta.ws.rs.core.Response.StatusType)

Example 8 with StatusType

use of jakarta.ws.rs.core.Response.StatusType in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getStatusInfoTest.

/*
   * @testName: getStatusInfoTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:858;
   * 
   * @test_Strategy: Get the complete status information associated with the
   * response.
   */
@Test
public void getStatusInfoTest() throws Fault {
    for (Status status : Status.values()) {
        setProperty(Property.STATUS_CODE, getStatusCode(status));
        Response response = invokePost("statusinfo", status.name());
        StatusType info = response.getStatusInfo();
        assertEqualsInt(info.getStatusCode(), status.getStatusCode(), "#getStatusInfo returned unexpected value", info);
    }
    logMsg("#getStatusInfo returned expected StatusTypes");
}
Also used : Status(jakarta.ws.rs.core.Response.Status) Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) Test(org.junit.jupiter.api.Test)

Aggregations

StatusType (jakarta.ws.rs.core.Response.StatusType)8 Response (jakarta.ws.rs.core.Response)6 Test (org.junit.jupiter.api.Test)6 Status (jakarta.ws.rs.core.Response.Status)2 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 Family (jakarta.ws.rs.core.Response.Status.Family)1