Search in sources :

Example 41 with NewCookie

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

the class JAXRSClientIT method constructorTest22.

/*
   * @testName: constructorTest22
   * 
   * @assertion_ids: JAXRS:JAVADOC:108; JAXRS:JAVADOC:100; JAXRS:JAVADOC:101;
   * JAXRS:JAVADOC:103; JAXRS:JAVADOC:49; JAXRS:JAVADOC:53; JAXRS:JAVADOC:54;
   * JAXRS:JAVADOC:55; JAXRS:JAVADOC:56;
   * 
   * @test_Strategy: Create a version 1 NewCookie instance using constructor
   * Cookie(String, String, String, String, int) NewCookie(Cookie, String
   * comment, int maxAge, boolean secure)
   */
@Test
public void constructorTest22() throws Fault {
    String name = "name_1";
    String value = "value_1";
    String path = "/acme";
    String domain = "y.x.foo.com";
    int version = 1;
    String comment = "cts test comment";
    int maxage = jakarta.ws.rs.core.NewCookie.DEFAULT_MAX_AGE;
    boolean secure = false;
    Cookie ck22 = new Cookie(name, value, path, domain, version);
    NewCookie nck22 = new NewCookie(ck22, comment, maxage, secure);
    verifyNewCookie(nck22, name, value, path, domain, version, comment, maxage, secure);
}
Also used : Cookie(jakarta.ws.rs.core.Cookie) NewCookie(jakarta.ws.rs.core.NewCookie) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 42 with NewCookie

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

the class JAXRSClientIT method getCookiesIsImmutableTest.

/*
   * @testName: getCookiesIsImmutableTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:844;
   * 
   * @test_Strategy: returns a read-only map of cookie name (String) to Cookie.
   */
@Test
public void getCookiesIsImmutableTest() throws Fault {
    NewCookie cookie1 = new NewCookie("c1", "v1");
    NewCookie cookie2 = new NewCookie("c2", "v2");
    Response response = Response.ok().cookie(cookie1).build();
    // getCookies test
    Map<String, NewCookie> map;
    try {
        map = response.getCookies();
        map.put("c2", cookie2);
    } catch (Exception e) {
    // can throw an exception or nothing or return a copy map
    }
    map = response.getCookies();
    assertTrue(!map.containsKey("c2"), "getCookies is not read-only returned" + map.get("c2"));
    logMsg("#getCookies is read-only as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) URISyntaxException(java.net.URISyntaxException) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 43 with NewCookie

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

the class ResponseFilter method getCookiesIsReadOnly.

public void getCookiesIsReadOnly() {
    NewCookie cookie = new NewCookie(COOKIENAME, COOKIENAME);
    Map<String, NewCookie> cookies = responseContext.getCookies();
    if (assertTrue(!cookies.containsKey(COOKIENAME), COOKIENAME, "is already present"))
        return;
    try {
        cookies.put(COOKIENAME, cookie);
    } catch (Exception e) {
    // Not mandatory, but possible as cookies is read-only
    }
    cookies = responseContext.getCookies();
    if (assertTrue(!cookies.containsKey(COOKIENAME), "#getCookies is Not readOnly"))
        return;
    setEntity("getCookies is read-only as expected");
}
Also used : IOException(java.io.IOException) NewCookie(jakarta.ws.rs.core.NewCookie)

Example 44 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:844;
   * 
   * @test_Strategy: Get any new cookies set on the response message.
   */
@Test
public void getCookiesTest() throws Fault {
    Response response = invokeGet("cookies");
    // getCookies test
    Map<String, NewCookie> map = response.getCookies();
    for (Entry<String, NewCookie> entry : map.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue().getValue();
        if (key.equals("c1"))
            assertEquals(value, "v1", value, "does not match expected v1");
        else if (key.equals("c2"))
            assertEquals(value, "v2", value, "does not match expected v2");
        else
            fault("Got unknown cookie", entry.getKey());
    }
    logMsg("#getCookies returned expected cookies");
}
Also used : Response(jakarta.ws.rs.core.Response) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 45 with NewCookie

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

the class JAXRSClientIT method getCookiesIsImmutableTest.

/*
   * @testName: getCookiesIsImmutableTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:844;
   * 
   * @test_Strategy: returns a read-only map of cookie name (String) to Cookie.
   */
@Test
public void getCookiesIsImmutableTest() throws Fault {
    NewCookie cookie3 = new NewCookie("c3", "v3");
    Response response = invokeGet("cookies");
    // getCookies test
    Map<String, NewCookie> map;
    try {
        map = response.getCookies();
        map.put("c3", cookie3);
    } catch (Exception e) {
    // can throw an exception or nothing or return a copy map
    }
    map = response.getCookies();
    assertFalse(map.containsKey("c3"), "getCookies is not read-only returned" + map.get("c3"));
    logMsg("#getCookies is read-only as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) ProcessingException(jakarta.ws.rs.ProcessingException) IOException(java.io.IOException) 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