use of jakarta.ws.rs.client.ClientResponseContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method setStatusInfoTest.
/*
* @testName: setStatusInfoTest
*
* @assertion_ids: JAXRS:JAVADOC:478; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Set the complete status information associated with the
* response.
*
* ClientResponseFilter.filter
*/
@Test
public void setStatusInfoTest() throws Fault {
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
StatusType info = new StatusType() {
@Override
public int getStatusCode() {
return Status.FOUND.getStatusCode();
}
@Override
public String getReasonPhrase() {
return null;
}
@Override
public Family getFamily() {
return null;
}
};
responseContext.setStatusInfo(info);
}
};
Response response = Response.ok().build();
invokeWithResponseAndAssertStatus(response, Status.FOUND, in);
}
use of jakarta.ws.rs.client.ClientResponseContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeadersTest.
/*
* @testName: getHeadersTest
*
* @assertion_ids: JAXRS:JAVADOC:462; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the mutable response headers multivalued map.
*
* ClientResponseFilter.filter
*/
@Test
public void getHeadersTest() throws Fault {
final String header1 = "header1";
final String value1 = "value1";
final String header2 = "header2";
final String value2 = "value2";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
MultivaluedMap<String, String> headers = responseContext.getHeaders();
assertTrue(headers != null, "the #getHeaders is null");
assertTrue(headers.size() == 2, "the #getHeaders size is " + headers.size() + " expected 2");
assertTrue(value1.equals(headers.getFirst(header1)), "#getHeaders was supposed to contain" + header1 + ":" + value1 + " header, but " + header1 + " is " + headers.getFirst(header1));
logMsg("Found #getHeaders()={", header1, ":", value1, "}");
}
};
Response response = Response.ok().header(header1, value1).header(header2, value2).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientResponseContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getLinkBuilderTest.
/*
* @testName: getLinkBuilderTest
*
* @assertion_ids: JAXRS:JAVADOC:468; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Convenience method that returns a
* jakarta.ws.rs.core.Link.Builder for the relation. ClientResponseFilter.filter
*/
@Test
public void getLinkBuilderTest() throws Fault {
final String rel = "RELATION";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
Builder builder = responseContext.getLinkBuilder(rel);
assertTrue(builder != null, "the #getLinkBuilder is null");
assertTrue(builder.build().getUri().toASCIIString().contains(getUrl()), "#getLinkBuilder.build was supposed to contain " + getUrl() + " but was " + builder.build().getUri().toASCIIString());
logMsg("Found #getLinkBuilder()=", builder.build().getUri().toASCIIString());
}
};
Response response = Response.ok().link(getUrl(), rel).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientResponseContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringIsCommaSeparatedTest.
/*
* @testName: getHeaderStringIsCommaSeparatedTest
*
* @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: the message header value. If the message header is present
* more than once then the values of joined together and separated by a ','
* character.
*
* ClientResponseFilter.filter
*/
@Test
public void getHeaderStringIsCommaSeparatedTest() throws Fault {
final String header1 = "header1";
final String value1 = "value1";
final String value2 = "value2";
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
String header = responseContext.getHeaderString(header1);
String value3 = value1 + "," + value2;
String value4 = value2 + "," + value1;
assertTrue(header != null, "the #getHeaderString is null");
assertTrue(header.equals(value3) || header.equals(value4), "the #getHeaderString=" + header + " differs from expected comma separated combination of " + value1 + " and " + value2);
logMsg("#getHeaderString is comma separated combination of", value1, "and", value2, "as expected");
}
};
Response response = Response.ok().header(header1, value1).header(header1, value2).build();
invokeWithResponseAndAssertStatus(response, Status.OK, in);
}
use of jakarta.ws.rs.client.ClientResponseContext in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getStatusInfoTest.
/*
* @testName: getStatusInfoTest
*
* @assertion_ids: JAXRS:JAVADOC:473; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: Get the status code associated with the response.
*
* ClientResponseFilter.filter
*/
@Test
public void getStatusInfoTest() throws Fault {
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
assertTrue(responseContext.getStatusInfo().getStatusCode() == 222, "unexpected status " + responseContext.getStatusInfo().getStatusCode());
TestUtil.logMsg("Found expected response status 222");
}
};
Response response = Response.status(222).build();
ClientRequestFilter filter = createRequestFilter(response);
Invocation i = buildInvocation(filter, provider);
Response r = invoke(i);
assertTrue(r.getStatus() == 222, "unexpected status " + r.getStatus());
}
Aggregations