Search in sources :

Example 41 with Application

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

the class ApplicationServiceImplTest method update_installed_local_application.

@Test
public void update_installed_local_application() throws Exception {
    final Node node = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").build();
    final String bundleName = "my-bundle";
    mockRepoCreateNode(node);
    when(this.repoService.updateApplicationNode(Mockito.isA(Application.class), Mockito.isA(ByteSource.class))).thenReturn(node);
    mockRepoGetNode(node, bundleName);
    final Application originalApplication = this.service.installLocalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.0").build())), bundleName);
    final Application updatedApplication = this.service.installLocalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.1").build())), bundleName);
    assertEquals("1.0.0", originalApplication.getVersion().toString());
    assertEquals("1.0.1", updatedApplication.getVersion().toString());
    assertTrue(this.service.isLocalApplication(updatedApplication.getKey()));
    assertEquals(updatedApplication, this.service.getInstalledApplication(updatedApplication.getKey()));
    verifyInstalledEvents(node, never());
    verifyStartedEvent(updatedApplication.getKey(), never());
}
Also used : Node(com.enonic.xp.node.Node) ByteSource(com.google.common.io.ByteSource) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 42 with Application

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

the class ApplicationServiceImplTest method uninstall_local_reinstall_global.

@Test
public void uninstall_local_reinstall_global() throws Exception {
    PropertyTree data = new PropertyTree();
    data.setBoolean(ApplicationPropertyNames.STARTED, true);
    final Node node = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").data(data).build();
    final String bundleName = "my-bundle";
    mockRepoCreateNode(node);
    when(this.repoService.updateApplicationNode(Mockito.isA(Application.class), Mockito.isA(ByteSource.class))).thenReturn(node);
    mockRepoGetNode(node, bundleName);
    final Application originalApplication = this.service.installGlobalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.0").build())), bundleName);
    final ApplicationKey applicationKey = originalApplication.getKey();
    assertFalse(this.service.isLocalApplication(applicationKey));
    assertEquals("1.0.0", originalApplication.getVersion().toString());
    final Application updatedApplication = this.service.installLocalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.1").build())), bundleName);
    assertEquals("1.0.1", updatedApplication.getVersion().toString());
    assertTrue(this.service.isLocalApplication(applicationKey));
    assertEquals(updatedApplication, this.service.getInstalledApplication(applicationKey));
    assertTrue(this.service.isLocalApplication(applicationKey));
    when(this.repoService.getApplicationSource(node.id())).thenReturn(ByteSource.wrap(ByteStreams.toByteArray(newBundle("my-bundle", true, "1.0.0").build())));
    this.service.uninstallApplication(updatedApplication.getKey(), false);
    assertEquals(originalApplication.getVersion(), this.service.getInstalledApplication(applicationKey).getVersion());
    assertFalse(this.service.isLocalApplication(updatedApplication.getKey()));
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ByteSource(com.google.common.io.ByteSource) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 43 with Application

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

the class ApplicationServiceImplTest method configuration_comes_twice.

@Test
public void configuration_comes_twice() throws Exception {
    final ApplicationKey key = ApplicationKey.from("myapp");
    final Bundle bundle = deployAppBundle("myapp");
    applicationRegistry.installApplication(bundle);
    final Application app = service.getInstalledApplication(key);
    final ApplicationInvalidator mock = mock(ApplicationInvalidator.class);
    applicationRegistry.addInvalidator(mock);
    applicationRegistry.configureApplication(bundle, ConfigBuilder.create().add("a", "b").build());
    applicationRegistry.configureApplication(bundle, ConfigBuilder.create().add("c", "d").build());
    assertEquals(ConfigBuilder.create().add("c", "d").build(), app.getConfig());
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Bundle(org.osgi.framework.Bundle) Application(com.enonic.xp.app.Application) ApplicationInvalidator(com.enonic.xp.app.ApplicationInvalidator) Test(org.junit.jupiter.api.Test)

Example 44 with Application

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

the class ApplicationServiceImplTest method uninstall_global_application.

@Test
public void uninstall_global_application() throws Exception {
    final Node node = Node.create().id(NodeId.from("myNodeId")).name("myBundle").parentPath(ApplicationRepoServiceImpl.APPLICATION_PATH).build();
    final String bundleName = "my-bundle";
    when(this.repoService.getApplicationSource(node.id())).thenReturn(createBundleSource(bundleName));
    final Application application = this.service.installStoredApplication(node.id());
    this.service.uninstallApplication(application.getKey(), true);
    assertNull(this.service.getInstalledApplication(application.getKey()));
    verify(this.eventPublisher, times(1)).publish(Mockito.argThat(new ApplicationEventMatcher(ApplicationClusterEvents.uninstall(application.getKey()))));
    verify(this.eventPublisher, times(1)).publish(Mockito.argThat(new ApplicationEventMatcher(ApplicationClusterEvents.uninstalled(application.getKey()))));
}
Also used : Node(com.enonic.xp.node.Node) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 45 with Application

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

the class ApplicationListenerHubTest method testActivatedDeactivated.

@Test
void testActivatedDeactivated() {
    final Application app = mock(Application.class);
    ApplicationListenerHub dispatcher = new ApplicationListenerHub();
    final ApplicationListener listener = mock(ApplicationListener.class);
    dispatcher.addListener(listener);
    dispatcher.activated(app);
    dispatcher.deactivated(app);
    final InOrder inOrder = inOrder(listener);
    inOrder.verify(listener, times(1)).activated(same(app));
    inOrder.verify(listener, times(1)).deactivated(same(app));
}
Also used : InOrder(org.mockito.InOrder) ApplicationListener(com.enonic.xp.app.ApplicationListener) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

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