use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getStringHeadersTest.
/*
* @testName: getStringHeadersTest
*
* @assertion_ids: JAXRS:JAVADOC:446; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get a string view of header values associated with the
* message.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getStringHeadersTest() throws Fault {
final String TCK = "cts";
final String DATE = "Tue, 15 Nov 1994 08:12:31 GMT";
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
MultivaluedMap<String, String> map;
map = context.getStringHeaders();
StringBuilder value = new StringBuilder();
value.append(map.getFirst("Accept")).append(" ");
value.append(map.getFirst("tck")).append(" ");
value.append(map.getFirst("Date"));
Response r = Response.ok(value.toString()).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).header("Accept", MediaType.TEXT_HTML).header("tck", TCK).header("Date", DATE).buildGet();
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(body, MediaType.TEXT_HTML);
assertContains(body, TCK);
assertContains(body, DATE);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getUriTest.
/*
* @testName: getUriTest
*
* @assertion_ids: JAXRS:JAVADOC:447; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the request URI.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getUriTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
URI uri = context.getUri();
String entity = uri.toASCIIString();
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Invocation invocation = buildInvocation(provider);
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(body, getUrl());
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getAcceptableLanguagesIsImmutableTest.
/*
* @testName: getAcceptableLanguagesIsImmutableTest
*
* @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.abortWith
*/
@Test
public void getAcceptableLanguagesIsImmutableTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
List<Locale> locales = context.getAcceptableLanguages();
try {
locales.add(Locale.JAPAN);
} catch (Exception e) {
// either exception is thrown, or add does nothing
}
locales = context.getAcceptableLanguages();
boolean b = locales.contains(Locale.JAPAN);
assertTrue(!b, "getAcceptableLanguages is not read-only");
Response r = Response.ok().build();
context.abortWith(r);
}
};
WebTarget target = buildTarget(provider);
Invocation.Builder builder = target.request();
Invocation invocation;
invocation = builder.header("Accept-Language", "da, en-gb;q=0.6, en-us;q=0.7").buildGet();
Response response = invoke(invocation);
assertStatus(response, Status.OK);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getStringHeadersUsingHeaderDelegateTest.
/*
* @testName: getStringHeadersUsingHeaderDelegateTest
*
* @assertion_ids: JAXRS:JAVADOC:446; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get a string view of header values associated with the
* message. The method converts the non-string header values to strings using
* a RuntimeDelegate.HeaderDelegate
*
* ClientRequestFilter.abortWith
*/
@Test
public void getStringHeadersUsingHeaderDelegateTest() throws Fault {
final String TCK = "cts";
final StringBean bean = new StringBean(TCK);
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
MultivaluedMap<String, String> map;
map = context.getStringHeaders();
StringBuilder value = new StringBuilder();
value.append(map.getFirst(TCK));
Response r = Response.ok(value.toString()).build();
context.abortWith(r);
}
};
RuntimeDelegate delegate = RuntimeDelegate.getInstance();
RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(delegate));
try {
Invocation invocation = buildBuilder(provider).header(TCK, bean).buildGet();
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(body, TCK);
} finally {
RuntimeDelegate.setInstance(delegate);
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
}
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getClientTest.
/*
* @testName: getClientTest
*
* @assertion_ids: JAXRS:JAVADOC:430; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the client instance associated with the request.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getClientTest() throws Fault {
final Client client = ClientBuilder.newClient();
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Client contextClient = context.getClient();
assertTrue(client == contextClient, "the client instance is different from the context one");
Response r = Response.ok().build();
context.abortWith(r);
}
};
client.register(provider);
WebTarget target = client.target(getUrl());
Invocation invocation = target.request().buildGet();
Response response = invoke(invocation);
assertStatus(response, Status.OK);
}
Aggregations