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);
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class ScriptExecutorFactory method create.
public ScriptExecutor create(final ApplicationKey applicationKey) {
LOG.debug("Create Script Executor for {}", applicationKey);
final Application application = applicationService.getInstalledApplication(applicationKey);
if (application == null || !application.isStarted() || application.getConfig() == null) {
throw new ApplicationNotFoundException(applicationKey);
}
final ClassLoader classLoader = application.getClassLoader();
final Bundle bundle = application.getBundle();
final BundleContext bundleContext = Objects.requireNonNull(bundle.getBundleContext(), String.format("application bundle %s context must not be null", bundle.getBundleId()));
return new ScriptExecutorImpl(scriptAsyncService.getAsyncExecutor(application.getKey()), scriptSettings, classLoader, new ServiceRegistryImpl(bundleContext), resourceService, application, RunMode.get());
}
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 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());
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class DeployDirectoryWatcher method installApplication.
private void installApplication(final File file) {
// Installs the application
final ByteSource byteSource = Files.asByteSource(file);
final Application application = DeployHelper.runAsAdmin(() -> applicationService.installLocalApplication(byteSource, file.getName()));
final ApplicationKey applicationKey = application.getKey();
final String path = file.getPath();
// Stores a mapping fileName -> applicationKey. Needed for uninstallation
this.applicationKeyByPath.put(path, applicationKey);
// Updates the mapping applicationKey -> stack<fileName>. Needed in some particular case for uninstallatioon
this.pathsByApplicationKey.compute(applicationKey, (applicationKeyParam, fileNameStack) -> {
if (fileNameStack == null) {
fileNameStack = new Stack<>();
}
fileNameStack.remove(path);
fileNameStack.push(path);
return fileNameStack;
});
}
Aggregations