Search in sources :

Example 1 with StatusType

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

the class JAXRSClientIT method getFamilyTest.

/* Run test */
/*
   * @testName: getFamilyTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:302;
   * 
   * @test_Strategy: Get the class of status code
   */
@Test
public void getFamilyTest() throws Fault {
    Response response;
    for (int i = 0; i != status_codes.length; i++) {
        response = Response.status(status_codes[i]).build();
        StatusType type = response.getStatusInfo();
        Family family = type.getFamily();
        assertTrue(family == status_family[i], "unexpected family " + family + " differs from " + status_family[i]);
        logMsg("Found expected family", family, "for status", status_codes[i]);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) Family(jakarta.ws.rs.core.Response.Status.Family) Test(org.junit.jupiter.api.Test)

Example 2 with StatusType

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

the class ResponseFilter method getStatusInfo.

public void getStatusInfo() {
    StatusType type = responseContext.getStatusInfo();
    if (type == null) {
        setEntity(NULL);
        responseContext.setStatus(Status.OK.getStatusCode());
        return;
    }
    int status = type.getStatusCode();
    responseContext.setStatus(Status.OK.getStatusCode());
    setEntity(String.valueOf(status));
}
Also used : StatusType(jakarta.ws.rs.core.Response.StatusType)

Example 3 with StatusType

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

the class JAXRSClientIT method getStatusCodeTest.

/*
   * @testName: getStatusCodeTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:304;
   * 
   * @test_Strategy: Get the associated status code.
   */
@Test
public void getStatusCodeTest() throws Fault {
    Response response;
    for (int i = 0; i != status_codes.length; i++) {
        response = Response.status(status_codes[i]).build();
        StatusType type = response.getStatusInfo();
        int code = type.getStatusCode();
        assertTrue(code == status_codes[i], "unexpected status code " + code + " differs from " + status_codes[i]);
        logMsg("Found expected status code", code, "for status", status_codes[i]);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) Test(org.junit.jupiter.api.Test)

Example 4 with StatusType

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

the class JAXRSClientIT method getReasonPhraseTest.

/*
   * @testName: getReasonPhraseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:303;
   * 
   * @test_Strategy: Get the reason phrase
   */
@Test
public void getReasonPhraseTest() throws Fault {
    Response response;
    for (int i = 0; i != status_codes.length; i++) {
        response = Response.status(status_codes[i]).build();
        StatusType type = response.getStatusInfo();
        String phrase = type.getReasonPhrase();
        assertTrue(phrase.equals(status[i]), "unexpected phrase " + phrase + " differs from " + status[i]);
        logMsg("Found expected phrase", phrase, "for status", status_codes[i]);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) Test(org.junit.jupiter.api.Test)

Example 5 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()) {
        Response response = Response.status(status).build();
        StatusType info = response.getStatusInfo();
        assertTrue(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