Search in sources :

Example 31 with Response

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

the class JAXRSClientIT method getLanguageTest.

/*
   * @testName: getLanguageTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:850;
   * 
   * @test_Strategy: Get the language of the message entity.
   */
@Test
public void getLanguageTest() throws Fault {
    Response response = Response.ok().language(Locale.CANADA_FRENCH).build();
    Locale locale = response.getLanguage();
    assertTrue(Locale.CANADA_FRENCH.equals(locale), "Locale" + Locale.CANADA_FRENCH + "does NOT match response#getLocale()" + locale);
    logMsg("#getLocale matches the Content-Language HTTP header");
}
Also used : Response(jakarta.ws.rs.core.Response) Locale(java.util.Locale) Test(org.junit.jupiter.api.Test)

Example 32 with Response

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

the class JAXRSClientIT method cacheControlTest.

/*
   * @testName: cacheControlTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:139; JAXRS:JAVADOC:141; JAXRS:JAVADOC:142;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.ResponseBuilder.cacheControl(String).build() verify that correct
   * status code is returned
   */
@Test
public void cacheControlTest() throws Fault {
    VerificationResult result;
    int status = 200;
    boolean nostore = true;
    CacheControl ccl4 = new CacheControl();
    ccl4.setNoStore(nostore);
    List<String> ccl = Arrays.asList("no-store", "no-transform");
    Response resp = Response.status(status).cacheControl(ccl4).build();
    result = verifyStatus(resp, status);
    result.append(verifyCacheControl(resp, ccl));
    logMsg(result);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) CacheControl(jakarta.ws.rs.core.CacheControl) Test(org.junit.jupiter.api.Test)

Example 33 with Response

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

the class JAXRSClientIT method temporaryRedirectTest.

/*
   * @testName: temporaryRedirectTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:140; JAXRS:JAVADOC:141; JAXRS:JAVADOC:123;
   * JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.temporaryRedirect(URI).build() verify that correct status code is
   * returned
   */
@Test
public void temporaryRedirectTest() throws Fault {
    VerificationResult result = new VerificationResult();
    URI test_uri = null;
    try {
        test_uri = new URI("http://java.sun.com/j2se/1.3/");
    } catch (URISyntaxException ex) {
        result.message.append("Unexpected exception thrown:").append(ex.getMessage());
        result.pass = false;
    }
    Response resp = Response.temporaryRedirect(test_uri).build();
    HashMap<String, String> expected_map = new HashMap<String, String>();
    expected_map.put("Location", "http://java.sun.com/j2se/1.3/");
    result.append(verifyStatus(resp, 307));
    result.append(verifyHeaders(resp, expected_map));
    logMsg(result);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) HashMap(java.util.HashMap) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 34 with Response

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

the class JAXRSClientIT method getHeaderStringUsingHeaderDelegateTest.

/*
   * @testName: getHeaderStringUsingHeaderDelegateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:849;
   * 
   * @test_Strategy: Get a message header as a single string value. Each single
   * header value is converted to String using a RuntimeDelegate.HeaderDelegate
   * or using its toString
   */
@Test
public void getHeaderStringUsingHeaderDelegateTest() throws Fault {
    StringBean bean = new StringBean("s3");
    RuntimeDelegate original = RuntimeDelegate.getInstance();
    RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(original));
    try {
        Response response = Response.ok().header(bean.get(), bean).build();
        String header = response.getHeaderString(bean.get());
        assertContainsIgnoreCase(header, bean.get(), "Header", bean.get(), "has unexpected value", header);
        logMsg("HeaderDelegate is used for header", bean.get());
    } finally {
        RuntimeDelegate.setInstance(original);
        StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Test(org.junit.jupiter.api.Test)

Example 35 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 = Response.ok().build();
    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)

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