use of com.enonic.xp.app.Application in project xp by enonic.
the class LocaleServiceImplTest method bundleInvalidateCaching.
@Test
public void bundleInvalidateCaching() {
final ResourceKeys resourceKeys = ResourceKeys.empty();
when(resourceService.findFiles(any(), anyString())).thenReturn(resourceKeys);
final ApplicationKey myApp = ApplicationKey.from("myapplication");
final ApplicationKey otherApp = ApplicationKey.from("otherapp");
MessageBundle bundleCached = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
MessageBundle bundle = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
MessageBundle otherBundleCached = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
MessageBundle otherBundle = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
assertSame(bundle, bundleCached);
assertSame(otherBundle, otherBundleCached);
Application application = Mockito.mock(Application.class);
when(application.getKey()).thenReturn(myApp);
localeService.activated(application);
bundle = localeService.getBundle(myApp, Locale.ENGLISH, "/phrases", "/override");
otherBundle = localeService.getBundle(otherApp, Locale.ENGLISH, "/texts");
assertNotSame(bundle, bundleCached);
assertSame(otherBundle, otherBundleCached);
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class ApplicationServiceTest method testUpdate.
@Test
public void testUpdate() {
String applicationName = "appName";
adminContext().callWith(() -> {
Application application = applicationService.installGlobalApplication(createByteSource("7.8.0"), applicationName);
assertEquals("7.8.0", application.getVersion().toString());
nodeService.refresh(RefreshMode.ALL);
systemRepoContext().callWith(() -> {
Node applicationNode = nodeService.getByPath(NodePath.create(NodePath.ROOT, "/applications/" + applicationName).build());
assertNotNull(applicationNode);
assertEquals("7.8.0", applicationNode.data().getString("version"));
return null;
});
application = applicationService.installGlobalApplication(createByteSource("7.8.1"), applicationName);
assertEquals("7.8.1", application.getVersion().toString());
nodeService.refresh(RefreshMode.ALL);
systemRepoContext().callWith(() -> {
Node applicationNode = nodeService.getByPath(NodePath.create(NodePath.ROOT, "/applications/" + applicationName).build());
assertNotNull(applicationNode);
assertEquals("7.8.1", applicationNode.data().getString("version"));
return null;
});
return null;
});
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class AbstractErrorHandlerTest method setup.
@BeforeEach
public void setup() throws Exception {
this.portalRequest = new PortalRequest();
this.portalRequest.setMethod(HttpMethod.GET);
this.portalResponse = PortalResponse.create().build();
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("myapplication"))).thenReturn(application);
this.resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = AbstractErrorHandlerTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
this.factory = new ErrorHandlerScriptFactoryImpl();
this.factory.setScriptService(scriptService);
this.postProcessor = new PostProcessorImpl();
final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
ServletRequestHolder.setRequest(req);
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class WidgetDescriptorLoader method loadIcon.
private Icon loadIcon(final DescriptorKey key) {
final Application application = this.applicationService.getInstalledApplication(key.getApplicationKey());
if (application != null) {
final String iconPath = PATH + "/" + key.getName() + "/" + key.getName() + ".svg";
final Bundle bundle = application.getBundle();
if (this.hasAppIcon(bundle, iconPath)) {
final URL iconUrl = bundle.getResource(iconPath);
try (InputStream stream = iconUrl.openStream()) {
final byte[] iconData = stream.readAllBytes();
return Icon.from(iconData, "image/svg+xml", Instant.ofEpochMilli(bundle.getLastModified()));
} catch (IOException e) {
throw new RuntimeException("Unable to load widget icon for " + bundle.getSymbolicName() + ":" + key.getName(), e);
}
}
}
return null;
}
use of com.enonic.xp.app.Application in project xp by enonic.
the class MacroDescriptorServiceImpl method getAll.
@Override
public MacroDescriptors getAll() {
final Set<MacroDescriptor> set = new LinkedHashSet<>(builtinMacrosDescriptors.getAll().getSet());
for (final Application application : this.applicationService.getInstalledApplications()) {
final MacroDescriptors macroDescriptors = getByApplication(application.getKey());
set.addAll(macroDescriptors.getSet());
}
return MacroDescriptors.from(set);
}
Aggregations