Search in sources :

Example 41 with ApplicationKey

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));
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 42 with 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);
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 43 with ApplicationKey

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();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 44 with ApplicationKey

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();
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 45 with ApplicationKey

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());
    }
}
Also used : ApplicationInfoJson(com.enonic.xp.impl.server.rest.model.ApplicationInfoJson) OutboundSseEvent(javax.ws.rs.sse.OutboundSseEvent) ApplicationKey(com.enonic.xp.app.ApplicationKey) ApplicationUninstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationUninstalledJson) Application(com.enonic.xp.app.Application)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)78 Test (org.junit.jupiter.api.Test)40 Application (com.enonic.xp.app.Application)16 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)12 Bundle (org.osgi.framework.Bundle)10 ResourceKey (com.enonic.xp.resource.ResourceKey)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 ExtraData (com.enonic.xp.content.ExtraData)4 Site (com.enonic.xp.site.Site)4 Node (com.enonic.xp.node.Node)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 XDataName (com.enonic.xp.schema.xdata.XDataName)3 ByteSource (com.google.common.io.ByteSource)3 ApplicationInvalidator (com.enonic.xp.app.ApplicationInvalidator)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 PropertySet (com.enonic.xp.data.PropertySet)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2