Search in sources :

Example 36 with WebTarget

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

the class JAXRSClientIT method readEntityGenericTypeThrowsIllegalStateExceptionTest.

/*
   * @testName: readEntityGenericTypeThrowsIllegalStateExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:866;
   * 
   * @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 readEntityGenericTypeThrowsIllegalStateExceptionTest() 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(generic(String.class));
    assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(GenericType<byte[]>)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
    try {
        response.readEntity(generic(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) 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) Test(org.junit.jupiter.api.Test)

Example 37 with WebTarget

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

the class JAXRSClientIT method readEntityClassAnnotationThrowsIllegalStateExceptionTest.

/*
   * @testName: readEntityClassAnnotationThrowsIllegalStateExceptionTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:869;
   * 
   * @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 readEntityClassAnnotationThrowsIllegalStateExceptionTest() 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(String.class, annotations);
    assertTrue(ResponseTest.ENTITY.equals(entity), "#readEntity(String.class, annotations)={" + entity + "} differs from expected" + ResponseTest.ENTITY);
    try {
        response.readEntity(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) 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 38 with WebTarget

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

the class JAXRSClientIT method isEnabledFeatureClassReturningTrueTest.

/*
   * @testName: isEnabledFeatureClassReturningTrueTest
   * 
   * @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 isEnabledFeatureClassReturningTrueTest() throws Fault {
    final CheckingFeature feature1 = new FeatureReturningTrue1();
    final CheckingFeature feature2 = new FeatureReturningTrue2();
    final CheckingFeature feature3 = new FeatureReturningTrue3();
    final CheckingFeature feature4 = new FeatureReturningTrue4();
    feature1.addDisabledClasses(FeatureReturningTrue2.class, FeatureReturningTrue3.class, FeatureReturningTrue4.class).setName("feature1");
    feature2.addDisabledClasses(FeatureReturningTrue3.class, FeatureReturningTrue4.class).addEnabledClasses(FeatureReturningTrue1.class).setName("feature2");
    feature3.addDisabledClasses(FeatureReturningTrue4.class).addEnabledClasses(FeatureReturningTrue1.class, FeatureReturningTrue2.class).setName("feature3");
    feature4.addEnabledClasses(FeatureReturningTrue1.class, FeatureReturningTrue2.class, FeatureReturningTrue3.class).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 39 with WebTarget

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

the class JAXRSClientIT method imutableWithRespectToUriMatrixPathTest.

/* Run test */
/*
   * @testName: imutableWithRespectToUriMatrixPathTest
   * 
   * @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 imutableWithRespectToUriMatrixPathTest() throws Fault {
    IteratedList<WebTarget> targets = new IteratedList<WebTarget>(WebTarget.class);
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("");
    targets.add(target);
    targets.doWithAll("matrixParam", "", new String[] { "" });
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("matrixParam", "matrix", new String[] { "st" });
    assertFaultEqualWebTargets(targets);
    TestUtil.logMsg("checked matrixParam() method");
    targets.doWithAll("path", "");
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("path", "/");
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("path", "path");
    assertFaultEqualWebTargets(targets);
    targets.doWithAll("path", "path/path/path");
    assertFaultEqualWebTargets(targets);
    TestUtil.logMsg("checked path() method");
}
Also used : 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)

Example 40 with WebTarget

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

the class JAXRSClientIT method startBuilderForMethod.

protected Invocation.Builder startBuilderForMethod(String methodName) {
    Client client = ClientBuilder.newClient();
    client.register(new JdkLoggingFilter(false));
    WebTarget target = client.target(getAbsoluteUrl(methodName));
    Invocation.Builder ib = target.request();
    return ib;
}
Also used : JdkLoggingFilter(ee.jakarta.tck.ws.rs.common.client.JdkLoggingFilter) Invocation(jakarta.ws.rs.client.Invocation) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

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