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()));
}
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());
}
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;
}
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;
}
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);
}
Aggregations