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:440; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get a message header as a single string value.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getHeaderStringTest() 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 {
String value;
value = context.getHeaderString("tck");
assertContainsIgnoreCase(value, TCK, "The expected value", TCK, "was not found, found", value, "instead");
value = context.getHeaderString("accept");
assertContainsIgnoreCase(value, MediaType.TEXT_HTML, "The expected value", MediaType.TEXT_HTML, "was not found, found", value, "instead");
value = context.getHeaderString("date");
assertContainsIgnoreCase(value, DATE, "The expected value", DATE, "was not found, found", value, "instead");
Response r = Response.ok().build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).header("Accept", MediaType.TEXT_HTML).header("tck", // toString()
new StringBuffer().append(TCK)).header("Date", DATE).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 getEntityAnnotationsIsNotTakenFromEntityClassTest.
/*
* @testName: getEntityAnnotationsIsNotTakenFromEntityClassTest
*
* @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. Note that the
* returned annotations array contains only those annotations explicitly
* attached to entity instance (such as the ones attached using
* Entity.Entity(Object, jakarta.ws.rs.core.MediaType,
* java.lang.annotation.Annotation[]) method). The entity instance annotations
* array does not include annotations declared on the entity implementation
* class or its ancestors.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityAnnotationsIsNotTakenFromEntityClassTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Annotation[] annotations = context.getEntityAnnotations();
String first = annotations == null ? "0" : String.valueOf(annotations.length);
Response r = Response.ok(first).build();
context.abortWith(r);
}
};
Entity<StringBeanWithAnnotation> post = createEntity(new StringBeanWithAnnotation("test"));
Invocation invocation = buildTarget(provider).register(StringBeanEntityProvider.class).request().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 getMediaTypeIsNullTest.
/*
* @testName: getMediaTypeIsNullTest
*
* @assertion_ids: JAXRS:JAVADOC:442; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get the media type of the entity. Returns: the media type
* or null if not specified (e.g. there's no request entity).
*
* ClientRequestFilter.abortWith
*/
@Test
public void getMediaTypeIsNullTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
MediaType media = context.getMediaType();
String entity = media == null ? "NULL" : media.toString();
Response r = Response.ok(entity).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).buildGet();
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 getMediaTypeTest.
/*
* @testName: getMediaTypeTest
*
* @assertion_ids: JAXRS:JAVADOC:471; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the media type of the entity.
*
* ClientResponseFilter.filter
*/
@Test
public void getMediaTypeTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
MediaType type = responseContext.getMediaType();
assertTrue(MediaType.APPLICATION_SVG_XML_TYPE.equals(type), "Unexpected mediatype found " + type);
TestUtil.logMsg("Found expected MediaType.APPLICATION_SVG_XML_TYPE");
}
};
Response response = Response.ok("TEST", MediaType.APPLICATION_SVG_XML).build();
invokeWithResponseAndAssertStatus(response, Status.OK, provider);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLengthTest.
/*
* @testName: getLengthTest
*
* @assertion_ids: JAXRS:JAVADOC:466; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get Content-Length value.
*
* ClientResponseFilter.filter
*/
@Test
public void getLengthTest() throws Fault {
final String entity = "ENTITY";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
int len = responseContext.getLength();
assertTrue(len == entity.length(), "#getLength was supposed to be " + entity.length() + " but was " + len);
logMsg("Found #getLength()=", len);
}
};
Response response = Response.ok().header(HttpHeaders.CONTENT_LENGTH, entity.length()).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Aggregations