Search in sources :

Example 81 with WebTarget

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

the class JAXRSClientIT method readEntityGenericTypeAnnotationThrowsIllegalStateExceptionTest.

/*
   * @testName: readEntityGenericTypeAnnotationThrowsIllegalStateExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:872;
   * 
   * @test_Strategy: if the entity is not backed by an input stream, or if the
   * entity input stream has been fully consumed already and has not been
   * buffered prior consuming.
   */
@Test
public void readEntityGenericTypeAnnotationThrowsIllegalStateExceptionTest() throws Fault {
    Annotation[] annotations = AnnotatedClass.class.getAnnotations();
    // create a new client
    Client client = ClientBuilder.newClient();
    WebTarget target = // with no bufferEntity called
    client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
    Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
    String entity = response.readEntity(generic(String.class), annotations);
    assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(GenericType<String>, annotations)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
    try {
        response.readEntity(generic(Reader.class), annotations);
        throw new Fault("No exception has been thrown when reader for entity is not buffered");
    } catch (IllegalStateException e) {
        logMsg("IllegalStateException has been thrown as expected");
    }
}
Also used : Response(jakarta.ws.rs.core.Response) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) WebTarget(jakarta.ws.rs.client.WebTarget) JaxrsCommonClient(ee.jakarta.tck.ws.rs.common.client.JaxrsCommonClient) Client(jakarta.ws.rs.client.Client) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Example 82 with WebTarget

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

the class JAXRSClientIT method readEntityClassThrowsIllegalStateExceptionTest.

/*
   * @testName: readEntityClassThrowsIllegalStateExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:863;
   * 
   * @test_Strategy: if the entity is not backed by an input stream, or if the
   * entity input stream has been fully consumed already and has not been
   * buffered prior consuming.
   */
@Test
public void readEntityClassThrowsIllegalStateExceptionTest() throws Fault {
    // create a new client
    Client client = ClientBuilder.newClient();
    WebTarget target = // with no bufferEntity called
    client.target("http://" + _hostname + ":" + _port + getContextRoot()).path("entity");
    Response response = target.request(MediaType.TEXT_PLAIN_TYPE).buildGet().invoke();
    String entity = response.readEntity(String.class);
    assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(String.class)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
    try {
        response.readEntity(Reader.class);
        throw new Fault("No exception has been thrown when reader for entity is not buffered");
    } catch (IllegalStateException e) {
        logMsg("IllegalStateException has been thrown 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 83 with WebTarget

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

the class JAXRSClientIT method checkConfig.

protected Invocation checkConfig(Registrar registrar, Assertable assertable, Object[] registerables, Entity<?> entity) throws Fault {
    Client client = ClientBuilder.newClient();
    Configuration config = client.getConfiguration();
    registeredClassesCnt = config.getClasses().size();
    registeredInstancesCnt = config.getInstances().size();
    logMsg("Already registered", registeredClassesCnt, "classes");
    logMsg("Already registered", registeredInstancesCnt, "instances");
    register(registrar, client, registerables[0]);
    assertable.check1OnClient(client);
    assertable.incrementLocation();
    WebTarget target = client.target(getAbsoluteUrl());
    register(registrar, target, registerables[1]);
    assertable.check2OnTarget(target);
    assertable.incrementLocation();
    Invocation.Builder builder = target.request();
    Invocation invocation = builder.buildPost(entity);
    return invocation;
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) 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 84 with WebTarget

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

the class JAXRSClientIT method isEnabledFeatureReturningTrueTest.

/*
   * @testName: isEnabledFeatureReturningTrueTest
   * 
   * @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 isEnabledFeatureReturningTrueTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningTrue1();
    final CheckingFeature feature2 = new FeatureReturningTrue2();
    final CheckingFeature feature3 = new FeatureReturningTrue3();
    final CheckingFeature feature4 = new FeatureReturningTrue4();
    feature1.addDisabledFeatures(feature2, feature3, feature4).setName("feature1");
    feature2.addDisabledFeatures(feature3, feature4).addEnabledFeatures(feature1).setName("feature2");
    feature3.addDisabledFeatures(feature4).addEnabledFeatures(feature1, feature2).setName("feature3");
    feature4.addEnabledFeatures(feature1, feature2, feature3).setName("feature4");
    Assertable assertable = new Assertable() {

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

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

        void assertIsRegistered(Configurable<?> config, CheckingFeature feature) throws Fault {
            Configuration configuration = config.getConfiguration();
            assertTrue(configuration.isRegistered(feature), "Feature" + feature.getName() + "is NOT registered" + getLocation());
            logMsg("Feature", feature.getName(), "registered as expected", getLocation());
        }

        void assertIsNotRegistered(Configurable<?> config, CheckingFeature feature) throws Fault {
            Configuration configuration = config.getConfiguration();
            assertFalse(configuration.isRegistered(feature), "Feature" + feature.getName() + "is unexpectedly registered" + getLocation());
            logMsg("Feature", feature.getName(), "NOT registered 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 : Configuration(jakarta.ws.rs.core.Configuration) 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 85 with WebTarget

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

the class JAXRSClientIT method imutableWithRespectToUriQueryResolveTemplateTest.

/*
   * @testName: imutableWithRespectToUriQueryResolveTemplateTest
   * 
   * @assertion_ids: JAXRS:SPEC:66;
   * 
   * @test_Strategy: WebTarget instances are immutable with respect to their URI
   * (or URI template): methods for specifying additional path segments and
   * parameters return a new instance of WebTarget.
   */
@Test
public void imutableWithRespectToUriQueryResolveTemplateTest() throws Fault {
    IteratedList<WebTarget> targets = new IteratedList<WebTarget>(WebTarget.class);
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("");
    targets.add(target);
    targets.doWithAll("queryParam", "", new String[] { "" });
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("queryParam", "path", new String[] { "xyz" });
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("queryParam", "xyz", new String[] { "path" });
    assertFaultEqualWebTargets(targets);
    TestUtil.logMsg("checked queryParam() method");
    targets.doWithAll("resolveTemplateFromEncoded", "", "");
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("resolveTemplateFromEncoded", "path", "xyz");
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("resolveTemplateFromEncoded", "path/path/path", "");
    assertFaultEqualWebTargets(targets);
    TestUtil.logMsg("checked resolveTemplateFromEncoded() method");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("", "path");
    targets.doWithAll("resolveTemplates", params);
    assertFaultEqualWebTargets(targets);
    params = new HashMap<String, Object>();
    params.put("path", "xyz");
    targets.doWithAll("resolveTemplates", params);
    assertFaultEqualWebTargets(targets);
    TestUtil.logMsg("checked resolveTemplates() method");
    targets.doWithAll("resolveTemplatesFromEncoded", params);
    assertFaultEqualWebTargets(targets);
    params = new HashMap<String, Object>();
    params.put("path", "xyz");
    targets.doWithAll("resolveTemplatesFromEncoded", params);
    assertFaultEqualWebTargets(targets);
    TestUtil.logMsg("checked resolveTemplatesFromEncoded() method");
}
Also used : HashMap(java.util.HashMap) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.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