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 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));
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class ApplicationResource method installApplication.
private ApplicationInstallResultJson installApplication(final URL url, byte[] sha512) {
final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
try {
final Application application = this.applicationService.installGlobalApplication(url, sha512);
result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
} catch (Exception e) {
final String failure = "Failed to process application from " + url;
LOG.error(failure, e);
result.setFailure(failure);
}
return result;
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class ApplicationResource method installApplication.
private ApplicationInstallResultJson installApplication(final ByteSource byteSource, final String applicationName) {
final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
try {
final Application application = this.applicationService.installGlobalApplication(byteSource, applicationName);
result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
} catch (Exception e) {
final String failure = "Failed to process application " + applicationName;
LOG.error(failure, e);
result.setFailure(failure);
}
return result;
}
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());
}
Aggregations