use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLinksTest.
/*
* @testName: getLinksTest
*
* @assertion_ids: JAXRS:JAVADOC:469; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the links attached to the message as header.
*
* ClientResponseFilter.filter
*/
@Test
public void getLinksTest() throws Fault {
final Link link = Link.fromUri(getUrl()).build();
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
Set<Link> links = responseContext.getLinks();
assertTrue(links != null, "the #getLinks is null");
assertTrue(links.size() == 1, "the links was supposed to be of size 1, was " + links.size());
assertTrue(links.contains(link), "#getLinks was supposed to contain " + link.getUri().toASCIIString());
logMsg("Found #getLinks()={", link.getUri().toASCIIString(), "}");
}
};
Response response = Response.ok().links(link).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityClassTest.
/*
* @testName: getEntityClassTest
*
* @assertion_ids: JAXRS:JAVADOC:436; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the raw entity type information.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityClassTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Class<?> clazz = context.getEntityClass();
Response r = Response.ok(clazz.getName()).build();
context.abortWith(r);
}
};
Entity<ByteArrayInputStream> post = createEntity(new ByteArrayInputStream("test".getBytes()));
Invocation invocation = buildBuilder(provider).buildPost(post);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, ByteArrayInputStream.class.getName());
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getDateNullTest.
/*
* @testName: getDateNullTest
*
* @assertion_ids: JAXRS:JAVADOC:433; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get message date. Returns: the message date, otherwise null
* if not present.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getDateNullTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Date date = context.getDate();
Response r = Response.ok(date == null ? "NULL" : date.toString()).build();
context.abortWith(r);
}
};
Invocation invocation = buildInvocation(provider);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "NULL");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getMethodTest.
/*
* @testName: getMethodTest
*
* @assertion_ids: JAXRS:JAVADOC:443; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the request method.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getMethodTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
String method = context.getMethod();
Response r = Response.ok(method).build();
context.abortWith(r);
}
};
Entity<String> entity = createEntity("TEST");
Invocation invocation;
Response response;
for (String method : new String[] { "OPTIONS", "DELETE", "GET", "TRACE" }) {
invocation = buildBuilder(provider).build(method);
response = invoke(invocation);
String body = response.readEntity(String.class).toUpperCase();
assertContains(body, method);
}
for (String method : new String[] { "PUT", "POST" }) {
invocation = buildBuilder(provider).build(method, entity);
response = invoke(invocation);
String body = response.readEntity(String.class).toUpperCase();
assertContains(body, method);
}
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getAcceptableLanguagesByWeightsTest.
/*
* @testName: getAcceptableLanguagesByWeightsTest
*
* @assertion_ids: JAXRS:JAVADOC:428; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: a read-only list of requested response media types sorted
* according to their q-value, with highest preference first.
*
* ClientRequestFilter.filter ClientRequestFilter.abortWith
*/
@Test
public void getAcceptableLanguagesByWeightsTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
List<Locale> locales = context.getAcceptableLanguages();
String languages = JaxrsUtil.iterableToString(";", locales);
Response r = Response.ok(languages).build();
context.abortWith(r);
}
};
Invocation.Builder builder = buildBuilder(provider);
Invocation invocation;
invocation = builder.acceptLanguage("da, en-gb;q=0.6, en-us;q=0.7").buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class).toLowerCase();
assertContains(entity, "da");
assertContains(entity, "gb");
assertContains(entity, "us");
int indexDa = entity.indexOf("da");
int indexUs = entity.indexOf("us");
int indexGb = entity.indexOf("gb");
assertTrue(indexDa < indexUs && indexUs < indexGb, "List of acceptable languages " + entity + " is not sorted by q values");
}
Aggregations