Search in sources :

Example 26 with Application

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

the class ApplicationResourceTest method test_stop_application.

@Test
public void test_stop_application() throws Exception {
    final Application application = createApplication();
    request().path("app/stop").entity("{\"key\": \"" + application.getKey() + "\" }", MediaType.APPLICATION_JSON_TYPE).post();
    final InOrder inOrder = Mockito.inOrder(applicationService);
    inOrder.verify(this.applicationService).stopApplication(application.getKey(), true);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 27 with Application

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

the class ApplicationResourceTest method test_uninstall_application.

@Test
public void test_uninstall_application() throws Exception {
    final Application application = createApplication();
    request().path("app/uninstall").entity("{\"key\": \"" + application.getKey() + "\" }", MediaType.APPLICATION_JSON_TYPE).post();
    final InOrder inOrder = Mockito.inOrder(applicationService);
    inOrder.verify(this.applicationService).uninstallApplication(application.getKey(), true);
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 28 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 29 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 30 with Application

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

the class AbstractScriptTest method createScriptRuntimeFactory.

private ScriptRuntimeFactory createScriptRuntimeFactory() {
    final BundleContext bundleContext = Mockito.mock(BundleContext.class);
    final Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
    final Application application = Mockito.mock(Application.class);
    Mockito.when(application.getBundle()).thenReturn(bundle);
    Mockito.when(application.getKey()).thenReturn(APPLICATION_KEY);
    Mockito.when(application.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
    Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
    Mockito.when(application.isStarted()).thenReturn(true);
    Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
    final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
    Mockito.when(applicationService.getInstalledApplication(APPLICATION_KEY)).thenReturn(application);
    final ResourceService resourceService = Mockito.mock(ResourceService.class);
    Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = AbstractScriptTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    });
    final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
    return new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
}
Also used : ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) UrlResource(com.enonic.xp.resource.UrlResource) Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) Application(com.enonic.xp.app.Application) URL(java.net.URL) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) ResourceKey(com.enonic.xp.resource.ResourceKey)

Aggregations

Application (com.enonic.xp.app.Application)68 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