use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityTest.
/*
* @testName: getEntityTest
*
* @assertion_ids: JAXRS:JAVADOC:434; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85;
*
* @test_Strategy: Get the message entity Java instance. Returns null if the
* message does not contain an entity.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Object entity = context.getEntity();
Response r = Response.ok(entity.toString()).build();
context.abortWith(r);
}
};
Entity<String> post = createEntity("test");
Invocation invocation = buildBuilder(provider).buildPost(post);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "test");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityNullTest.
/*
* @testName: getEntityNullTest
*
* @assertion_ids: JAXRS:JAVADOC:434; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the message entity Java instance. Returns null if the
* message does not contain an entity.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityNullTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Object entity = context.getEntity();
Response r = Response.ok(entity == null ? "NULL" : entity.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 getLanguageIsNullTest.
/*
* @testName: getLanguageIsNullTest
*
* @assertion_ids: JAXRS:JAVADOC:441; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the language of the entity. Returns: the language of
* the entity or null if not specified
*
* ClientRequestFilter.abortWith
*/
@Test
public void getLanguageIsNullTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Locale lang = context.getLanguage();
String entity = lang == null ? "NULL" : lang.toString();
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Entity<String> entity = createEntity("TEST");
Invocation invocation = buildBuilder(provider).buildPost(entity);
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(body, "NULL");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityAnnotationsNullTest.
/*
* @testName: getEntityAnnotationsNullTest
*
* @assertion_ids: JAXRS:JAVADOC:435; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the annotations attached to the entity.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityAnnotationsNullTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Annotation[] annotations = context.getEntityAnnotations();
String len = annotations == null ? "0" : String.valueOf(annotations.length);
Response r = Response.ok(len).build();
context.abortWith(r);
}
};
Entity<String> post = createEntity("test");
Invocation invocation = buildBuilder(provider).buildPost(post);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "0");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLanguageTest.
/*
* @testName: getLanguageTest
*
* @assertion_ids: JAXRS:JAVADOC:441; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the language of the entity. Returns: the language of
* the entity or null if not specified
*
* ClientRequestFilter.abortWith
*/
@Test
public void getLanguageTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Locale lang = context.getLanguage();
String entity = lang == null ? "NULL" : lang.toString();
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Locale locale = Locale.TRADITIONAL_CHINESE;
Variant variant = new Variant(MediaType.TEXT_XML_TYPE, locale, null);
Entity<String> entity = Entity.entity("TEST", variant);
Invocation invocation = buildBuilder(provider).buildPost(entity);
Response response = invoke(invocation);
String body = response.readEntity(String.class).toLowerCase().replace('-', '_');
assertContains(body, locale.toString().toLowerCase());
}
Aggregations