Search in sources :

Example 21 with NewCookie

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

the class JAXRSClientIT method toStringTest.

/*
   * @testName: toStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:110; JAXRS:JAVADOC:52; JAXRS:JAVADOC:58;
   * 
   * @test_Strategy: Create a NewCookie instance NewCokie(String name, String
   * value, String path, String domain, int version, String comment, int maxAge,
   * boolean secure) Verify that toString method works.
   */
@Test
public void toStringTest() throws Fault {
    boolean pass = true;
    StringBuffer sb = new StringBuffer();
    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 = 12345;
    boolean secure = false;
    List<String> tobeVerified = Arrays.asList(name, value, path, domain, Integer.valueOf(version).toString(), comment, Integer.valueOf(maxage).toString(), secure ? Boolean.valueOf(secure).toString() : null);
    NewCookie nck31 = new NewCookie(name, value, path, domain, version, comment, maxage, secure);
    String nk_String = nck31.toString();
    for (String nk_part : tobeVerified) {
        if (nk_part != null) {
            if (!nk_String.contains(nk_part)) {
                sb.append("Test failed.  Expected ").append(nk_part + " not faound.").append(newline);
                pass = false;
            } else {
                sb.append("Expected ").append(nk_part).append(" faound.").append(newline);
            }
        }
    }
    sb.append("Expected NewCookie: ").append(nk_String).append(newline);
    assertTrue(pass, "At least one assertion failed: " + sb.toString());
    TestUtil.logTrace(sb.toString());
}
Also used : NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 22 with NewCookie

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

the class JAXRSClientIT method constructorTest5.

/*
   * @testName: constructorTest5
   * 
   * @assertion_ids: JAXRS:JAVADOC:107; 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 0 NewCookie instance using constructor
   * Cookie(String, String, String, String, int) NewCookie(Cookie)
   */
@Test
public void constructorTest5() throws Fault {
    String name = "name_1";
    String value = "value_1";
    String path = "/acme";
    String domain = "y.x.foo.com";
    int version = 0;
    String comment = "";
    int maxage = jakarta.ws.rs.core.NewCookie.DEFAULT_MAX_AGE;
    boolean secure = false;
    Cookie ck5 = new Cookie(name, value, path, domain, version);
    NewCookie nck5 = new NewCookie(ck5);
    verifyNewCookie(nck5, 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 23 with NewCookie

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

the class JAXRSClientIT method parseTest2.

/*
   * @testName: parseTest2
   * 
   * @assertion_ids: JAXRS:JAVADOC:111; JAXRS:JAVADOC:100; JAXRS:JAVADOC:101;
   * JAXRS:JAVADOC:103; JAXRS:JAVADOC:53; JAXRS:JAVADOC:54; JAXRS:JAVADOC:55;
   * JAXRS:JAVADOC:56;
   * 
   * @test_Strategy: Create a version 0 NewCookie instance by Parsing a String
   */
@Test
public void parseTest2() throws Fault {
    String newCookie_toParse = "Customer=WILE_E_COYOTE; Path=/acme; Version=1";
    String name = "customer";
    String value = "wile_e_coyote";
    String path = "/acme";
    String domain = "";
    int version = 1;
    NewCookie nck27 = jakarta.ws.rs.core.NewCookie.valueOf(newCookie_toParse);
    verifyNewCookie(nck27, name, value, path, domain, version, "", -1, false);
}
Also used : NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 24 with NewCookie

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

the class Resource method set.

@POST
@Path("Set")
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response set(String content) {
    ResponseBuilder rb = Response.ok();
    if (content != null) {
        String[] cookies1 = content.split(";");
        for (String cookie : cookies1) {
            // name=0, value=1
            String[] nameVal = cookie.split("=");
            rb.cookie(new NewCookie(nameVal[0], nameVal[1]));
        }
    }
    return rb.build();
}
Also used : ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) NewCookie(jakarta.ws.rs.core.NewCookie) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST) Produces(jakarta.ws.rs.Produces) Consumes(jakarta.ws.rs.Consumes)

Example 25 with NewCookie

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

the class JAXRSClientIT method getHeadersTest.

/*
   * @testName: getHeadersTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:848;
   * 
   * @test_Strategy: Get view of the response headers and their object values.
   */
@Test
public void getHeadersTest() throws Fault {
    CacheControl ccl = new CacheControl();
    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()));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    String header = null;
    header = headers.getFirst(HttpHeaders.CACHE_CONTROL).toString();
    assertContainsIgnoreCase(header, "no-transform", "Cache-Control:no-transform has not been found");
    header = headers.getFirst(HttpHeaders.SET_COOKIE).toString();
    assertContainsIgnoreCase(header, "cookie=eikooc", "Set-Cookie:cookie=eikooc has not been found");
    header = headers.getFirst(HttpHeaders.CONTENT_ENCODING).toString();
    assertContainsIgnoreCase(header, "gzip", "Content-Encoding:gzip has not been found");
    header = headers.getFirst(HttpHeaders.EXPIRES).toString();
    assertNotNull(header, "Expires has not been found");
    header = headers.getFirst(HttpHeaders.CONTENT_LANGUAGE).toString();
    assertContainsIgnoreCase(langToString(header), langToString(Locale.CANADA_FRENCH), "Content-Language:", langToString(Locale.CANADA_FRENCH), "has not been found");
    Object noHeader = headers.getFirst("unknown");
    assertNull(noHeader, "Unknown header has been found", header);
}
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)

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