Search in sources :

Example 6 with StringBean

use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method proceedThrowsWebApplicationExceptionTest.

/*
   * @testName: proceedThrowsWebApplicationExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:925; JAXRS:JAVADOC:1008; JAXRS:JAVADOC:920;
   * JAXRS:SPEC:85;
   * 
   * @test_Strategy: Throws: WebApplicationException - thrown by the wrapped
   * {@code MessageBodyReader.readFrom} method.
   * 
   * Proceed is tested in any of the intercepter tests.
   * 
   * ReaderInterceptor.aroundReadFrom If abortWith is invoked, execution is
   * aborted
   */
@Test
public void proceedThrowsWebApplicationExceptionTest() throws Fault {
    ResponseBuilder builder = createResponse(ContextOperation.PROCEEDTHROWSWEBAPPEXCEPTION);
    Response fake = builder.build();
    addProviders(fake);
    addProvider(ExceptionThrowingStringBeanEntityProvider.class);
    invoke();
    // Exception thrown, caught in InterceptorBodyOne
    StringBean bean = getResponseBody(ExceptionThrowingStringBean.class);
    // 
    assertContains(bean.get(), TemplateInterceptorBody.WAE, "WebApplicationException has not been thrown and the message is", bean.get());
    logMsg("WebApplicationException has been thrown as expected", bean.get());
}
Also used : Response(jakarta.ws.rs.core.Response) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with StringBean

use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getHeaderStringUsesToStringTest.

/*
   * @testName: getHeaderStringUsesToStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:780;
   * 
   * @test_Strategy: Get a HTTP header as a single string value. Each single
   * header value is converted to String using its toString method if a header
   * delegate is not available.
   */
@Test
public void getHeaderStringUsesToStringTest() throws Fault {
    final StringBean bean = new StringBean("bean");
    ClientRequestFilter filter = new ClientRequestFilter() {

        @Override
        public void filter(ClientRequestContext ctx) throws IOException {
            ctx.getHeaders().add(bean.get(), bean);
        }
    };
    setProperty(Property.REQUEST, buildRequest(Request.POST, "headerstring"));
    setProperty(Property.CONTENT, bean.get());
    addProvider(filter);
    setProperty(Property.SEARCH_STRING, bean.toString());
    invoke();
    logMsg("#getHeaderString() returned expected header converted by toString() method");
}
Also used : ClientRequestFilter(jakarta.ws.rs.client.ClientRequestFilter) ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) Test(org.junit.jupiter.api.Test)

Example 8 with StringBean

use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method clientWriterTest.

/* Run test */
/*
   * @testName: clientWriterTest
   * 
   * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94;
   * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99;
   * JAXRS:SPEC:100; JAXRS:JAVADOC:754;
   * 
   * @test_Strategy: @Context available to providers
   * 
   * An instance can be injected into a class field or method parameter using
   * the @Context annotation.
   * 
   * The lifecycle of components registered using this class-based register(...)
   * method is fully managed by the JAX-RS implementation or any underlying IoC
   * container supported by the implementation.
   */
@Test
public void clientWriterTest() throws Fault {
    addProvider(StringBeanEntityProviderWithInjectables.class);
    setRequestContentEntity(new StringBean("stringbean"));
    setProperty(Property.REQUEST, buildRequest(Request.POST, "echo"));
    invoke();
    assertInjection("@Context injection did not work properly:");
}
Also used : StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) Test(org.junit.jupiter.api.Test)

Example 9 with StringBean

use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method clientReaderTest.

/*
   * @testName: clientReaderTest
   * 
   * @assertion_ids: JAXRS:SPEC:93; JAXRS:SPEC:93.3; JAXRS:SPEC:94;
   * JAXRS:SPEC:95; JAXRS:SPEC:96; JAXRS:SPEC:97; JAXRS:SPEC:98; JAXRS:SPEC:99;
   * JAXRS:SPEC:100; JAXRS:JAVADOC:754;
   * 
   * @test_Strategy: @Context available to providers
   * 
   * An instance can be injected into a class field or method parameter using
   * the @Context annotation.
   * 
   * The lifecycle of components registered using this class-based register(...)
   * method is fully managed by the JAX-RS implementation or any underlying IoC
   * container supported by the implementation.
   */
@Test
public void clientReaderTest() throws Fault {
    addProvider(StringBeanEntityProviderWithInjectables.class);
    setRequestContentEntity("stringbean");
    setProperty(Property.REQUEST, buildRequest(Request.POST, "echo"));
    invoke();
    StringBean content = getResponseBody(StringBean.class);
    assertNotNull(content, "response body is null");
    logMsg("Injectables are", content.get());
    assertInjection(content.get(), "@Context injection did not work properly:");
}
Also used : StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean) Test(org.junit.jupiter.api.Test)

Example 10 with StringBean

use of ee.jakarta.tck.ws.rs.common.provider.StringBean in project jaxrs-api by eclipse-ee4j.

the class TextPlainStringBeanEntityProvider 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() + MediaType.TEXT_PLAIN_TYPE.getType() + "/");
    return bean;
}
Also used : StringBean(ee.jakarta.tck.ws.rs.common.provider.StringBean)

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