Search in sources :

Example 86 with WebTarget

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

the class JAXRSClientIT method webTargetConfigNotImpactClientTest.

/*
   * @testName: webTargetConfigNotImpactClientTest
   * 
   * @assertion_ids: JAXRS:SPEC:74;
   * 
   * @test_Strategy: However, any additional changes to the instance of
   * WebTarget will not impact the Client's configuration and vice versa.
   */
@Test
public void webTargetConfigNotImpactClientTest() throws Fault {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("resource");
    target.property("any", "some");
    Object property = client.getConfiguration().getProperty("any");
    assertTrue(property == null, "WebTarget config impacts Client config");
    client.property("some", "any");
    property = target.getConfiguration().getProperty("some");
    assertTrue(property == null, "Client config impacts WebTarget config");
}
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 87 with WebTarget

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

the class JAXRSClientIT method deepCopyConfigWebTargetLevelTest.

/*
   * @testName: deepCopyConfigWebTargetLevelTest
   * 
   * @assertion_ids: JAXRS:SPEC:68; JAXRS:SPEC:72; JAXRS:JAVADOC:988;
   * 
   * @test_Strategy: Note that changes to hello's configuration do not affect
   * base, i.e. configuration inheritance requires performing a deep copy of the
   * configuration.
   * 
   * The following Client API types are configurable: Client, Invocation,
   * Invocation.Builder and WebTarget.
   * 
   * Get access to the underlying Configuration configuration.
   */
@Test
public void deepCopyConfigWebTargetLevelTest() throws Fault {
    Client client = ClientBuilder.newClient();
    Configuration config = client.getConfiguration();
    int registeredInstances = config.getInstances().size();
    // WebTarget level inheritance
    WebTarget target1 = client.target("");
    WebTarget target2 = client.target("");
    target1.register(new StringBeanEntityProvider());
    config = target2.getConfiguration();
    assertTrue(config.getInstances().size() == registeredInstances, "configuration() does not perform deep copy");
}
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) StringBeanEntityProvider(ee.jakarta.tck.ws.rs.common.provider.StringBeanEntityProvider) Test(org.junit.jupiter.api.Test)

Example 88 with WebTarget

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

the class JAXRSClientIT method sseStageCheckTest.

/*
   * @testName: sseStageCheckTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:1232; JAXRS:JAVADOC:1217;
   * 
   * @test_Strategy: check the stage is ever done
   */
@Test
public void sseStageCheckTest() throws Fault {
    LinkedHolder<InboundSseEvent> holder = new LinkedHolder<>();
    WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl("stage"));
    try (SseEventSource source = SseEventSource.target(target).build()) {
        source.register(holder::add);
        source.open();
        sleepUntilHolderGetsFilled(holder);
        assertNotNull(holder.get(), "No message received");
        assertTrue(holder.get(0).readData().contains(SSEJAXRSClient.MESSAGE), holder.get(0) + "does not contain expected" + SSEJAXRSClient.MESSAGE);
        if (!holder.get(1).readData().contains(StageCheckerResource.DONE)) {
            sleepUntilHolderGetsFilled(holder);
        }
    }
    assertNotNull(holder.get(1), "No message received");
    assertEquals(holder.get(1).readData(), StageCheckerResource.DONE, "The stage has not ever been done, message is", holder.get().readData());
}
Also used : LinkedHolder(ee.jakarta.tck.ws.rs.common.util.LinkedHolder) SseEventSource(jakarta.ws.rs.sse.SseEventSource) InboundSseEvent(jakarta.ws.rs.sse.InboundSseEvent) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 89 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:1233; JAXRS:JAVADOC:1197; JAXRS:JAVADOC:1198;
   * JAXRS:JAVADOC:1199; JAXRS:JAVADOC:1200; JAXRS:JAVADOC:1201;
   * JAXRS:JAVADOC:1202; JAXRS:JAVADOC:1241; JAXRS:JAVADOC:1240;
   * JAXRS:JAVADOC:1236;
   * 
   * @test_Strategy:
   */
@Test
public void closeTest() throws Fault {
    boolean isOpen = true;
    LinkedHolder<InboundSseEvent> holder = new LinkedHolder<>();
    WebTarget target = ClientBuilder.newClient().target(getAbsoluteUrl("repeat/cast"));
    // set clear
    setRequestContentEntity(Boolean.TRUE);
    setProperty(Property.REQUEST, buildRequest(Request.POST, "repeat/set"));
    setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_PLAIN_TYPE));
    invoke();
    assertTrue(getResponse().readEntity(Boolean.class), "Cast has not been set");
    // ask for a message
    SseEventSource source = SseEventSource.target(target).build();
    source.register(holder::add);
    source.open();
    sleepUntilHolderGetsFilled(holder);
    assertNotNull(holder.get(), "Message was not received");
    for (InboundSseEvent e : holder) logMsg("Received message no", e.readData());
    // check the session is opened
    setProperty(Property.REQUEST, buildRequest(Request.GET, "repeat/isopen"));
    invoke();
    isOpen = getResponseBody(Boolean.class);
    assertTrue(isOpen, "SseEventSource is closed");
    // Wait 3 times
    for (int i = 0; i != 3; i++) {
        holder.clear();
        sleepUntilHolderGetsFilled(holder);
        for (InboundSseEvent e : holder) logMsg("Received message no", e.readData());
    }
    // close
    source.close();
    assertFalse(source.isOpen(), "SseEventSource was not closed");
    // check it was closed
    int cnt = 0;
    int size = holder.size();
    try {
        while (isOpen && cnt < 20) {
            // check the server sends events
            holder.clear();
            cnt++;
            setProperty(Property.REQUEST, buildRequest(Request.GET, "repeat/isopen"));
            invoke();
            isOpen = getResponseBody(Boolean.class);
            assertFalse(size == 0 && isOpen, "Message was not received and SseEventSink is open");
            sleepUntilHolderGetsFilled(holder);
            for (InboundSseEvent e : holder) logMsg("Received message no", e.readData());
            size = holder.size();
        }
    } finally {
        System.out.println("Sending false");
        setRequestContentEntity(Boolean.FALSE);
        setProperty(Property.REQUEST, buildRequest(Request.POST, "repeat/set"));
        setProperty(Property.REQUEST_HEADERS, buildContentType(MediaType.TEXT_PLAIN_TYPE));
        invoke();
        System.out.println("Sent false");
    }
}
Also used : LinkedHolder(ee.jakarta.tck.ws.rs.common.util.LinkedHolder) SseEventSource(jakarta.ws.rs.sse.SseEventSource) InboundSseEvent(jakarta.ws.rs.sse.InboundSseEvent) WebTarget(jakarta.ws.rs.client.WebTarget) Test(org.junit.jupiter.api.Test)

Example 90 with WebTarget

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

the class JAXRSClientIT method startBuilderForMethod.

// ///////////////////////////////////////////////////////////////////////
// utility methods
protected Invocation.Builder startBuilderForMethod(String methodName) {
    Client client = createClient();
    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) 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