Search in sources :

Example 36 with Application

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

the class ApplicationServiceImplTest method install_local.

@Test
public void install_local() throws Exception {
    final Node applicationNode = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").build();
    final String bundleName = "my-bundle";
    mockRepoCreateNode(applicationNode);
    mockRepoGetNode(applicationNode, bundleName);
    final ByteSource byteSource = createBundleSource(bundleName);
    final Application application = this.service.installLocalApplication(byteSource, bundleName);
    assertNotNull(application);
    assertEquals(bundleName, application.getKey().getName());
    assertTrue(this.service.isLocalApplication(application.getKey()));
    assertEquals(application, this.service.getInstalledApplication(application.getKey()));
    verifyInstalledEvents(applicationNode, never());
    verifyStartedEvent(application.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 37 with Application

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

the class ApplicationServiceImplTest method install_local_overriding_global.

@Test
public void install_local_overriding_global() 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.installGlobalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.0").build())), bundleName);
    assertFalse(this.service.isLocalApplication(originalApplication.getKey()));
    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()));
    assertTrue(this.service.isLocalApplication(updatedApplication.getKey()));
}
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 38 with Application

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

the class ApplicationNodeTransformerTest method app_binary_updated.

@Test
public void app_binary_updated() throws Exception {
    final PropertyTree data = new PropertyTree();
    final BinaryReference appReference = BinaryReference.from(ApplicationNodeTransformer.APPLICATION_BINARY_REF);
    data.addBinaryReference(ApplicationNodeTransformer.APPLICATION_BINARY_REF, appReference);
    final Node existingNode = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").data(data).attachedBinaries(AttachedBinaries.create().add(new AttachedBinary(appReference, "abc")).build()).build();
    final Application app = Mockito.mock(Application.class);
    Mockito.when(app.getKey()).thenReturn(ApplicationKey.from("myApp"));
    Mockito.when(app.getVersion()).thenReturn(Version.valueOf("1.0.0"));
    Mockito.when(app.getMaxSystemVersion()).thenReturn("1.0.0");
    Mockito.when(app.getMinSystemVersion()).thenReturn("1.0.0.");
    Mockito.when(app.getDisplayName()).thenReturn("displayName");
    final ByteSource updatedSource = ByteSource.wrap(ByteStreams.toByteArray(newBundle("myBundleUpdated", true).build()));
    final UpdateNodeParams updateNodeParams = ApplicationNodeTransformer.toUpdateNodeParams(app, updatedSource, existingNode);
    final BinaryAttachments binaryAttachments = updateNodeParams.getBinaryAttachments();
    assertEquals(updatedSource, binaryAttachments.get(appReference).getByteSource());
}
Also used : BinaryAttachments(com.enonic.xp.node.BinaryAttachments) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) ByteSource(com.google.common.io.ByteSource) BinaryReference(com.enonic.xp.util.BinaryReference) Application(com.enonic.xp.app.Application) AttachedBinary(com.enonic.xp.node.AttachedBinary) Test(org.junit.jupiter.api.Test)

Example 39 with Application

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

the class ApplicationServiceImplTest method uninstall_local_application.

@Test
public void uninstall_local_application() throws Exception {
    final Node applicationNode = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").build();
    final String bundleName = "my-bundle";
    mockRepoCreateNode(applicationNode);
    final ByteSource byteSource = createBundleSource(bundleName);
    final Application application = this.service.installLocalApplication(byteSource, bundleName);
    assertNotNull(this.service.getInstalledApplication(application.getKey()));
    this.service.uninstallApplication(application.getKey(), false);
    assertNull(this.service.getInstalledApplication(application.getKey()));
    verify(this.eventPublisher, never()).publish(Mockito.argThat(new ApplicationEventMatcher(ApplicationClusterEvents.uninstall(application.getKey()))));
    verify(this.eventPublisher, never()).publish(Mockito.argThat(new ApplicationEventMatcher(ApplicationClusterEvents.uninstalled(application.getKey()))));
}
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 40 with Application

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

the class ApplicationServiceImplTest method install_global_when_local_installed.

@Test
public void install_global_when_local_installed() throws Exception {
    final Node applicationNode = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").build();
    final String bundleName = "my-bundle";
    mockRepoCreateNode(applicationNode);
    final ByteSource byteSource = createBundleSource(bundleName);
    final Application application = this.service.installLocalApplication(byteSource, bundleName);
    assertTrue(this.service.isLocalApplication(application.getKey()));
    when(this.repoService.getApplicationNode(application.getKey())).thenReturn(applicationNode);
    this.service.installGlobalApplication(byteSource, bundleName);
    assertTrue(this.service.isLocalApplication(application.getKey()));
    verifyInstalledEvents(applicationNode, times(1));
}
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)

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