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: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 getMediaTypeTest() 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);
}
};
Entity<String> entity = Entity.entity("TEST", MediaType.APPLICATION_FORM_URLENCODED);
Invocation invocation = buildBuilder(provider).buildPost(entity);
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(body, MediaType.APPLICATION_FORM_URLENCODED);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getAcceptableLanguagesTest.
/*
* @testName: getAcceptableLanguagesTest
*
* @assertion_ids: JAXRS:JAVADOC:428; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Get a list of languages that are acceptable for the
* response. Returns: a read-only list of acceptable languages sorted
* according to their q-value, with highest preference first.
*
* ClientRequestFilter.filter ClientRequestFilter.abortWith
*/
@Test
public void getAcceptableLanguagesTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
List<Locale> locales = context.getAcceptableLanguages();
String languages = JaxrsUtil.iterableToString(";", locales);
Response r = Response.ok(languages).build();
context.abortWith(r);
}
};
Invocation.Builder builder = buildBuilder(provider);
Invocation invocation;
invocation = builder.acceptLanguage(Locale.CANADA_FRENCH).acceptLanguage(Locale.PRC).buildGet();
Response response = invoke(invocation);
String entity = response.readEntity(String.class);
assertContains(entity, Locale.CANADA_FRENCH.toString());
assertContains(entity, Locale.PRC.toString());
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getCookiesIsImmutableTest.
/*
* @testName: getCookiesIsImmutableTest
*
* @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 getCookiesIsImmutableTest() throws Fault {
final Cookie cts = new Cookie("cts", "cts");
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Map<String, Cookie> cookies = context.getCookies();
try {
cookies.put("test", cts);
} catch (Exception e) {
// either exception is thrown or put does nothing
}
cookies = context.getCookies();
Cookie cookie = cookies.get("test");
assertTrue(cookie == null, "getCookies is not read-only");
Response r = Response.ok().build();
context.abortWith(r);
}
};
Invocation invocation = buildBuilder(provider).cookie(cts).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 getPropertyIsNullTest.
/*
* @testName: getPropertyIsNullTest
*
* @assertion_ids: JAXRS:JAVADOC:444; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
* JAXRS:SPEC:85; JAXRS:JAVADOC:427;
*
* @test_Strategy: Returns the property with the given name registered in the
* current request/response exchange context, or null if there is no property
* by that name.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getPropertyIsNullTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
Object property = context.getProperty("PROPERTY");
String entity = property == null ? "NULL" : property.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 hasEntityWhenEntityTest.
/*
* @testName: hasEntityWhenEntityTest
*
* @assertion_ids: JAXRS:JAVADOC:474; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Check if there is a non-empty entity input stream is
* available in the response message. ClientResponseFilter.filter
*/
@Test
public void hasEntityWhenEntityTest() throws Fault {
final String entity = "eNtitY";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
boolean has = responseContext.hasEntity();
assertTrue(has, "the #hasEntity did not found the given entity");
logMsg("Found #hasEntity()=true");
}
};
Response response = Response.ok(entity).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Aggregations