Search in sources :

Example 11 with RuntimeDelegate

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

the class JAXRSDelegateClient method assertRuntimeDelegate.

/**
 * Check what is the RuntimeDelegate
 *
 * @param wantTckRuntimeDelegate
 * @throws Fault
 *           when wantTckRuntimeDelegate && RuntimeDelegate.getInstance !=
 *           TckRuntimeDelegate when !wantTckRuntimeDelegate &&
 *           RuntimeDelegate.getInstance == TckRuntimeDelegate
 */
protected void assertRuntimeDelegate(boolean wantTckRuntimeDelegate) throws Fault {
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    Class<? extends RuntimeDelegate> clazz = delegate.getClass();
    boolean check = clazz == TckRuntimeDelegate.class;
    check = (wantTckRuntimeDelegate ? check : !check);
    assertTrue(check, "TckRuntimeDelegate was " + (wantTckRuntimeDelegate ? "" : " not ") + "set, got " + clazz.getName());
    logMsg("Found", clazz.getName());
}
Also used : RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate)

Example 12 with RuntimeDelegate

use of jakarta.ws.rs.ext.RuntimeDelegate 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 13 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: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 14 with RuntimeDelegate

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

the class Resource method setOriginalRuntime.

// We need to switch back to the original runtime delegate since
// we cannot be sure what happen when the war with our runtimedelegate gets
// undeployed
@Path("setoriginalruntime")
@GET
public Response setOriginalRuntime() {
    ResponseBuilder builder = createResponseWithHeader();
    RuntimeDelegate stringBeanDelegate = RuntimeDelegate.getInstance();
    if (stringBeanDelegate instanceof StringBeanRuntimeDelegate) {
        RuntimeDelegate original = ((StringBeanRuntimeDelegate) stringBeanDelegate).getOriginal();
        RuntimeDelegate.setInstance(original);
    } else
        builder = builder.status(Status.NO_CONTENT);
    return builder.build();
}
Also used : StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) StringBeanRuntimeDelegate(ee.jakarta.tck.ws.rs.common.provider.StringBeanRuntimeDelegate) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 15 with RuntimeDelegate

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

the class ReturnTypeTest method entityResponseTest.

@GET
@Path("entitybodyresponsetest")
public Response entityResponseTest() {
    RuntimeDelegate rd = RuntimeDelegate.getInstance();
    ResponseBuilder rb = rd.createResponseBuilder();
    ReadableWritableEntity rwe = entityTest();
    return rb.entity(rwe).build();
}
Also used : ReadableWritableEntity(ee.jakarta.tck.ws.rs.ee.rs.ext.messagebodyreaderwriter.ReadableWritableEntity) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) RuntimeDelegate(jakarta.ws.rs.ext.RuntimeDelegate) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

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