Search in sources :

Example 6 with Application

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

the class NamedTaskFactoryImplTest method setupPortalScriptService.

private PortalScriptService setupPortalScriptService() {
    final BundleContext bundleContext = mock(BundleContext.class);
    final Bundle bundle = mock(Bundle.class);
    when(bundle.getBundleContext()).thenReturn(bundleContext);
    final Application application = mock(Application.class);
    when(application.getBundle()).thenReturn(bundle);
    when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
    when(application.isStarted()).thenReturn(true);
    when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
    final ApplicationService applicationService = mock(ApplicationService.class);
    when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
    ResourceService resourceService = mock(ResourceService.class);
    final Answer<Object> getResource = invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = NamedTaskFactoryImplTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    };
    when(resourceService.getResource(any())).thenAnswer(getResource);
    final ScriptAsyncService scriptAsyncService = mock(ScriptAsyncService.class);
    final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
    final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
    scriptService.initialize();
    return scriptService;
}
Also used : Strictness(org.mockito.quality.Strictness) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) TaskDescriptorService(com.enonic.xp.task.TaskDescriptorService) URL(java.net.URL) Mock(org.mockito.Mock) ResourceKey(com.enonic.xp.resource.ResourceKey) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) PortalScriptService(com.enonic.xp.portal.script.PortalScriptService) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) Answer(org.mockito.stubbing.Answer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RunnableTask(com.enonic.xp.task.RunnableTask) Application(com.enonic.xp.app.Application) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) ConfigBuilder(com.enonic.xp.config.ConfigBuilder) Bundle(org.osgi.framework.Bundle) PropertyTree(com.enonic.xp.data.PropertyTree) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResourceService(com.enonic.xp.resource.ResourceService) Mockito.when(org.mockito.Mockito.when) UrlResource(com.enonic.xp.resource.UrlResource) BundleContext(org.osgi.framework.BundleContext) ApplicationKey(com.enonic.xp.app.ApplicationKey) TaskId(com.enonic.xp.task.TaskId) Test(org.junit.jupiter.api.Test) TaskNotFoundException(com.enonic.xp.task.TaskNotFoundException) DescriptorKey(com.enonic.xp.page.DescriptorKey) TaskDescriptor(com.enonic.xp.task.TaskDescriptor) ApplicationService(com.enonic.xp.app.ApplicationService) Mockito.mock(org.mockito.Mockito.mock) Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) URL(java.net.URL) ResourceKey(com.enonic.xp.resource.ResourceKey) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) UrlResource(com.enonic.xp.resource.UrlResource) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService)

Example 7 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 8 with Application

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

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final URL url, byte[] sha512) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(url, sha512);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application from " + url;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 9 with Application

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

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final ByteSource byteSource, final String applicationName) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(byteSource, applicationName);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application " + applicationName;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 10 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)

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