Search in sources :

Example 41 with ResponseBuilder

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

the class JAXRSClientIT method ioExceptionTest.

/*
   * @testName: ioExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:921; JAXRS:JAVADOC:920; JAXRS:SPEC:85;
   * 
   * @test_Strategy: Throws IOException - if an IO error arises.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void ioExceptionTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.IOEXCEPTION);
    Response fake = builder.build();
    addProviders(fake);
    invoke();
    try {
        getResponseBody();
    } catch (Exception e) {
        assertNotNull(e.getMessage(), "Returned unexpected exception", e);
        IOException io = assertCause(e, IOException.class, "Unexpected exception has been found:", e);
        assertContains(io.getMessage(), TemplateInterceptorBody.IOE, "Found unexpected message from IOException", e.getMessage());
        logMsg("found expected IOException", io);
        return;
    }
    fault("Expected IOException not found");
}
Also used : Response(jakarta.ws.rs.core.Response) IOException(java.io.IOException) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) IOException(java.io.IOException) WebApplicationException(jakarta.ws.rs.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 42 with ResponseBuilder

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

the class JAXRSClientIT method getPropertyIsNullTest.

/*
   * @testName: getPropertyIsNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:906; JAXRS:JAVADOC:920; JAXRS:SPEC:85;
   * 
   * @test_Strategy: Returns null if there is no property by that name.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void getPropertyIsNullTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.GETPROPERTY);
    Response fake = builder.build();
    addProviders(fake);
    setProperty(Property.SEARCH_STRING, TemplateInterceptorBody.NULL);
    invoke();
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 43 with ResponseBuilder

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

the class JAXRSClientIT method webApplicationExceptionTest.

/*
   * @testName: webApplicationExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:922; JAXRS:JAVADOC:920; JAXRS:SPEC:85;
   * 
   * @test_Strategy: throws WebApplicationException thrown by wrapped method.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void webApplicationExceptionTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.WEBAPPLICATIONEXCEPTION);
    Response fake = builder.build();
    addProviders(fake);
    invoke();
    try {
        getResponseBody();
    } catch (Exception e) {
        WebApplicationException we = assertCause(e, WebApplicationException.class, "Found unexpected exception", e);
        assertNotNull(we.getResponse(), "WebApplicationException.getResponse is null");
        Response response = we.getResponse();
        String entity = response.getEntity().toString();
        assertEqualsInt(Status.CONFLICT.getStatusCode(), response.getStatus(), "Unexcpected status returned from WebApplicationException.getResponse", response.getStatus());
        assertEquals(TemplateInterceptorBody.ENTITY2, entity, "Found unexpected body content from WebApplicationException.getResponse", entity);
        logMsg("found expected WebApplicationException", we);
        return;
    }
    fault("Expected WebApplicationException not found");
}
Also used : Response(jakarta.ws.rs.core.Response) WebApplicationException(jakarta.ws.rs.WebApplicationException) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) IOException(java.io.IOException) WebApplicationException(jakarta.ws.rs.WebApplicationException) Test(org.junit.jupiter.api.Test)

Example 44 with ResponseBuilder

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

the class JAXRSClientIT method setPropertyNullTest.

/*
   * @testName: setPropertyNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:913; JAXRS:JAVADOC:920; JAXRS:SPEC:85;
   * 
   * @test_Strategy: If a null value is passed, the effect is the same as
   * calling the removeProperty(String) method.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void setPropertyNullTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.SETPROPERTYNULL);
    Response fake = builder.build();
    addProviders(fake);
    setProperty(Property.SEARCH_STRING, TemplateInterceptorBody.NULL);
    invoke();
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 45 with ResponseBuilder

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

the class JAXRSClientIT method getAnnotationsTest.

/*
   * @testName: getAnnotationsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:903; JAXRS:JAVADOC:920; JAXRS:SPEC:85;
   * 
   * @test_Strategy: Get an array of the annotations formally declared on the
   * artifact that initiated the intercepted entity provider invocation. The
   * annotations are not on client reader.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void getAnnotationsTest() throws Fault {
    Annotation[] annotations = ContextOperation.class.getAnnotations();
    ResponseBuilder builder = createResponse(ContextOperation.GETANNOTATIONS);
    Response fake = builder.entity(TemplateInterceptorBody.ENTITY, annotations).build();
    addProviders(fake);
    for (Annotation a : annotations) setProperty(Property.UNEXPECTED_RESPONSE_MATCH, a.annotationType().getName());
    invoke();
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)80 Response (jakarta.ws.rs.core.Response)69 Path (jakarta.ws.rs.Path)41 Test (org.junit.jupiter.api.Test)34 POST (jakarta.ws.rs.POST)27 GET (jakarta.ws.rs.GET)14 Date (java.util.Date)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Annotation (java.lang.annotation.Annotation)4 VerificationResult (ee.jakarta.tck.ws.rs.api.rs.core.responseclient.VerificationResult)3 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)3 NewCookie (jakarta.ws.rs.core.NewCookie)3 RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)3 IOException (java.io.IOException)3 StringBeanWithAnnotation (ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation)2 Produces (jakarta.ws.rs.Produces)2 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 EntityTag (jakarta.ws.rs.core.EntityTag)2 Link (jakarta.ws.rs.core.Link)2 InputStreamReader (java.io.InputStreamReader)2