Search in sources :

Example 86 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method registerObjectWriterContractsInMapTest.

/*
   * @testName: registerObjectWriterContractsInMapTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:990;
   * 
   * @test_Strategy: This registration method provides same functionality as
   * register(Object, Class[]) except that any binding priority specified on the
   * registered JAX-RS component class using @Priority annotation is overridden
   * for each extension provider contract type separately with an integer
   * binding priority value specified as a value in the supplied map.
   */
@Test
public void registerObjectWriterContractsInMapTest() throws Fault {
    final String content = "registerObjectWriterContractsInMapTest";
    Object[] instances = createProviderInstances();
    // entity to send to a server
    Entity<?> entity = getCallableEntity(content);
    // register only once per client build
    IncrementableRegistrar registrar = new IncrementableRegistrar(0, 1) {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            if (currentValue++ == finalValue) {
                Map<Class<?>, Integer> contracts = new HashMap<Class<?>, Integer>();
                contracts.put(MessageBodyWriter.class, 100);
                config.register(registerable, contracts);
            }
        }
    };
    setResourceMethod("echo");
    // configurable each time
    for (int cnt = 0; cnt != configurableCnt; cnt++) {
        // Check the provider is registered
        logMsg("Check on Configurable", Assertable.getLocation(cnt));
        Assertable assertable = getAssertableWithRegisteredProviderInstancesOnConfigurable(cnt, 1);
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Invocation i = checkConfig(registrar, assertable, instances, entity);
        Response response = i.invoke();
        response.bufferEntity();
        String responseString = response.readEntity(String.class);
        assertEquals(content, responseString, "Expected", content, "differs from given", response);
        logMsg("sucessufully wrote Callable by provider registered on Configurable", Assertable.getLocation(cnt));
        // check message body reader contract
        try {
            Callable<?> callable = response.readEntity(Callable.class);
            fault("MessageBodyReader contract has been unexpectedly registered", callable);
        } catch (Exception e) {
            logMsg("MessageBodyReader contract has not been registered as expected", e);
        }
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) HashMap(java.util.HashMap) Configurable(jakarta.ws.rs.core.Configurable) IOException(java.io.IOException) Response(jakarta.ws.rs.core.Response) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) ConfigurableObject(ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject) Test(org.junit.jupiter.api.Test)

Example 87 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method registerObjectReaderContractsTest.

/*
   * @testName: registerObjectReaderContractsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:760;
   * 
   * @test_Strategy: This registration method provides the same functionality as
   * register(Object) except the JAX-RS component class is only registered as a
   * provider of the listed extension provider or meta-provider contracts.
   */
@Test
public void registerObjectReaderContractsTest() throws Fault {
    final String content = "registerClassReaderContractsTest";
    Object[] instances = createProviderInstances();
    // entity to send to a server
    Entity<?> entity = Entity.entity(content, MediaType.WILDCARD);
    // register only once per client build
    IncrementableRegistrar registrar = new IncrementableRegistrar(0, 1) {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            if (currentValue++ == finalValue)
                config.register(registerable, MessageBodyReader.class);
        }
    };
    setResourceMethod("echo");
    // configurable each time
    for (int cnt = 0; cnt != configurableCnt; cnt++) {
        // Check the provider is registered
        logMsg("Check on Configurable", Assertable.getLocation(cnt));
        Assertable assertable = getAssertableWithRegisteredProviderInstancesOnConfigurable(cnt, 1);
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Invocation i = checkConfig(registrar, assertable, instances, entity);
        Response response = i.invoke();
        Callable<?> callable = response.readEntity(Callable.class);
        assertEquals(content, callable.toString(), "Expected", content, "differs from given", response);
        logMsg("sucessufully read Callable by provider registered on Configurable", Assertable.getLocation(cnt));
    }
}
Also used : Response(jakarta.ws.rs.core.Response) MessageBodyReader(jakarta.ws.rs.ext.MessageBodyReader) Invocation(jakarta.ws.rs.client.Invocation) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) ConfigurableObject(ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject) Configurable(jakarta.ws.rs.core.Configurable) Test(org.junit.jupiter.api.Test)

Example 88 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method registerClassWriterContractsTest.

/* Run test */
/*
   * @testName: registerClassWriterContractsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:756;
   * 
   * @test_Strategy: This registration method provides the same functionality as
   * register(Class) except the JAX-RS component class is only registered as a
   * provider of the listed extension provider or meta-provider contracts.
   */
@Test
public void registerClassWriterContractsTest() throws Fault {
    final String content = "registerClassWriterContractsTest";
    Class<?>[] classes = createProviderClasses();
    // entity to send to a server
    Entity<?> entity = getCallableEntity(content);
    // register only once per client build
    IncrementableRegistrar registrar = new IncrementableRegistrar(0, 1) {

        @Override
        public void register(Configurable<?> config, Object registerable) {
            if (currentValue++ == finalValue)
                config.register((Class<?>) registerable, MessageBodyWriter.class);
        }
    };
    setResourceMethod("echo");
    // configurable each time
    for (int cnt = 0; cnt != configurableCnt; cnt++) {
        // Check the provider is registered
        logMsg("Check on Configurable", Assertable.getLocation(cnt));
        Assertable assertable = getAssertableWithRegisteredProviderClassesOnConfigurable(cnt, 1);
        // set we want to register the provider on Configurable
        // Assertable::LOCATION[cnt]
        registrar.setCurrentValue(0).setFinalValue(cnt);
        Invocation i = checkConfig(registrar, assertable, classes, entity);
        Response response = i.invoke();
        response.bufferEntity();
        String responseString = response.readEntity(String.class);
        assertEquals(content, responseString, "Expected", content, "differs from given", response);
        logMsg("sucessufully wrote Callable by provider registered on Configurable", Assertable.getLocation(cnt));
        // check message body reader contract
        try {
            Callable<?> callable = response.readEntity(Callable.class);
            fault("MessageBodyReader contract has been unexpectedly registered", callable);
        } catch (Exception e) {
            logMsg("MessageBodyReader contract has not been registered as expected", e);
        }
    }
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) Configurable(jakarta.ws.rs.core.Configurable) IOException(java.io.IOException) Response(jakarta.ws.rs.core.Response) Assertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable) SingleCheckAssertable(ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable) ConfigurableObject(ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject) MessageBodyWriter(jakarta.ws.rs.ext.MessageBodyWriter) Test(org.junit.jupiter.api.Test)

Example 89 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method dynamicFeatureIsRegisteredTest.

/*
   * @testName: dynamicFeatureIsRegisteredTest
   *
   * @assertion_ids: JAXRS:SPEC:137;
   *
   * @test_Strategy:
   */
@Test
public void dynamicFeatureIsRegisteredTest() throws Fault {
    try (Response response = ClientBuilder.newClient().target(getAbsoluteUrl("dynamicFeature")).request().get()) {
        assertEquals(200, response.getStatus());
        assertEquals(TckDynamicFeature.class.getName(), response.readEntity(String.class));
    } catch (Exception e) {
        fault(e);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 90 with Response

use of jakarta.ws.rs.core.Response in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method featureIsRegisteredTest.

/* Run test */
/*
   * @testName: featureIsRegisteredTest
   * 
   * @assertion_ids: JAXRS:SPEC:137;
   * 
   * @test_Strategy:
   */
@Test
public void featureIsRegisteredTest() throws Fault {
    try (Response response = ClientBuilder.newClient().target(getAbsoluteUrl("staticFeature")).request().get()) {
        assertEquals(200, response.getStatus());
        assertEquals(TckFeature.class.getName(), response.readEntity(String.class));
    } catch (Exception e) {
        fault(e);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)665 Test (org.junit.jupiter.api.Test)551 AsyncInvoker (jakarta.ws.rs.client.AsyncInvoker)78 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)71 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)67 Invocation (jakarta.ws.rs.client.Invocation)65 CompletionStageRxInvoker (jakarta.ws.rs.client.CompletionStageRxInvoker)51 Path (jakarta.ws.rs.Path)44 IOException (java.io.IOException)43 SyncInvoker (jakarta.ws.rs.client.SyncInvoker)41 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)33 POST (jakarta.ws.rs.POST)27 Client (jakarta.ws.rs.client.Client)25 WebTarget (jakarta.ws.rs.client.WebTarget)24 Link (jakarta.ws.rs.core.Link)23 Status (jakarta.ws.rs.core.Response.Status)23 MediaType (jakarta.ws.rs.core.MediaType)22 Annotation (java.lang.annotation.Annotation)22 Date (java.util.Date)21 GET (jakarta.ws.rs.GET)18