use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ScriptRuntimeFactoryImplTest method deactivate.
@Test
void deactivate() {
final ScriptRuntimeFactoryImpl scriptRuntimeFactory = spy(new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService));
final ScriptRuntimeImpl scriptRuntime = mock(ScriptRuntimeImpl.class);
when(scriptRuntimeFactory.doCreate(any())).thenReturn(scriptRuntime);
scriptRuntimeFactory.create(ScriptSettings.create().build());
final ApplicationKey applicationKey = ApplicationKey.from("myapp");
final Application application = mock(Application.class);
when(application.getKey()).thenReturn(applicationKey);
scriptRuntimeFactory.deactivated(application);
verify(scriptRuntime).runDisposers(eq(applicationKey));
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ScriptRuntimeImplTest method execute.
@Test
void execute() {
final ApplicationKey applicationKey = ApplicationKey.from("myApp");
when(scriptExecutorFactory.apply(applicationKey)).thenReturn(scriptExecutor);
final ScriptRuntimeImpl scriptRuntime = new ScriptRuntimeImpl(scriptExecutorFactory);
final ResourceKey resourceKey = ResourceKey.from(applicationKey, "/main.js");
scriptRuntime.execute(resourceKey);
verify(scriptExecutor, Mockito.times(1)).executeMain(resourceKey);
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ScriptRuntimeImplTest method runDisposers_no_script_executor.
@Test
void runDisposers_no_script_executor() {
final ApplicationKey applicationKey = ApplicationKey.from("myApp");
when(scriptExecutorFactory.apply(applicationKey)).thenReturn(scriptExecutor);
final ScriptRuntimeImpl scriptRuntime = new ScriptRuntimeImpl(scriptExecutorFactory);
final ResourceKey resourceKey = ResourceKey.from(applicationKey, "/main.js");
scriptRuntime.execute(resourceKey);
scriptRuntime.invalidate(applicationKey);
scriptRuntime.runDisposers(applicationKey);
verify(scriptExecutor, Mockito.never()).runDisposers();
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class ScriptRuntimeImplTest method runDisposers.
@Test
void runDisposers() {
final ApplicationKey applicationKey = ApplicationKey.from("myApp");
when(scriptExecutorFactory.apply(applicationKey)).thenReturn(scriptExecutor);
final ScriptRuntimeImpl scriptRuntime = new ScriptRuntimeImpl(scriptExecutorFactory);
final ResourceKey resourceKey = ResourceKey.from(applicationKey, "/main.js");
scriptRuntime.execute(resourceKey);
scriptRuntime.runDisposers(applicationKey);
verify(scriptExecutor, Mockito.times(1)).runDisposers();
}
use of com.enonic.xp.app.ApplicationKey in project xp by enonic.
the class SseEntryPoint method handleEvent.
private void handleEvent(final Event event, final String eventSubType) {
final SseContextHolder ctx = contextHolder;
if (ctx == null) {
LOG.debug("Skipping {} {}. Please to subscribe to send SSE events.", EVENT_TYPE, eventSubType);
return;
}
if (event.getValue(APPLICATION_KEY_PARAM).isPresent()) {
final OutboundSseEvent.Builder eventBuilder = ctx.sse.newEventBuilder().name(eventSubType).id(UUID.randomUUID().toString()).mediaType(MediaType.APPLICATION_JSON_TYPE);
if (UNINSTALLED.equals(eventSubType)) {
eventBuilder.data(ApplicationUninstalledJson.class, new ApplicationUninstalledJson(event.getValue(APPLICATION_KEY_PARAM).get().toString()));
} else {
final ApplicationKey applicationKey = ApplicationKey.from(event.getValue(APPLICATION_KEY_PARAM).get().toString());
final Application application = applicationService.getInstalledApplication(applicationKey);
if (application == null) {
LOG.warn("Application \"{}\" not found", applicationKey);
return;
}
final boolean localApplication = applicationService.isLocalApplication(application.getKey());
eventBuilder.data(ApplicationInfoJson.class, new ApplicationInfoJson(application, localApplication));
}
ctx.broadcaster.broadcast(eventBuilder.build());
}
}
Aggregations