use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLastModifiedTest.
/*
* @testName: getLastModifiedTest
*
* @assertion_ids: JAXRS:JAVADOC:465; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the last modified date.
*
* ClientResponseFilter.filter
*/
@Test
public void getLastModifiedTest() throws Fault {
final Date lastModified = getNewDate();
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
Date date = responseContext.getLastModified();
assertTrue(date != null, "the #getLastModified is null");
assertTrue(lastModified.equals(date), "#getLastModified was supposed to be " + lastModified + " but was " + date);
logMsg("Found #getLastModified()=", date);
}
};
Response response = Response.ok().lastModified(lastModified).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringTest.
/*
* @testName: getHeaderStringTest
*
* @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: the message header value.
*
* ClientResponseFilter.filter
*/
@Test
public void getHeaderStringTest() throws Fault {
final String header1 = "header1";
final String value1 = "value1";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
String header = responseContext.getHeaderString(header1);
assertTrue(header != null, "the #getHeaderString is null");
assertTrue(header.equals(value1), "the #getHeaderString=" + header + " differs from expected " + value1);
logMsg("#getHeaderString is", value1, "as expected");
}
};
Response response = Response.ok().header(header1, value1).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringIsEmptyTest.
/*
* @testName: getHeaderStringIsEmptyTest
*
* @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: the message header value. If the message header is present
* but has no value then the empty string is returned.
*
* ClientResponseFilter.filter
*/
@Test
public <T> void getHeaderStringIsEmptyTest() throws Fault {
final String header1 = "header1";
RuntimeDelegate original = RuntimeDelegate.getInstance();
RuntimeDelegate.setInstance(new NullStringBeanRuntimeDelegate(original));
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
String header = responseContext.getHeaderString(header1);
assertTrue(header != null, "the #getHeaderString is null");
assertTrue(header.equals(""), "the #getHeaderString is NOT empty, but " + header);
logMsg("#getHeaderString is empty string as expected");
}
};
Response response = Response.ok().header(header1, new StringBean("aa")).build();
try {
invokeWithResponseAndAssertStatus(response, Status.OK, in);
} finally {
RuntimeDelegate.setInstance(original);
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
}
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method createBadResponseFilter.
protected ClientRequestFilter createBadResponseFilter() {
ClientRequestFilter filter = new ClientRequestFilter() {
@Override
public void filter(ClientRequestContext arg0) throws IOException {
Response r = Response.status(Status.NOT_ACCEPTABLE).build();
arg0.abortWith(r);
}
};
return filter;
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeadersIsMutableTest.
/*
* @testName: getHeadersIsMutableTest
*
* @assertion_ids: JAXRS:JAVADOC:440; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the mutable request headers multivalued map.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getHeadersIsMutableTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
MultivaluedMap<String, Object> headers = context.getHeaders();
headers.add("Accept", MediaType.APPLICATION_JSON);
headers = context.getHeaders();
String entity = JaxrsUtil.iterableToString(";", headers.keySet());
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "Accept");
}
Aggregations