Search in sources :

Example 11 with Application

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

the class AbstractPortalUrlServiceImplTest method setup.

@BeforeEach
public void setup() {
    final ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    final Application application = Mockito.mock(Application.class);
    when(application.getKey()).thenReturn(applicationKey);
    req = mock(HttpServletRequest.class);
    this.portalRequest = new PortalRequest();
    this.portalRequest.setBranch(Branch.from("draft"));
    this.portalRequest.setApplicationKey(applicationKey);
    this.portalRequest.setBaseUri("/site");
    this.portalRequest.setContentPath(ContentPath.from("context/path"));
    this.portalRequest.setRawRequest(req);
    this.service = new PortalUrlServiceImpl();
    this.service.setMacroService(new MacroServiceImpl());
    this.contentService = Mockito.mock(ContentService.class);
    this.service.setContentService(this.contentService);
    this.styleDescriptorService = Mockito.mock(StyleDescriptorService.class);
    when(this.styleDescriptorService.getByApplications(Mockito.any())).thenReturn(StyleDescriptors.empty());
    this.service.setStyleDescriptorService(this.styleDescriptorService);
    this.applicationService = Mockito.mock(ApplicationService.class);
    when(this.applicationService.getInstalledApplication(applicationKey)).thenReturn(application);
    this.resourceService = Mockito.mock(ResourceService.class);
    this.service.setResourceService(this.resourceService);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationKey(com.enonic.xp.app.ApplicationKey) MacroServiceImpl(com.enonic.xp.impl.macro.MacroServiceImpl) StyleDescriptorService(com.enonic.xp.style.StyleDescriptorService) ResourceService(com.enonic.xp.resource.ResourceService) ContentService(com.enonic.xp.content.ContentService) Application(com.enonic.xp.app.Application) PortalRequest(com.enonic.xp.portal.PortalRequest) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with Application

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

the class ScriptExecutorFactory method create.

public ScriptExecutor create(final ApplicationKey applicationKey) {
    LOG.debug("Create Script Executor for {}", applicationKey);
    final Application application = applicationService.getInstalledApplication(applicationKey);
    if (application == null || !application.isStarted() || application.getConfig() == null) {
        throw new ApplicationNotFoundException(applicationKey);
    }
    final ClassLoader classLoader = application.getClassLoader();
    final Bundle bundle = application.getBundle();
    final BundleContext bundleContext = Objects.requireNonNull(bundle.getBundleContext(), String.format("application bundle %s context must not be null", bundle.getBundleId()));
    return new ScriptExecutorImpl(scriptAsyncService.getAsyncExecutor(application.getKey()), scriptSettings, classLoader, new ServiceRegistryImpl(bundleContext), resourceService, application, RunMode.get());
}
Also used : ServiceRegistryImpl(com.enonic.xp.script.impl.service.ServiceRegistryImpl) ApplicationNotFoundException(com.enonic.xp.app.ApplicationNotFoundException) Bundle(org.osgi.framework.Bundle) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext)

Example 13 with Application

use of com.enonic.xp.app.Application 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 14 with Application

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

the class ScriptEventManagerImplTest method testInvalidate.

@Test
public void testInvalidate() {
    final ScriptEventListener listener1 = newListener("foo.bar");
    final ScriptEventListener listener2 = newListener("foo.other");
    this.manager.add(listener1);
    this.manager.add(listener2);
    assertEquals(2, StreamSupport.stream(manager.spliterator(), false).count());
    Application application = mock(Application.class);
    when(application.getKey()).thenReturn(ApplicationKey.from("foo.bar"));
    this.manager.invalidate(ApplicationKey.from("foo.bar"), ApplicationInvalidationLevel.FULL);
    assertEquals(1, StreamSupport.stream(manager.spliterator(), false).count());
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 15 with Application

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

the class DeployDirectoryWatcher method installApplication.

private void installApplication(final File file) {
    // Installs the application
    final ByteSource byteSource = Files.asByteSource(file);
    final Application application = DeployHelper.runAsAdmin(() -> applicationService.installLocalApplication(byteSource, file.getName()));
    final ApplicationKey applicationKey = application.getKey();
    final String path = file.getPath();
    // Stores a mapping fileName -> applicationKey. Needed for uninstallation
    this.applicationKeyByPath.put(path, applicationKey);
    // Updates the mapping applicationKey -> stack<fileName>. Needed in some particular case for uninstallatioon
    this.pathsByApplicationKey.compute(applicationKey, (applicationKeyParam, fileNameStack) -> {
        if (fileNameStack == null) {
            fileNameStack = new Stack<>();
        }
        fileNameStack.remove(path);
        fileNameStack.push(path);
        return fileNameStack;
    });
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) ByteSource(com.google.common.io.ByteSource) Application(com.enonic.xp.app.Application)

Aggregations

Application (com.enonic.xp.app.Application)66 Test (org.junit.jupiter.api.Test)42 ApplicationKey (com.enonic.xp.app.ApplicationKey)20 Node (com.enonic.xp.node.Node)16 Bundle (org.osgi.framework.Bundle)16 ByteSource (com.google.common.io.ByteSource)12 URL (java.net.URL)11 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ApplicationService (com.enonic.xp.app.ApplicationService)8 ResourceService (com.enonic.xp.resource.ResourceService)8 BundleContext (org.osgi.framework.BundleContext)8 UrlResource (com.enonic.xp.resource.UrlResource)7 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)7 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)7 PortalScriptServiceImpl (com.enonic.xp.portal.impl.script.PortalScriptServiceImpl)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 IOException (java.io.IOException)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 PropertyTree (com.enonic.xp.data.PropertyTree)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4