Search in sources :

Example 1 with LinkedHolder

use of ee.jakarta.tck.ws.rs.common.util.LinkedHolder 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 2 with LinkedHolder

use of ee.jakarta.tck.ws.rs.common.util.LinkedHolder 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)

Aggregations

LinkedHolder (ee.jakarta.tck.ws.rs.common.util.LinkedHolder)2 WebTarget (jakarta.ws.rs.client.WebTarget)2 InboundSseEvent (jakarta.ws.rs.sse.InboundSseEvent)2 SseEventSource (jakarta.ws.rs.sse.SseEventSource)2 Test (org.junit.jupiter.api.Test)2