Search in sources :

Example 66 with WebTarget

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

the class JAXRSClientIT method getPropertiesIsImmutableTest.

/*
     * @testName: getPropertiesIsImmutableTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:995; JAXRS:JAVADOC:758;
     * 
     * @test_Strategy: Get the immutable bag of configuration properties. Set the
     * new configuration property
     */
@Test
public void getPropertiesIsImmutableTest() throws Fault {
    Assertable assertable = new Assertable() {

        @Override
        public void check1OnClient(Client client) throws Fault {
            setNewProperty(client.getConfiguration());
            assertSizeAndLog(client.getConfiguration(), 1);
        }

        @Override
        public void check2OnTarget(WebTarget target) throws Fault {
            setNewProperty(target.getConfiguration());
            assertSizeAndLog(target.getConfiguration(), 2);
        }

        void setNewProperty(Configuration config) {
            try {
                config.getProperties().put("property88", "property88");
            } catch (Exception e) {
            // can throw an exception or do nothing
            // or getProperties can be hard copy
            }
        }

        void assertSizeAndLog(Configuration config, int size) throws Fault {
            assertTrue(config.getProperties().size() == size + registeredPropertiesCnt, "getConfiguration().getProperties() is NOT immutable " + getLocation() + " got " + config.getProperties().size());
            logMsg("Found", config.getProperties().size(), " properties");
        }
    };
    checkConfigWithProperties(assertable);
}
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) 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 67 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 {
    Client client = ClientBuilder.newClient();
    Configuration config = client.getConfiguration();
    registeredPropertiesCnt = config.getProperties().size();
    registeredClassesCnt = config.getClasses().size();
    registeredInstancesCnt = config.getInstances().size();
    logMsg("Already registered", registeredClassesCnt, "classes");
    logMsg("Already registered", registeredInstancesCnt, "instances");
    logMsg("Already registered", registeredPropertiesCnt, "properties");
    register(registrar, client, registerables[0]);
    assertable.check1OnClient(client);
    assertable.incrementLocation();
    WebTarget target = client.target("http://tck.cts:888");
    register(registrar, target, registerables[1]);
    assertable.check2OnTarget(target);
    assertable.incrementLocation();
}
Also used : Configuration(jakarta.ws.rs.core.Configuration) WebTarget(jakarta.ws.rs.client.WebTarget) JAXRSCommonClient(ee.jakarta.tck.ws.rs.common.JAXRSCommonClient) Client(jakarta.ws.rs.client.Client)

Example 68 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesWithBooleanNullValueTest.

/*
   * @testName: resolveTemplatesWithBooleanNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:948;
   * 
   * @test_Strategy: NullPointerException - if the name-value map or any of the
   * names or values in the map is null.
   */
@Test
public void resolveTemplatesWithBooleanNullValueTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("path", null);
    WebTarget target = createWebTarget();
    try {
        target.path("{path}").resolveTemplates(map, true);
        throw new Fault("NullPointerException has not been thrown");
    } catch (NullPointerException npe) {
        logMsg("NullPointerException has been thrown as expected", npe);
    }
}
Also used : HashMap(java.util.HashMap) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 69 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesWithBooleanFalseReturnsTheSameTargetTest.

/*
   * @testName: resolveTemplatesWithBooleanFalseReturnsTheSameTargetTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:948;
   * 
   * @test_Strategy: A call to the method with an empty parameter map is
   * ignored, i.e. same WebTarget instance is returned.
   */
@Test
public void resolveTemplatesWithBooleanFalseReturnsTheSameTargetTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.path("{path}");
    WebTarget other = target.resolveTemplates(new TreeMap<String, Object>(), false);
    assertEquals(target, other, "#pathParams did not return the same target when the input map is empty");
    logMsg("#pathParams returned the same traget wehn empty as expected");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 70 with WebTarget

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

the class JAXRSClientIT method requestStringTest.

/*
   * @testName: requestStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:623;
   * 
   * @test_Strategy: Start building a request to the targeted web resource and
   * define the accepted response media types.
   */
@Test
public void requestStringTest() throws Fault {
    WebTarget target = createWebTarget();
    Response response = target.request(MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON, MediaType.TEXT_XML).buildGet().invoke();
    String body = response.readEntity(String.class);
    assertContains(body, URL);
    assertContains(body, MediaType.APPLICATION_ATOM_XML);
    assertContains(body, MediaType.APPLICATION_JSON);
    assertContains(body, MediaType.TEXT_XML);
}
Also used : Response(jakarta.ws.rs.core.Response) WebTarget(jakarta.ws.rs.client.WebTarget) 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