Search in sources :

Example 1 with RuntimeDelegate

use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getStringHeadersUsingHeaderDelegateTest.

/*
   * @testName: getStringHeadersUsingHeaderDelegateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:446; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get a string view of header values associated with the
   * message. The method converts the non-string header values to strings using
   * a RuntimeDelegate.HeaderDelegate
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getStringHeadersUsingHeaderDelegateTest() throws Fault {
    final String TCK = "cts";
    final StringBean bean = new StringBean(TCK);
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            MultivaluedMap<String, String> map;
            map = context.getStringHeaders();
            StringBuilder value = new StringBuilder();
            value.append(map.getFirst(TCK));
            Response r = Response.ok(value.toString()).build();
            context.abortWith(r);
        }
    };
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(delegate));
    try {
        Invocation invocation = buildBuilder(provider).header(TCK, bean).buildGet();
        Response response = invoke(invocation);
        String body = response.readEntity(String.class);
        assertContains(body, TCK);
    } finally {
        RuntimeDelegate.setInstance(delegate);
        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 2 with RuntimeDelegate

use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getStringHeadersUsingHeaderDelegateTest.

/*
   * @testName: getStringHeadersUsingHeaderDelegateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:859;
   * 
   * @test_Strategy: Get view of the response headers and their string values.
   * Each single header value is converted to String using a
   * RuntimeDelegate.HeaderDelegate or using its toString
   */
@Test
public void getStringHeadersUsingHeaderDelegateTest() throws Fault {
    RuntimeDelegate original = RuntimeDelegate.getInstance();
    RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(original));
    try {
        StringBuilder builder = new StringBuilder("s1");
        StringBuffer buffer = new StringBuffer("s2");
        StringBean bean = new StringBean("s3");
        Response response = Response.ok().header(builder.toString(), builder).header(buffer.toString(), buffer).header(bean.get(), bean).build();
        MultivaluedMap<String, String> headers = response.getStringHeaders();
        String header = headers.getFirst(bean.get());
        assertContainsIgnoreCase(bean.get(), header, "Header", bean.get(), "has unexpected value", header);
        logMsg("#getStringHeaders contains expected values", JaxrsUtil.iterableToString(",", headers.entrySet()));
    } finally {
        RuntimeDelegate.setInstance(original);
        StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) 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 3 with RuntimeDelegate

use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method getHeaderStringUsingHeaderDelegateTest.

/*
   * @testName: getHeaderStringUsingHeaderDelegateTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:849;
   * 
   * @test_Strategy: Get a message header as a single string value. Each single
   * header value is converted to String using a RuntimeDelegate.HeaderDelegate
   * or using its toString
   */
@Test
public void getHeaderStringUsingHeaderDelegateTest() throws Fault {
    StringBean bean = new StringBean("s3");
    RuntimeDelegate original = RuntimeDelegate.getInstance();
    RuntimeDelegate.setInstance(new StringBeanRuntimeDelegate(original));
    try {
        Response response = Response.ok().header(bean.get(), bean).build();
        String header = response.getHeaderString(bean.get());
        assertContainsIgnoreCase(header, bean.get(), "Header", bean.get(), "has unexpected value", header);
        logMsg("HeaderDelegate is used for header", bean.get());
    } finally {
        RuntimeDelegate.setInstance(original);
        StringBeanRuntimeDelegate.assertNotStringBeanRuntimeDelegate();
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) 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 4 with RuntimeDelegate

use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.

the class StringBeanRuntimeDelegate method assertNotStringBeanRuntimeDelegate.

public static final void assertNotStringBeanRuntimeDelegate() {
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    assertNotStringBeanRuntimeDelegate(delegate);
}
Also used : RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate)

Example 5 with RuntimeDelegate

use of jakarta.ws.rs.ext.RuntimeDelegate in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method createEndpointTest.

/*
   * @testName: createEndpointTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:284; JAXRS:JAVADOC:285; JAXRS:JAVADOC:286;
   * 
   * @test_Strategy: Create a configured instance of the supplied endpoint type.
   * How the returned endpoint instance is published is dependent on the type of
   * endpoint.
   * 
   * IllegalArgumentException - if application is null or the requested endpoint
   * type is not supported. UnsupportedOperationException - if the
   * implementation supports no endpoint types.
   * 
   * Note that these assertions are almost untestable, as it can either create
   * an instance or throw one exception or the other.
   */
@Test
public void createEndpointTest() throws Fault {
    Application application = new Application() {

        public java.util.Set<java.lang.Class<?>> getClasses() {
            java.util.Set<java.lang.Class<?>> set = new HashSet<Class<?>>();
            set.add(Resource.class);
            return set;
        }
    };
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    HttpHandler handler = null;
    try {
        handler = delegate.createEndpoint(application, com.sun.net.httpserver.HttpHandler.class);
    } catch (IllegalArgumentException e) {
        logMsg("IllegalArgumentException has been thrown as expected", e);
        return;
    } catch (UnsupportedOperationException e) {
        logMsg("UnsupportedOperationException has been thrown as expected", e);
        return;
    }
    assertNotNull(handler, "HttpHandler end point should be created, or an exception thrown otherwise");
    logMsg("HttpHandler endpoint has been sucessfully created");
}
Also used : HttpHandler(com.sun.net.httpserver.HttpHandler) Application(jakarta.ws.rs.core.Application) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)16 StringBeanRuntimeDelegate (ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate)10 Test (org.junit.jupiter.api.Test)8 Response (jakarta.ws.rs.core.Response)7 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)6 GET (jakarta.ws.rs.GET)6 Path (jakarta.ws.rs.Path)6 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)3 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)3 Invocation (jakarta.ws.rs.client.Invocation)2 HttpHandler (com.sun.net.httpserver.HttpHandler)1 TckRuntimeDelegate (ee.jakarta.tck.ws.rs.api.rs.ext.runtimedelegate.TckRuntimeDelegate)1 ReadableWritableEntity (ee.jakarta.tck.ws.rs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity)1 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)1 Application (jakarta.ws.rs.core.Application)1 HashSet (java.util.HashSet)1