Search in sources :

Example 51 with Application

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);
}
Also used : MessageBundle(com.enonic.xp.i18n.MessageBundle) ApplicationKey(com.enonic.xp.app.ApplicationKey) ResourceKeys(com.enonic.xp.resource.ResourceKeys) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 52 with Application

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;
    });
}
Also used : Node(com.enonic.xp.node.Node) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest)

Example 53 with Application

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);
}
Also used : Bundle(org.osgi.framework.Bundle) ResourceService(com.enonic.xp.resource.ResourceService) PortalScriptServiceImpl(com.enonic.xp.portal.impl.script.PortalScriptServiceImpl) URL(java.net.URL) PortalRequest(com.enonic.xp.portal.PortalRequest) ResourceKey(com.enonic.xp.resource.ResourceKey) ScriptRuntimeFactoryImpl(com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl) HttpServletRequest(javax.servlet.http.HttpServletRequest) UrlResource(com.enonic.xp.resource.UrlResource) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) PostProcessorImpl(com.enonic.xp.portal.impl.postprocess.PostProcessorImpl) Application(com.enonic.xp.app.Application) BundleContext(org.osgi.framework.BundleContext) ApplicationService(com.enonic.xp.app.ApplicationService) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 54 with Application

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;
}
Also used : Bundle(org.osgi.framework.Bundle) InputStream(java.io.InputStream) IOException(java.io.IOException) Application(com.enonic.xp.app.Application) URL(java.net.URL)

Example 55 with Application

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MacroDescriptor(com.enonic.xp.macro.MacroDescriptor) Application(com.enonic.xp.app.Application) MacroDescriptors(com.enonic.xp.macro.MacroDescriptors)

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