use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method abortWithTest.
/*
* @testName: abortWithTest
*
* @assertion_ids: JAXRS:JAVADOC:427; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85;
*
* @test_Strategy: Abort the filter chain with a response. This method breaks
* the filter chain processing and returns the provided response back to the
* client. The provided response goes through the chain of applicable response
* filters.
*
* ClientRequestFilter.filter ClientRequestFilter.abortWith
*/
@Test
public void abortWithTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Response r = Response.status(Status.CREATED).build();
context.abortWith(r);
}
};
Invocation i = buildInvocation(provider);
Response r = invoke(i);
assertStatus(r, Status.CREATED);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getCookiesTest.
/*
* @testName: getCookiesTest
*
* @assertion_ids: JAXRS:JAVADOC:432; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get any cookies that accompanied the request. Returns a
* read-only map of cookie name (String) to Cookie.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getCookiesTest() throws Fault {
Cookie cts = new Cookie("cts", "cts");
Cookie tck = new Cookie("tck", "tck");
Cookie jee = new Cookie("jee", "jee");
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
String cookies = JaxrsUtil.iterableToString(";", context.getCookies().values());
Response r = Response.ok(cookies).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).cookie(cts).cookie(tck).cookie(jee).buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "cts");
assertContains(entity, "tck");
assertContains(entity, "jee");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityAnnotationsTest.
/*
* @testName: getEntityAnnotationsTest
*
* @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).
*
* ClientRequestFilter.abortWith
*/
@Test
public void getEntityAnnotationsTest() throws Fault {
Annotation[] annotations = ContextProvider.class.getAnnotations();
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Annotation[] annotations = context.getEntityAnnotations();
String first = annotations == null ? "NULL" : annotations.length == 0 ? "0" : annotations[0].annotationType().getName();
Response r = Response.ok(first).build();
context.abortWith(r);
}
};
Entity<String> post = Entity.entity("test", MediaType.WILDCARD_TYPE, annotations);
Invocation invocation = buildBuilder(provider).buildPost(post);
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, annotations[0].annotationType().getName());
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getAcceptableMediaTypesIsSortedTest.
/*
* @testName: getAcceptableMediaTypesIsSortedTest
*
* @assertion_ids: JAXRS:JAVADOC:429; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get a list of media types that are acceptable for the
* response. Returns a read-only list of requested response media types sorted
* according to their q-value, with highest preference first.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getAcceptableMediaTypesIsSortedTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
List<MediaType> types = context.getAcceptableMediaTypes();
String medias = JaxrsUtil.iterableToString(";", types);
Response r = Response.ok(medias).build();
context.abortWith(r);
}
};
String media = "text/plain;q=0.3, text/html;q=0.7, text/xml;level=1, text/java;level=2;q=0.4, */*;q=0.5";
Invocation.Builder builder = buildBuilder(provider);
Invocation invocation = builder.header("Accept", media).buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class).toLowerCase();
int indexXml = entity.indexOf(MediaType.TEXT_XML);
int indexHtml = entity.indexOf(MediaType.TEXT_HTML);
int indexAny = entity.indexOf(MediaType.WILDCARD);
int indexJava = entity.indexOf("text/java");
int indexPlain = entity.indexOf(MediaType.TEXT_PLAIN);
assertTrue(indexXml < indexHtml && indexHtml < indexAny && indexAny < indexJava && indexJava < indexPlain, "Media Types " + entity + " are not sorted");
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getDateTest.
/*
* @testName: getDateTest
*
* @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 getDateTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Date date = context.getDate();
Response r = Response.ok(date.toString()).build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).header("Date", "Tue, 15 Nov 1994 08:12:31 GMT").buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, "Nov");
assertContains(entity, "1994");
assertContains(entity, "31");
}
Aggregations