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);
}
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"));
}
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;
}
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);
}
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);
}
Aggregations