use of org.apache.cxf.systest.jaxrs.resources.Book in project cxf by apache.
the class SpringSseEmitterTest method testSseEvents.
@Test
public void testSseEvents() throws InterruptedException {
final WebTarget target = createWebTarget();
final Collection<Book> books = new ArrayList<>(CNT);
final AtomicReference<Throwable> throwable = new AtomicReference<>();
try (SseEventSource eventSource = SseEventSource.target(target).build()) {
eventSource.register(event -> {
books.add(event.readData(Book.class, javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE));
if (books.size() == CNT) {
synchronized (books) {
books.notify();
}
}
}, e -> throwable.set(e));
eventSource.open();
// Give the SSE stream some time to collect all events
synchronized (books) {
books.wait(5000L);
}
}
assertThat(throwable.get(), nullValue());
assertThat(books, hasItems(new Book("New Book #1", "Author #1"), new Book("New Book #2", "Author #2"), new Book("New Book #3", "Author #3"), new Book("New Book #4", "Author #4"), new Book("New Book #5", "Author #5")));
}
Aggregations