Search in sources :

Example 11 with StringBean

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();
    }
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) ClientResponseContext(jakarta.ws.rs.client.ClientResponseContext) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Test(org.junit.jupiter.api.Test)

Example 12 with StringBean

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();
    }
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Response(jakarta.ws.rs.core.Response) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Invocation(jakarta.ws.rs.client.Invocation) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Test(org.junit.jupiter.api.Test)

Example 13 with StringBean

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");
}
Also used : StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 14 with StringBean

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;
}
Also used : StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean)

Example 15 with StringBean

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;
}
Also used : Response(jakarta.ws.rs.core.Response) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Aggregations

StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)15 Test (org.junit.jupiter.api.Test)11 Response (jakarta.ws.rs.core.Response)8 StringBeanRuntimeDelegate (ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate)6 RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)6 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)4 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)3 POST (jakarta.ws.rs.POST)2 Path (jakarta.ws.rs.Path)2 Invocation (jakarta.ws.rs.client.Invocation)2 ClientRequestFilter (jakarta.ws.rs.client.ClientRequestFilter)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 Tag (org.junit.jupiter.api.Tag)1