use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLocationTest.
/*
* @testName: getLocationTest
*
* @assertion_ids: JAXRS:JAVADOC:470; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the location. ClientResponseFilter.filter
*/
@Test
public void getLocationTest() throws Fault {
URI uri = null;
try {
uri = new URI(getUrl());
} catch (URISyntaxException e) {
throw new Fault(e);
}
final URI location = uri;
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
URI responseLocation = responseContext.getLocation();
assertTrue(responseLocation != null, "the #getLinks is null");
assertTrue(location.equals(responseLocation), "#getLocation was supposed to be " + location + " but was " + responseLocation);
logMsg("Found #getLocation=", location.toASCIIString());
}
};
Response response = Response.ok().location(location).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createRequestFilter.
// ///////////////////////////////////////////////////////////////////////
protected static ClientRequestFilter createRequestFilter(final Response response) {
ClientRequestFilter outFilter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext context) throws IOException {
// logMsg(" -- OUT FILTER --");
Response r;
if (response == null)
r = Response.ok().build();
else
r = response;
context.abortWith(r);
}
};
return outFilter;
}
use of jakarta.ws.rs.client.ClientRequestContext 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.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getDateTest.
/*
* @testName: getDateTest
*
* @assertion_ids: JAXRS:JAVADOC:459; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get message date.
*
* ClientResponseFilter.filter
*/
@Test
public void getDateTest() throws Fault {
final Date date = getNewDate();
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
assertTrue(date.equals(responseContext.getDate()), "The #getDate " + responseContext.getDate() + " is not equal to what is inserted to the response " + date);
logMsg("Found #getDate()=", responseContext.getDate());
}
};
Response response = Response.ok().header("Date", date).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method setStatusTest.
/*
* @testName: setStatusTest
*
* @assertion_ids: JAXRS:JAVADOC:477; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Set a new response status code. ClientResponseFilter.filter
*/
@Test
public void setStatusTest() throws Fault {
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
responseContext.setStatus(Status.FORBIDDEN.getStatusCode());
}
};
Response response = Response.ok().build();
invokeWithResponseAndAssertStatus(response, Status.FORBIDDEN, in);
}
Aggregations