Search in sources :

Example 96 with Response

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

the class JAXRSClientIT method getLengthTest.

/*
   * @testName: getLengthTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:852;
   * 
   * @test_Strategy: Get Content-Length value.
   */
@Test
public void getLengthTest() throws Fault {
    Response response = invokePost("length", "1234567890");
    int len = response.getLength();
    assertTrue(len > 9, "Expected Content-Length > 9" + "does NOT match response#getLength()" + len);
    logMsg("#getLength matches expected Content-Length", len);
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Example 97 with Response

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

the class JAXRSClientIT method getLinksIsNotNullTest.

/*
   * @testName: getLinksIsNotNullTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:855;
   * 
   * @test_Strategy: Does not return null.
   */
@Test
public void getLinksIsNotNullTest() throws Fault {
    Response response = invokeGet("entity");
    Set<Link> responseLinks = response.getLinks();
    assertTrue(responseLinks != null, "#getLinks() returned null!");
    assertTrue(responseLinks.size() == 0, "#getLinks() returned non-empty map!");
    logMsg("#getLinks contains no links as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 98 with Response

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

the class JAXRSClientIT method getDateTest.

/*
   * @testName: getDateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:845;
   * 
   * @test_Strategy: Get message date.
   */
@Test
public void getDateTest() throws Fault {
    long date = getCurrentTimeMillis();
    Response response = invokePost("date", String.valueOf(date));
    long responseDate = response.getDate().getTime();
    // assertEqualsLong(date, responseDate, "Original date", date,
    // "and response#getDate()", responseDate, "differs");
    // int TC, the Date settings is overriden by underlaying containers
    // But getDate is to be tested, not setDate, hence
    assertTrue(Math.abs(responseDate - date) < (10 * 60 * 1000), "#getDate() returned time that differes by more than 10 minutes");
    logMsg("#getDate matches the Date HTTP header");
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Example 99 with Response

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

the class JAXRSClientIT method readEntityGenericTypeAnnotationCloseIsNotCalledOnInputStreamTest.

/*
   * @testName: readEntityGenericTypeAnnotationCloseIsNotCalledOnInputStreamTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:872;
   * 
   * @test_Strategy: Unless the supplied entity type is an input stream, this
   * method automatically closes the consumed response entity stream if it is
   * not buffered.
   */
@Test
public void readEntityGenericTypeAnnotationCloseIsNotCalledOnInputStreamTest() throws Fault {
    Annotation[] annotations = AnnotatedClass.class.getAnnotations();
    AtomicInteger ai = setCorruptedStream();
    Response response = invokeGet("corrupted");
    try {
        response.readEntity(generic(InputStream.class), annotations);
    } catch (ProcessingException e) {
        fault("Close was called", e);
    }
    assertEqualsInt(ai.get(), 0, "Close was called");
    logMsg("Close() has not been called on entity stream as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InputStream(java.io.InputStream) Annotation(java.lang.annotation.Annotation) ProcessingException(jakarta.ws.rs.ProcessingException) Test(org.junit.jupiter.api.Test)

Example 100 with Response

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

the class JAXRSClientIT method readEntityGenericTypeThrowsIllegalStateExceptionTest.

/*
   * @testName: readEntityGenericTypeThrowsIllegalStateExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:866;
   * 
   * @test_Strategy: if the entity is not backed by an input stream, or if the
   * entity input stream has been fully consumed already and has not been
   * buffered prior consuming.
   */
@Test
public void readEntityGenericTypeThrowsIllegalStateExceptionTest() throws Fault {
    // create a new client
    Client client = ClientBuilder.newClient();
    WebTarget target = // with no bufferEntity called
    client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
    Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
    String entity = response.readEntity(generic(String.class));
    assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(GenericType<byte[]>)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
    try {
        response.readEntity(generic(Reader.class));
        throw new Fault("No exception has been thrown when reader for entity is not buffered");
    } catch (IllegalStateException e) {
        logMsg("IllegalStateException has been thrown as expected");
    }
}
Also used : Response(jakarta.ws.rs.core.Response) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) WebTarget(jakarta.ws.rs.client.WebTarget) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)665 Test (org.junit.jupiter.api.Test)551 AsyncInvoker (jakarta.ws.rs.client.AsyncInvoker)78 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)71 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)67 Invocation (jakarta.ws.rs.client.Invocation)65 CompletionStageRxInvoker (jakarta.ws.rs.client.CompletionStageRxInvoker)51 Path (jakarta.ws.rs.Path)44 IOException (java.io.IOException)43 SyncInvoker (jakarta.ws.rs.client.SyncInvoker)41 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)33 POST (jakarta.ws.rs.POST)27 Client (jakarta.ws.rs.client.Client)25 WebTarget (jakarta.ws.rs.client.WebTarget)24 Link (jakarta.ws.rs.core.Link)23 Status (jakarta.ws.rs.core.Response.Status)23 MediaType (jakarta.ws.rs.core.MediaType)22 Annotation (java.lang.annotation.Annotation)22 Date (java.util.Date)21 GET (jakarta.ws.rs.GET)18