Search in sources :

Example 91 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method startAsyncInvokerForMethod.

// ///////////////////////////////////////////////////////////////////////
// utility methods
/**
 * Create AsyncInvoker for given resource method and start time
 */
protected AsyncInvoker startAsyncInvokerForMethod(String methodName) {
    Client client = createClient();
    client.register(new JdkLoggingFilter(false));
    WebTarget target = client.target(getAbsoluteUrl(methodName));
    AsyncInvoker async = target.request().async();
    setStartTime();
    return async;
}
Also used : JdkLoggingFilter(ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter) AsyncInvoker(jakarta.ws.rs.client.AsyncInvoker) WebTarget(jakarta.ws.rs.client.WebTarget) Client(jakarta.ws.rs.client.Client)

Example 92 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method closeTest.

/*
   * @testName: closeTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:841;
   * 
   * @test_Strategy: Close the message entity input stream (if available and
   * open). This operation is idempotent, i.e. it can be invoked multiple times
   * with the same effect which also means that calling the method on an already
   * closed message instance is legal and has no further effect
   */
@Test
public void closeTest() throws Fault {
    // make new Client, the one from super class calls bufferEntity()
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
    Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
    // calling the method on an already closed message
    response.close();
    // instance is legal
    response.close();
    // closed response will result in an IllegalStateException being thrown
    try {
        String entity = response.readEntity(String.class);
        assertTrue(false, "IllegalStateException has not been thrown when" + "#close() and #readEntity() but entity" + entity + "has been read");
    } catch (IllegalStateException e) {
        logMsg("#close() closed the stream, and consecutive reading threw IllegalStateException as expected");
    }
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Example 93 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method checkConfig.

protected void checkConfig(Registrar registrar, Assertable assertable, Object[] registerables) throws Fault {
    Entity<String> entity = Entity.entity("echo", MediaType.WILDCARD_TYPE);
    Client client = ClientBuilder.newClient();
    logMsg("Registering on Client");
    register(registrar, client, registerables[0]);
    WebTarget target = client.target(getAbsoluteUrl());
    logMsg("Registering on WebTarget");
    register(registrar, target, registerables[1]);
    Invocation.Builder builder = target.request();
    Invocation invocation = builder.buildPost(entity);
    String response = invocation.invoke(String.class);
    assertEquals(entity.getEntity(), response, "Unexpected response received", response);
    assertable.check1OnClient(client);
    assertable.incrementLocation();
    assertable.check2OnTarget(target);
}
Also used : Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client)

Example 94 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method isEnabledClassReturningFalseTest.

/*
   * @testName: isEnabledClassReturningFalseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:1000; JAXRS:JAVADOC:1003;
   * 
   * @test_Strategy: Check if a feature instance of featureClass class has been
   * previously enabled in the runtime configuration context.
   * 
   * Returns true if the feature was successfully enabled, false otherwise
   */
@SuppressWarnings("unchecked")
@Test
public void isEnabledClassReturningFalseTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningFalse1();
    final CheckingFeature feature2 = new FeatureReturningFalse2();
    final CheckingFeature feature3 = new FeatureReturningFalse3();
    final CheckingFeature feature4 = new FeatureReturningFalse4();
    feature1.addDisabledClasses(FeatureReturningFalse2.class, FeatureReturningFalse3.class, FeatureReturningFalse4.class).setName("feature1");
    feature2.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse3.class, FeatureReturningFalse4.class).setName("feature2");
    feature3.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse2.class, FeatureReturningFalse4.class).setName("feature3");
    feature4.addDisabledClasses(FeatureReturningFalse1.class, FeatureReturningFalse2.class, FeatureReturningFalse3.class).setName("feature4");
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            assertIsDisabled(client, feature1);
            assertIsDisabled(client, feature2);
            assertIsDisabled(client, feature3);
            assertIsDisabled(client, feature4);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            assertIsDisabled(target, feature1);
            assertIsDisabled(target, feature2);
            assertIsDisabled(target, feature3);
            assertIsDisabled(target, feature4);
        }

        void assertIsDisabled(Configurable<?> config, CheckingFeature feature) throws Fault {
            boolean isEnabled = config.getConfiguration().isEnabled(feature);
            assertFalse(isEnabled, "Feature" + feature.getName() + "is unexpectedly enabled" + getLocation());
            logMsg("No feature enabled as expected", getLocation());
        }
    };
    Object[] instances = { feature1, feature2, feature3, feature4 };
    checkConfig(assertable, instances);
    logMsg("The provider with unassignable contract has ben ignored as expected");
}
Also used : 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) WebTarget(jakarta.ws.rs.client.WebTarget) Configurable(jakarta.ws.rs.core.Configurable) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Example 95 with WebTarget

use of jakarta.ws.rs.client.WebTarget in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method isEnabledFeatureReturningFalseTest.

/* Run test */
/*
   * @testName: isEnabledFeatureReturningFalseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:999; JAXRS:JAVADOC:1003;
   * 
   * @test_Strategy: Check if a feature instance of featureClass class has been
   * previously enabled in the runtime configuration context.
   * 
   * Returns true if the feature was successfully enabled, false otherwise
   */
@Test
public void isEnabledFeatureReturningFalseTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningFalse1();
    final CheckingFeature feature2 = new FeatureReturningFalse2();
    final CheckingFeature feature3 = new FeatureReturningFalse3();
    final CheckingFeature feature4 = new FeatureReturningFalse4();
    feature1.addDisabledFeatures(feature2, feature3, feature4).setName("feature1");
    feature2.addDisabledFeatures(feature1, feature3, feature4).setName("feature2");
    feature3.addDisabledFeatures(feature1, feature2, feature4).setName("feature3");
    feature4.addDisabledFeatures(feature1, feature2, feature3).setName("feature4");
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            assertIsDisabled(client, feature1);
            assertIsDisabled(client, feature2);
            assertIsDisabled(client, feature3);
            assertIsDisabled(client, feature4);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            assertIsDisabled(target, feature1);
            assertIsDisabled(target, feature2);
            assertIsDisabled(target, feature3);
            assertIsDisabled(target, feature4);
        }

        void assertIsDisabled(Configurable<?> config, CheckingFeature feature) throws Fault {
            boolean isEnabled = config.getConfiguration().isEnabled(feature);
            assertFalse(isEnabled, "Feature" + feature.getName() + "is unexpectedly enabled" + getLocation());
            logMsg("No feature enabled as expected", getLocation());
        }
    };
    Object[] instances = { feature1, feature2, feature3, feature4 };
    checkConfig(assertable, instances);
    logMsg("The provider with unassignable contract has ben ignored as expected");
}
Also used : 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) WebTarget(jakarta.ws.rs.client.WebTarget) Configurable(jakarta.ws.rs.core.Configurable) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client) Test(org.junit.jupiter.api.Test)

Aggregations

WebTarget (jakarta.ws.rs.client.WebTarget)96 Test (org.junit.jupiter.api.Test)63 Client (jakarta.ws.rs.client.Client)52 JAXRSCommonClient (ee.jakarta.tck.ws.rs.common.JAXRSCommonClient)27 Response (jakarta.ws.rs.core.Response)24 Configuration (jakarta.ws.rs.core.Configuration)17 URI (java.net.URI)17 Invocation (jakarta.ws.rs.client.Invocation)16 Assertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.Assertable)14 SingleCheckAssertable (ee.jakarta.tck.ws.rs.api.rs.core.configurable.SingleCheckAssertable)14 JaxrsCommonClient (ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient)14 HashMap (java.util.HashMap)8 JdkLoggingFilter (ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter)6 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)5 InboundSseEvent (jakarta.ws.rs.sse.InboundSseEvent)5 SseEventSource (jakarta.ws.rs.sse.SseEventSource)5 ConfigurableObject (ee.jakarta.tck.ws.rs.api.rs.core.configurable.ConfigurableObject)4 LinkedHolder (ee.jakarta.tck.ws.rs.common.util.LinkedHolder)4 Configurable (jakarta.ws.rs.core.Configurable)4 ThrottledClient (jaxrs.examples.client.custom.ThrottledClient)4