55
66import java .net .URI ;
77import java .time .Duration ;
8+ import java .util .ArrayList ;
9+ import java .util .Collections ;
10+ import java .util .List ;
811import java .util .Set ;
12+ import java .util .concurrent .CompletableFuture ;
13+ import java .util .concurrent .TimeUnit ;
914
15+ import jakarta .ws .rs .client .ClientBuilder ;
16+ import jakarta .ws .rs .sse .SseEventSource ;
17+
18+ import org .assertj .core .api .Assertions ;
1019import org .junit .jupiter .api .Test ;
1120import org .junit .jupiter .api .condition .EnabledIfSystemProperty ;
1221import org .junit .jupiter .api .condition .EnabledOnOs ;
@@ -24,7 +33,24 @@ public class PowerResourceTest {
2433 @ Test
2534 public void testPowerEndpoint () throws Exception {
2635 final var pid = getPid ();
27- StreamChecker .checkPowerForPID (uri , pid );
36+ try (final var client = ClientBuilder .newClient ();
37+ final var eventSource = SseEventSource
38+ .target (client .target (uri )
39+ .path ("power/stream/{pid}" )
40+ .resolveTemplate ("pid" , pid ))
41+ .build ()) {
42+ CompletableFuture <List <String >> res = new CompletableFuture <>();
43+ List <String > collect = Collections .synchronizedList (new ArrayList <>());
44+ eventSource .register (inboundSseEvent -> {
45+ collect .add (inboundSseEvent .readData ());
46+ // stop after one event
47+ eventSource .close ();
48+ },
49+ res ::completeExceptionally ,
50+ () -> res .complete (collect ));
51+ eventSource .open ();
52+ Assertions .assertThat (res .get (5 , TimeUnit .SECONDS )).hasSize (1 );
53+ }
2854 }
2955
3056 @ Test
0 commit comments