use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method hasEntityTest.
/*
* @testName: hasEntityTest
*
* @assertion_ids: JAXRS:JAVADOC:448; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Check if there is an entity available in the request. The
* method returns true if the entity is present, returns false otherwise.
*
* ClientRequestFilter.abortWith
*/
@Test
public void hasEntityTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
boolean has = context.hasEntity();
String entity = String.valueOf(has);
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, "false");
Entity<String> entity = createEntity("TEST");
WebTarget target = buildTarget(provider);
invocation = target.request().buildPost(entity);
response = invoke(invocation);
body = response.readEntity(String.class);
assertContains(body, "true");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getConfigurationTest.
/*
* @testName: getConfigurationTest
*
* @assertion_ids: JAXRS:JAVADOC:977; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the immutable configuration of the request.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getConfigurationTest() throws Fault {
final Client client = ClientBuilder.newClient();
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Client contextClient = context.getClient();
assertEquals(contextClient, client, "the client instance is different from the context one");
Configuration contextConfig = context.getConfiguration();
assertNotNull(contextConfig, "context.getConfiguration() returned null");
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);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeadersTest.
/*
* @testName: getHeadersTest
*
* @assertion_ids: JAXRS:JAVADOC:439; 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 getHeadersTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
MultivaluedMap<String, Object> headers = context.getHeaders();
String entity = JaxrsUtil.iterableToString(";", headers.keySet());
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).header("Accept", MediaType.TEXT_HTML).header("tck", "cts").header("Date", "Tue, 15 Nov 1994 08:12:31 GMT").buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "Accept");
assertContains(entity, "Date");
assertContains(entity, "tck");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityClassListStringTest.
/*
* @testName: getEntityClassListStringTest
*
* @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 getEntityClassListStringTest() 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);
}
};
List<String> list = new ArrayList<String>();
Entity<List<String>> post = createEntity(list);
Invocation invocation = buildBuilder(provider).buildPost(post);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, ArrayList.class.getName());
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityTypeListStringTest.
/*
* @testName: getEntityTypeListStringTest
*
* @assertion_ids: JAXRS:JAVADOC:438; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the generic entity type information.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityTypeListStringTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Type type = context.getEntityType();
String entity = type.toString();
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
List<String> list = new ArrayList<String>();
GenericEntity<List<String>> generic = new GenericEntity<List<String>>(list) {
};
Entity<GenericEntity<List<String>>> post = createEntity(generic);
Invocation invocation = buildBuilder(provider).buildPost(post);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, String.class.getName());
}
Aggregations