Search in sources :

Example 21 with WebTarget

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

the class JAXRSClientIT method queryParamNullValueTest.

/*
   * @testName: queryParamNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:618;
   * 
   * @test_Strategy: In case a single null value is entered, all parameters with
   * that name are removed (if present) from the collection of query parameters
   * inherited from the current target.
   */
@Test
public void queryParamNullValueTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.path("path").queryParam("paramName", new StringBuffer().append("value1"), new StringBuilder().append("value2"), "value3");
    assertConfigurationSnapshot(target);
    target = target.queryParam("param", (Object[]) null).path("path2");
    URI uri = target.getUri();
    assertUriContains(uri, "/path/path2");
    logMsg("#paramName(name, null) removed values as expected");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 22 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesWithBooleanTrueReturnsTheSameTargetTest.

/*
   * @testName: resolveTemplatesWithBooleanTrueReturnsTheSameTargetTest
   * 
   * @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 resolveTemplatesWithBooleanTrueReturnsTheSameTargetTest() throws Fault {
    WebTarget target = createWebTarget();
    target = target.path("{path}");
    WebTarget other = target.resolveTemplates(new TreeMap<String, Object>(), true);
    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 23 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesFromEncodedTest.

/*
   * @testName: resolveTemplatesFromEncodedTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:950;
   * 
   * @test_Strategy: Create a new WebTarget instance by resolving a URI template
   * with a given name in the URI of the current target instance using a
   * supplied encoded value. A template with a matching name will be replaced by
   * the supplied value. Value is converted to String using its toString()
   * method and is then encoded to match the rules of the URI component to which
   * they pertain. All % characters in the stringified values that are not
   * followed by two hexadecimal numbers will be encoded.
   */
@Test
public void resolveTemplatesFromEncodedTest() throws Fault {
    WebTarget target = createWebTarget();
    StringBuilder sb = new StringBuilder();
    sb.append(ENCODED);
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("path", sb);
    target = target.path("{path}").resolveTemplatesFromEncoded(map);
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, "/" + ENCODED.replace("%%", "%25%"));
    logMsg("URI", uri, "contains given path parameter");
}
Also used : HashMap(java.util.HashMap) WebTarget(jakarta.ws.rs.client.WebTarget) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 24 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesNullValueTest.

/*
   * @testName: resolveTemplatesNullValueTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:946;
   * 
   * @test_Strategy: NullPointerException - if the name-value map or any of the
   * names or values in the map is null.
   */
@Test
public void resolveTemplatesNullValueTest() throws Fault {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("path", null);
    WebTarget target = createWebTarget();
    try {
        target.path("{path}").resolveTemplates(map);
        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 25 with WebTarget

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

the class JAXRSClientIT method resolveTemplatesWithBooleanFalseTest.

/*
   * @testName: resolveTemplatesWithBooleanFalseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:948;
   * 
   * @test_Strategy: Create a new WebTarget instance by resolving one or more
   * URI templates in the URI of the current target instance using supplied
   * name-value pairs. A call to the method with an empty parameter map is
   * ignored, i.e. same WebTarget instance is returned. A snapshot of the
   * present configuration of the current (parent) target instance is taken and
   * is inherited by the newly constructed (child) target instance.
   */
@Test
public void resolveTemplatesWithBooleanFalseTest() throws Fault {
    Map<String, Object> map = new TreeMap<String, Object>();
    map.put("path", new StringBuilder().append("lane"));
    map.put("highway", new StringBuffer().append("route66"));
    map.put("sidewalk", "pavement");
    WebTarget target = createWebTarget();
    target = target.path("{path}").path("{highway}").path("{sidewalk}");
    target = target.resolveTemplates(map, false);
    assertConfigurationSnapshot(target);
    URI uri = target.getUri();
    assertUriContains(uri, "/lane/route66/pavement");
    logMsg("URI", uri, "contains given path parameters");
}
Also used : WebTarget(jakarta.ws.rs.client.WebTarget) TreeMap(java.util.TreeMap) URI(java.net.URI) 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