Search in sources :

Example 76 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class ProcessorChainResolverTest method testFilterChainResolver.

@Test
public void testFilterChainResolver() {
    ApplicationKey ak1 = ApplicationKey.from("ak1");
    SiteConfig sc1 = SiteConfig.create().application(ak1).config(new PropertyTree()).build();
    ApplicationKey ak2 = ApplicationKey.from("ak2");
    SiteConfig sc2 = SiteConfig.create().application(ak2).config(new PropertyTree()).build();
    ApplicationKey ak3 = ApplicationKey.from("ak3");
    SiteConfig sc3 = SiteConfig.create().application(ak3).config(new PropertyTree()).build();
    portalRequest.setSite(Site.create().siteConfigs(SiteConfigs.from(sc1, sc2, sc3)).name("Site").path("/site").parentPath(ContentPath.ROOT).build());
    ResponseProcessorDescriptor fd12 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-2").order(2).build();
    ResponseProcessorDescriptor fd13 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-3").order(3).build();
    ResponseProcessorDescriptor fd15 = ResponseProcessorDescriptor.create().application(ak1).name("ak1-5").order(5).build();
    SiteDescriptor sd1 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd13, fd15, fd12)).build();
    Mockito.when(siteService.getDescriptor(Mockito.eq(ak1))).thenReturn(sd1);
    ResponseProcessorDescriptor fd21 = ResponseProcessorDescriptor.create().application(ak2).name("ak2-1").order(1).build();
    ResponseProcessorDescriptor fd22 = ResponseProcessorDescriptor.create().application(ak2).name("ak1-2").order(2).build();
    ResponseProcessorDescriptor fd23 = ResponseProcessorDescriptor.create().application(ak2).name("ak2-3").order(3).build();
    SiteDescriptor sd2 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd22, fd23, fd21)).build();
    Mockito.when(siteService.getDescriptor(Mockito.eq(ak2))).thenReturn(sd2);
    ResponseProcessorDescriptor fd32 = ResponseProcessorDescriptor.create().application(ak3).name("ak3-2").order(2).build();
    SiteDescriptor sd3 = SiteDescriptor.create().responseProcessors(ResponseProcessorDescriptors.from(fd32)).build();
    Mockito.when(siteService.getDescriptor(Mockito.eq(ak3))).thenReturn(sd3);
    ResponseProcessorDescriptors filters = resolver.resolve(portalRequest);
    assertEquals(7, filters.getSize());
    ResponseProcessorDescriptor fd = filters.get(0);
    assertEquals(1, fd.getOrder());
    assertEquals(ak2, fd.getApplication());
    fd = filters.get(1);
    assertEquals(2, fd.getOrder());
    assertEquals(ak1, fd.getApplication());
    fd = filters.get(2);
    assertEquals(2, fd.getOrder());
    assertEquals(ak2, fd.getApplication());
    fd = filters.get(3);
    assertEquals(2, fd.getOrder());
    assertEquals(ak3, fd.getApplication());
    fd = filters.get(4);
    assertEquals(3, fd.getOrder());
    assertEquals(ak1, fd.getApplication());
    fd = filters.get(5);
    assertEquals(3, fd.getOrder());
    assertEquals(ak2, fd.getApplication());
    fd = filters.get(6);
    assertEquals(5, fd.getOrder());
    assertEquals(ak1, fd.getApplication());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) ResponseProcessorDescriptor(com.enonic.xp.site.processor.ResponseProcessorDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig) ResponseProcessorDescriptors(com.enonic.xp.site.processor.ResponseProcessorDescriptors) Test(org.junit.jupiter.api.Test)

Example 77 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class DeployDirectoryWatcher method uninstallApplication.

private void uninstallApplication(final File file) {
    // Removes the mapping fileName -> applicationKey
    final String path = file.getPath();
    final ApplicationKey applicationKey = applicationKeyByPath.remove(path);
    this.pathsByApplicationKey.computeIfPresent(applicationKey, (applicationKeyParam, fileNameStack) -> {
        // Retrieve the file name for the currently installed application
        final String lastInstalledFile = fileNameStack.isEmpty() ? null : fileNameStack.peek();
        // If the file removed is currently installed
        if (path.equals(lastInstalledFile)) {
            // Uninstall the corresponding application
            DeployHelper.runAsAdmin(() -> this.applicationService.uninstallApplication(applicationKey, false));
            fileNameStack.pop();
            // If there is a previous file with the same applicationKey
            if (!fileNameStack.isEmpty()) {
                // Installs this previous application
                final String previousInstalledFile = fileNameStack.peek();
                final ByteSource byteSource = Files.asByteSource(new File(previousInstalledFile));
                DeployHelper.runAsAdmin(() -> {
                    try {
                        applicationService.installLocalApplication(byteSource, previousInstalledFile);
                    } catch (Exception e) {
                        LOGGER.warn("Failed to reinstall local application [" + previousInstalledFile + "]", e);
                    }
                });
            }
        } else {
            fileNameStack.remove(path);
        }
        return fileNameStack.isEmpty() ? null : fileNameStack;
    });
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ByteSource(com.google.common.io.ByteSource) File(java.io.File)

Example 78 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class ScriptRuntimeImplTest method executeAsync.

@Test
void executeAsync() {
    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.executeAsync(resourceKey);
    verify(scriptExecutor, Mockito.times(1)).executeMainAsync(resourceKey);
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

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