use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringIsEmptyTest.
/*
* @testName: getHeaderStringIsEmptyTest
*
* @assertion_ids: JAXRS:JAVADOC:463; JAXRS:JAVADOC:479; JAXRS:JAVADOC:480;
*
* @test_Strategy: the message header value. If the message header is present
* but has no value then the empty string is returned.
*
* ClientResponseFilter.filter
*/
@Test
public <T> void getHeaderStringIsEmptyTest() throws Fault {
final String header1 = "header1";
RuntimeDelegate original = RuntimeDelegate.getInstance();
RuntimeDelegate.setInstance(new NullStringBeanRuntimeDelegate(original));
ContextProvider in = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext requestContext, ClientResponseContext responseContext) throws Fault {
String header = responseContext.getHeaderString(header1);
assertTrue(header != null, "the #getHeaderString is null");
assertTrue(header.equals(""), "the #getHeaderString is NOT empty, but " + header);
logMsg("#getHeaderString is empty string as expected");
}
};
Response response = Response.ok().header(header1, new StringBean("aa")).build();
try {
invokeWithResponseAndAssertStatus(response, Status.OK, in);
} finally {
RuntimeDelegate.setInstance(original);
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
}
}
use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method getHeaderStringUsingHeaderDelegateTest.
/*
* @testName: getHeaderStringUsingHeaderDelegateTest
*
* @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. Each single
* header value is converted to String using a RuntimeDelegate.HeaderDelegate.
*
* ClientRequestFilter.abortWith
*/
@Test
public void getHeaderStringUsingHeaderDelegateTest() throws Fault {
final String name = "BEAN";
final StringBean bean = new StringBean(name);
ContextProvider provider = new ContextProvider() {
@Override
protected void checkFilterContext(ClientRequestContext context) throws Fault {
String value = context.getHeaderString(name);
Response r = Response.ok(value).build();
context.abortWith(r);
}
};
RuntimeDelegate original = RuntimeDelegate.getInstance();
RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(original));
try {
Invocation invocation = buildBuilder(provider).header(name, bean).buildGet();
Response response = invoke(invocation);
String body = response.readEntity(String.class);
assertContains(name.toLowerCase(), body.toLowerCase());
} finally {
RuntimeDelegate.setInstance(original);
StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
}
}
use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.
the class JAXRSClientIT method stringBeanWriterClientInterceptorTest.
/*
* @testName: stringBeanWriterClientInterceptorTest
*
* @assertion_ids: JAXRS:SPEC:84;
*
* @test_Strategy: JAX-RS implementations are REQUIRED to call registered
* interceptors when stringBeanping representations to Java types and vice
* versa.
*/
@Test
@Tag("xml_binding")
public void stringBeanWriterClientInterceptorTest() throws Fault {
addInterceptors(EntityWriterInterceptor.class);
addProvider(EntityWriterInterceptor.class);
addProvider(StringBeanEntityProvider.class);
setRequestContentEntity(new StringBean(content));
setProperty(Property.REQUEST, buildRequest(Request.POST, "poststring"));
setProperty(Property.SEARCH_STRING, EntityWriterInterceptor.class.getName());
setProperty(Property.UNEXPECTED_RESPONSE_MATCH, Resource.DIRECTION);
invoke();
logMsg("JAXRS called registered writer interceptor for StringBean provider");
}
use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.
the class TextWildCardStringBeanEntityProvider method readFrom.
@Override
public StringBean readFrom(Class<StringBean> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
StringBean bean = super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream);
bean.set(bean.get() + "text");
return bean;
}
use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.
the class Resource method getHeaderStringByHeader.
@POST
@Path("getheaderstringheader")
public Response getHeaderStringByHeader(String content) {
ResponseBuilder builder = createResponseWithHeader();
if (content.equals("toString"))
builder = builder.header(ResponseFilter.HEADER, new StringBuilder().append(ResponseFilter.ENTITY));
if (content.equals("commaSeparated")) {
builder = builder.header(ResponseFilter.HEADER, new StringBuilder().append(ResponseFilter.ENTITY));
builder = builder.header(ResponseFilter.HEADER, ResponseFilter.ENTITY);
}
if (content.equals("headerDelegate")) {
StringBean bean = new StringBean(ResponseFilter.ENTITY);
builder = builder.header(ResponseFilter.HEADER, bean);
}
if (content.equalsIgnoreCase("entity"))
builder = builder.header(ResponseFilter.HEADER, content);
Response response = builder.build();
return response;
}
Aggregations