use of com.enonic.xp.impl.server.rest.model.ListApplicationJson in project xp by enonic.
the class SseEntryPoint method subscribe.
@GET
@Path("events")
@Produces(MediaType.SERVER_SENT_EVENTS)
public void subscribe(@Context final SseEventSink sseEventSink) {
final SseContextHolder ctx = contextHolder;
if (ctx == null) {
throw new IllegalStateException("No SSE context");
}
final OutboundSseEvent sseEvent = ctx.sse.newEventBuilder().name("list").id(UUID.randomUUID().toString()).mediaType(MediaType.APPLICATION_JSON_TYPE).data(ListApplicationJson.class, new ListApplicationJson(applicationService.getInstalledApplications().stream().map(application -> new ApplicationInfoJson(application, applicationService.isLocalApplication(application.getKey()))).collect(Collectors.toList()))).build();
sseEventSink.send(sseEvent);
ctx.broadcaster.register(sseEventSink);
}
use of com.enonic.xp.impl.server.rest.model.ListApplicationJson in project xp by enonic.
the class SseEntryPointTest method testSubscribe.
@Test
public void testSubscribe() {
listener.setSse(sse);
final SseEventSink eventSink = mock(SseEventSink.class);
doNothing().when(broadcaster).register(eventSink);
final Application application = mock(Application.class);
when(application.getKey()).thenReturn(ApplicationKey.from("appKey"));
when(application.getVersion()).thenReturn(Version.emptyVersion);
final Applications applications = Applications.from(application);
when(applicationService.getInstalledApplications()).thenReturn(applications);
when(applicationService.isLocalApplication(any(ApplicationKey.class))).thenReturn(false);
final ArgumentCaptor<ListApplicationJson> listApplicationCaptor = ArgumentCaptor.forClass(ListApplicationJson.class);
listener.subscribe(eventSink);
verify(broadcaster, times(1)).register(eventSink);
verify(sse, times(1)).newEventBuilder();
verify(eventBuilder).data(eq(ListApplicationJson.class), listApplicationCaptor.capture());
verify(applicationService, times(1)).getInstalledApplications();
verify(applicationService, times(1)).isLocalApplication(any(ApplicationKey.class));
final List<ApplicationInfoJson> actualApplications = listApplicationCaptor.getValue().getApplications();
assertNotNull(actualApplications);
assertFalse(actualApplications.isEmpty());
assertEquals("appKey", actualApplications.get(0).getKey());
assertFalse(actualApplications.get(0).getLocal());
}
Aggregations