Search in sources :

Example 16 with Status

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

the class JAXRSClientIT method constructorResponseThrowsExceptionTest.

/*
   * @testName: constructorResponseThrowsExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:320;
   * 
   * @test_Strategy: Construct a new internal server error exception.
   * java.lang.IllegalArgumentException - in case the status code set in the
   * response is not HTTP 500.
   */
@Test
public void constructorResponseThrowsExceptionTest() throws Fault {
    for (Status status : Status.values()) if (status != STATUS)
        try {
            Response response = Response.status(status).build();
            InternalServerErrorException e = new InternalServerErrorException(response);
            fault("No exception has been thrown for status", status, "; exception", e);
        } catch (IllegalArgumentException e) {
            logMsg("IllegalArgumentException has been thrown as expected for status", status);
        }
}
Also used : Status(jakarta.ws.rs.core.Response.Status) Response(jakarta.ws.rs.core.Response) InternalServerErrorException(jakarta.ws.rs.InternalServerErrorException) Test(org.junit.jupiter.api.Test)

Example 17 with Status

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

the class JAXRSClientIT method constructorStringResponseThrowableThrowsIEATest.

/*
   * @testName: constructorStringResponseThrowableThrowsIEATest
   * 
   * @assertion_ids: JAXRS:JAVADOC:1073;
   * 
   * @test_Strategy: Construct a new internal server error exception.
   * java.lang.IllegalArgumentException - in case the status code set in the
   * response is not HTTP 500.
   */
@Test
public void constructorStringResponseThrowableThrowsIEATest() throws Fault {
    for (Status status : Status.values()) if (status != STATUS)
        try {
            Response response = Response.status(status).build();
            InternalServerErrorException e = new InternalServerErrorException(MESSAGE, response, new Throwable());
            fault("No exception has been thrown for status", status, "exception", e);
        } catch (IllegalArgumentException e) {
            logMsg("IllegalArgumentException has been thrown as expected for status", status);
        }
}
Also used : Status(jakarta.ws.rs.core.Response.Status) Response(jakarta.ws.rs.core.Response) InternalServerErrorException(jakarta.ws.rs.InternalServerErrorException) Test(org.junit.jupiter.api.Test)

Example 18 with Status

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

the class ResponseTest method getStatusInfo.

@POST
@Path("statusinfo")
public Response getStatusInfo(String status) {
    Status stat = Status.valueOf(status);
    Response response = Response.status(stat).build();
    return response;
}
Also used : Status(jakarta.ws.rs.core.Response.Status) Response(jakarta.ws.rs.core.Response) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 19 with Status

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

the class JAXRSClientIT method constructorStringResponseThrowsIAETest.

/*
   * @testName: constructorStringResponseThrowsIAETest
   * 
   * @assertion_ids: JAXRS:JAVADOC:1075;
   * 
   * @test_Strategy: Construct a new "request not acceptable" exception.
   * java.lang.IllegalArgumentException - in case the status code set in the
   * response is not HTTP 406.
   */
@Test
public void constructorStringResponseThrowsIAETest() throws Fault {
    for (Status status : Status.values()) if (status != STATUS)
        try {
            Response response = Response.status(status).build();
            NotAcceptableException e = new NotAcceptableException(MESSAGE, response);
            fault("IllegalArgumentException has not been thrown; exception", e);
        } catch (IllegalArgumentException e) {
            logMsg("IllegalArgumentException has been thrown for status", status, "as expected");
        }
}
Also used : Status(jakarta.ws.rs.core.Response.Status) Response(jakarta.ws.rs.core.Response) NotAcceptableException(jakarta.ws.rs.NotAcceptableException) Test(org.junit.jupiter.api.Test)

Example 20 with Status

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

the class JAXRSClientIT method constructorResponseThrowsExceptionTest.

/*
   * @testName: constructorResponseThrowsExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:971;
   * 
   * @test_Strategy: Construct a new "forbidden" exception.
   * java.lang.IllegalArgumentException - in case the status code set in the
   * response is not HTTP 403.
   */
@Test
public void constructorResponseThrowsExceptionTest() throws Fault {
    for (Status status : Status.values()) if (status != STATUS)
        try {
            Response response = Response.status(status).build();
            ForbiddenException e = new ForbiddenException(response);
            fault("IllegalArgumentException has not been thrown; exception", e);
        } catch (IllegalArgumentException e) {
            logMsg("IllegalArgumentException has been thrown for status", status, "as expected");
        }
}
Also used : Status(jakarta.ws.rs.core.Response.Status) Response(jakarta.ws.rs.core.Response) ForbiddenException(jakarta.ws.rs.ForbiddenException) Test(org.junit.jupiter.api.Test)

Aggregations

Status (jakarta.ws.rs.core.Response.Status)68 Test (org.junit.jupiter.api.Test)58 Response (jakarta.ws.rs.core.Response)25 ClientErrorException (jakarta.ws.rs.ClientErrorException)12 ServerErrorException (jakarta.ws.rs.ServerErrorException)12 RedirectionException (jakarta.ws.rs.RedirectionException)10 Path (jakarta.ws.rs.Path)9 GET (jakarta.ws.rs.GET)6 WebApplicationException (jakarta.ws.rs.WebApplicationException)6 ReadableWritableEntity (ee.jakarta.tck.ws.rs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity)4 BadRequestException (jakarta.ws.rs.BadRequestException)4 InternalServerErrorException (jakarta.ws.rs.InternalServerErrorException)4 POST (jakarta.ws.rs.POST)3 IOException (java.io.IOException)3 Consumes (jakarta.ws.rs.Consumes)2 ForbiddenException (jakarta.ws.rs.ForbiddenException)2 NotAcceptableException (jakarta.ws.rs.NotAcceptableException)2 StatusType (jakarta.ws.rs.core.Response.StatusType)2 AnyExceptionExceptionMapper (ee.jakarta.tck.ws.rs.ee.rs.ext.exceptionmapper.AnyExceptionExceptionMapper)1 SyncInvoker (jakarta.ws.rs.client.SyncInvoker)1