Search in sources :

Example 16 with Application

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

the class ApplicationServiceImplTest method update_installed_application.

@Test
public void update_installed_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.installGlobalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.0").build())), bundleName);
    mockRepoGetNode(node, bundleName);
    final Application updatedApplication = this.service.installGlobalApplication(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());
    assertFalse(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 17 with Application

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

the class ApplicationServiceImplTest method install_stored_application.

@Test
public void install_stored_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());
    assertNotNull(application);
    assertEquals(bundleName, application.getKey().getName());
    assertFalse(this.service.isLocalApplication(application.getKey()));
    assertEquals(application, this.service.getInstalledApplication(application.getKey()));
    verifyInstalledEvents(node, never());
    verifyStartedEvent(application.getKey(), never());
}
Also used : Node(com.enonic.xp.node.Node) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 18 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 19 with Application

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

the class IdProviderControllerServiceImplTest method setupPortalScriptService.

private PortalScriptService setupPortalScriptService() {
    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.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(ApplicationKey.from("defaultapplication"))).thenReturn(application);
    Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
    ResourceService resourceService = Mockito.mock(ResourceService.class);
    Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
        final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
        final URL resourceUrl = AbstractControllerTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
        return new UrlResource(resourceKey, resourceUrl);
    });
    final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
    final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
    final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
    scriptService.initialize();
    return scriptService;
}
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) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) 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)

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

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