use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityStreamTest.
/*
* @testName: getEntityStreamTest
*
* @assertion_ids: JAXRS:JAVADOC:460; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the entity input stream
*
* ClientResponseFilter.filter
*/
@Test
public void getEntityStreamTest() throws Fault {
final String entity = "ENTITY";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
InputStream stream = responseContext.getEntityStream();
assertTrue(stream != null, "the #getEntityStream is null");
InputStreamReader isr = new InputStreamReader(stream);
BufferedReader br = new BufferedReader(isr);
String line = null;
try {
line = br.readLine();
} catch (IOException e) {
throw new Fault(e);
} finally {
try {
br.close();
} catch (IOException e) {
}
}
assertTrue(entity.equals(line), "The #getEntityStream " + line + " is not equal to what is inserted to the response: " + entity);
logMsg("Found #getEntityStream()=", line);
// for next reading
responseContext.setEntityStream(new ByteArrayInputStream(entity.getBytes()));
}
};
Response response = Response.ok(entity).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getEntityTagTest.
/*
* @testName: getEntityTagTest
*
* @assertion_ids: JAXRS:JAVADOC:461; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the entity tag.
*
* ClientResponseFilter.filter
*/
@Test
public void getEntityTagTest() throws Fault {
final String value = "EntityTagValue";
final EntityTag tag = new EntityTag(value);
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
EntityTag etag = responseContext.getEntityTag();
assertTrue(etag != null, "the #getEntityTag is null");
assertTrue(value.equals(etag.getValue()), "The #getEntityTag " + etag.getValue() + " is not equal to what is inserted to the response: " + value);
logMsg("Found #getEntityTag()=", value);
}
};
Response response = Response.ok().tag(tag).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLinkTest.
/*
* @testName: getLinkTest
*
* @assertion_ids: JAXRS:JAVADOC:467; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the link for the relation.
*
* ClientResponseFilter.filter
*/
@Test
public void getLinkTest() throws Fault {
final String rel = "RELATION";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
Link link = responseContext.getLink(rel);
assertTrue(link != null, "the #getLink is null");
assertTrue(link.getUri() != null, "the #getLink.getUri is null");
assertTrue(link.getUri().toASCIIString().contains(getUrl()), "#getLink was supposed to contain " + getUrl() + " but was " + link.getUri().toASCIIString());
logMsg("Found #getLink()=", link.getUri().toASCIIString());
}
};
Response response = Response.ok().link(getUrl(), rel).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method hasLinkWhenNoLinkTest.
/*
* @testName: hasLinkWhenNoLinkTest
*
* @assertion_ids: JAXRS:JAVADOC:475; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Check if link for relation exists.
*
* ClientResponseFilter.filter
*/
@Test
public void hasLinkWhenNoLinkTest() throws Fault {
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
boolean has = responseContext.hasLink("rel");
assertTrue(!has, "the #hasLink did found some link");
logMsg("#hasLink has not found any link as expected");
}
};
Response response = Response.ok().link(getUrl(), "ANY").build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientRequestContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method hasLinkWhenLinkTest.
/*
* @testName: hasLinkWhenLinkTest
*
* @assertion_ids: JAXRS:JAVADOC:475; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Check if link for relation exists.
* ClientResponseFilter.filter
*/
@Test
public void hasLinkWhenLinkTest() throws Fault {
final String rel = "RelatiOn";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
boolean has = responseContext.hasLink(rel);
assertTrue(has, "the #hasLink did not found the given link");
logMsg("#hasLink has found the given link");
}
};
Response response = Response.ok().link(getUrl(), rel).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
Aggregations