Search in sources :

Example 1 with NewCookie

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

the class JAXRSClientIT method getCookiesTest.

/*
   * @testName: getCookiesTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:458; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
   * 
   * @test_Strategy: Get any new cookies set on the response message.
   * 
   * ClientResponseFilter.filter
   */
@Test
public void getCookiesTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
            Map<String, NewCookie> map = responseContext.getCookies();
            assertTrue(map.size() == 2, "Cookies were not set");
        }
    };
    NewCookie cookie1 = new NewCookie("cookie1", "cookie1");
    NewCookie cookie2 = new NewCookie("cookie2", "cookie2");
    Response response = Response.ok().cookie(cookie1).cookie(cookie2).build();
    invokeWithResponseAndAssertStatus(response, Status.OK, provider);
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 2 with NewCookie

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

the class JAXRSClientIT method getHeaderStringTest.

/*
   * @testName: getHeaderStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:849;
   * 
   * @test_Strategy: Get a message header as a single string value.
   */
@Test
public void getHeaderStringTest() throws Fault {
    CacheControl ccl = new CacheControl();
    ccl.setNoStore(true);
    NewCookie cookie = new NewCookie("cookie", "eikooc");
    String encoding = "gzip";
    Date date = Calendar.getInstance().getTime();
    Response response = Response.ok().cacheControl(ccl).cookie(cookie).encoding(encoding).expires(date).language(Locale.CANADA_FRENCH).build();
    logMsg("Found following objects:");
    logMsg((Object[]) JaxrsCommonClient.getMetadata(response.getHeaders()));
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.CACHE_CONTROL), "no-store", "Cache-Control:no-store has not been found");
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.CACHE_CONTROL), "no-transform", "Cache-Control:no-transform has not been found");
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.SET_COOKIE), "cookie=eikooc", "Set-Cookie:cookie=eikooc has not been found");
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.CONTENT_ENCODING), "gzip", "Content-Encoding:gzip has not been found");
    assertNotNull(response.getHeaderString(HttpHeaders.EXPIRES), "Expires has not been found");
    assertContainsIgnoreCase(langToString(response.getHeaderString("Content-Language")), langToString(Locale.CANADA_FRENCH), "Content-Language:", langToString(Locale.CANADA_FRENCH), "has not been found");
    assertNull(response.getHeaderString("unknown"), "Unknown header has been found", response.getHeaderString("unknown"));
}
Also used : Response(jakarta.ws.rs.core.Response) CacheControl(jakarta.ws.rs.core.CacheControl) Date(java.util.Date) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 3 with NewCookie

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

the class ResponseTest method getCookies.

@GET
@Path("cookies")
public Response getCookies() {
    NewCookie cookie1 = new NewCookie("c1", "v1");
    NewCookie cookie2 = new NewCookie("c2", "v2");
    Response response = Response.ok().cookie(cookie1).cookie(cookie2).build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) NewCookie(jakarta.ws.rs.core.NewCookie) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 4 with NewCookie

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

the class CookieParamTest method setNewCookie.

private static void setNewCookie(ResponseBuilder rb, String queryParam) {
    if (!queryParam.contains("="))
        return;
    String[] split = queryParam.split("=");
    Cookie cookie = new Cookie(split[0], split[1]);
    NewCookie newCookie = new NewCookie(cookie);
    rb.cookie(newCookie);
}
Also used : NewCookie(jakarta.ws.rs.core.NewCookie) Cookie(jakarta.ws.rs.core.Cookie) ParamEntityWithFromString(ee.jakarta.tck.ws.rs.ee.rs.ParamEntityWithFromString) NewCookie(jakarta.ws.rs.core.NewCookie)

Example 5 with NewCookie

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

the class JAXRSClientIT method cookieTest.

/*
   * @testName: cookieTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:139; JAXRS:JAVADOC:141; JAXRS:JAVADOC:145;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.ResponseBuilder.cookie(NewCookie).build() verify that correct
   * status code is returned
   */
@Test
public void cookieTest() throws Fault {
    VerificationResult result;
    int status = 200;
    String name = "name_1";
    String value = "value_1";
    // int maxage = jakarta.ws.rs.core.NewCookie.DEFAULT_MAX_AGE;
    Cookie ck1 = new Cookie(name, value);
    NewCookie nck1 = new NewCookie(ck1);
    name = "name_2";
    value = "value_2";
    String path = "/acme";
    String domain = "";
    Cookie ck2 = new Cookie(name, value, path, domain);
    NewCookie nck2 = new NewCookie(ck2);
    name = "name_3";
    value = "value_3";
    path = "";
    domain = "y.x.foo.com";
    Cookie ck3 = new Cookie(name, value, path, domain);
    NewCookie nck3 = new NewCookie(ck3);
    List<String> cookies = Arrays.asList(nck1.toString().toLowerCase(), nck2.toString().toLowerCase(), nck3.toString().toLowerCase());
    Response resp = Response.status(status).cookie(nck1, nck2, nck3).build();
    result = verifyStatus(resp, status);
    result.append(verifyCookies(resp, cookies));
    logMsg(result);
    assertResultTrue(result);
}
Also used : Cookie(jakarta.ws.rs.core.Cookie) NewCookie(jakarta.ws.rs.core.NewCookie) Response(jakarta.ws.rs.core.Response) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Aggregations

NewCookie (jakarta.ws.rs.core.NewCookie)48 Test (org.junit.jupiter.api.Test)41 Cookie (jakarta.ws.rs.core.Cookie)20 Response (jakarta.ws.rs.core.Response)13 Path (jakarta.ws.rs.Path)4 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)4 GET (jakarta.ws.rs.GET)3 CacheControl (jakarta.ws.rs.core.CacheControl)3 Date (java.util.Date)3 ParamEntityWithFromString (ee.jakarta.tck.ws.rs.ee.rs.ParamEntityWithFromString)2 POST (jakarta.ws.rs.POST)2 IOException (java.io.IOException)2 Consumes (jakarta.ws.rs.Consumes)1 ProcessingException (jakarta.ws.rs.ProcessingException)1 Produces (jakarta.ws.rs.Produces)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 URISyntaxException (java.net.URISyntaxException)1