Search in sources :

Example 51 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class ApplicationServiceImplTest method uninstall_local_reinstall_global.

@Test
public void uninstall_local_reinstall_global() throws Exception {
    PropertyTree data = new PropertyTree();
    data.setBoolean(ApplicationPropertyNames.STARTED, true);
    final Node node = Node.create().id(NodeId.from("myNode")).parentPath(NodePath.ROOT).name("myNode").data(data).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);
    final ApplicationKey applicationKey = originalApplication.getKey();
    assertFalse(this.service.isLocalApplication(applicationKey));
    assertEquals("1.0.0", originalApplication.getVersion().toString());
    final Application updatedApplication = this.service.installLocalApplication(ByteSource.wrap(ByteStreams.toByteArray(newBundle(bundleName, true, "1.0.1").build())), bundleName);
    assertEquals("1.0.1", updatedApplication.getVersion().toString());
    assertTrue(this.service.isLocalApplication(applicationKey));
    assertEquals(updatedApplication, this.service.getInstalledApplication(applicationKey));
    assertTrue(this.service.isLocalApplication(applicationKey));
    when(this.repoService.getApplicationSource(node.id())).thenReturn(ByteSource.wrap(ByteStreams.toByteArray(newBundle("my-bundle", true, "1.0.0").build())));
    this.service.uninstallApplication(updatedApplication.getKey(), false);
    assertEquals(originalApplication.getVersion(), this.service.getInstalledApplication(applicationKey).getVersion());
    assertFalse(this.service.isLocalApplication(updatedApplication.getKey()));
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) ByteSource(com.google.common.io.ByteSource) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Example 52 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class ApplicationServiceImplTest method configuration_comes_twice.

@Test
public void configuration_comes_twice() throws Exception {
    final ApplicationKey key = ApplicationKey.from("myapp");
    final Bundle bundle = deployAppBundle("myapp");
    applicationRegistry.installApplication(bundle);
    final Application app = service.getInstalledApplication(key);
    final ApplicationInvalidator mock = mock(ApplicationInvalidator.class);
    applicationRegistry.addInvalidator(mock);
    applicationRegistry.configureApplication(bundle, ConfigBuilder.create().add("a", "b").build());
    applicationRegistry.configureApplication(bundle, ConfigBuilder.create().add("c", "d").build());
    assertEquals(ConfigBuilder.create().add("c", "d").build(), app.getConfig());
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) Bundle(org.osgi.framework.Bundle) Application(com.enonic.xp.app.Application) ApplicationInvalidator(com.enonic.xp.app.ApplicationInvalidator) Test(org.junit.jupiter.api.Test)

Example 53 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class SiteConfigsValidator method validate.

@Override
public void validate(final ContentValidatorParams params, final ValidationErrors.Builder validationErrorsBuilder) {
    final SiteConfigs siteConfigs = new SiteConfigsDataSerializer().fromProperties(params.getData().getRoot()).build();
    for (final SiteConfig siteConfig : siteConfigs) {
        final ApplicationKey applicationKey = siteConfig.getApplicationKey();
        final SiteDescriptor siteDescriptor = siteService.getDescriptor(applicationKey);
        if (siteDescriptor != null) {
            OccurrenceValidator.validate(siteDescriptor.getForm(), siteConfig.getConfig().getRoot(), validationErrorsBuilder);
            try {
                InputValidator.create().form(siteDescriptor.getForm()).inputTypeResolver(InputTypes.BUILTIN).build().validate(siteConfig.getConfig());
            } catch (final Exception e) {
                validationErrorsBuilder.add(ValidationError.generalError(ValidationErrorCode.from(ApplicationKey.SYSTEM, "cms.validation.siteConfigInvalid")).args(siteConfig.getApplicationKey()).build());
            }
        }
    }
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) SiteConfigsDataSerializer(com.enonic.xp.site.SiteConfigsDataSerializer) SiteConfig(com.enonic.xp.site.SiteConfig) SiteConfigs(com.enonic.xp.site.SiteConfigs)

Example 54 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class ServiceHandlerWorker method newWebSocketEndpoint.

private WebSocketEndpoint newWebSocketEndpoint(final WebSocketConfig config) {
    final ApplicationKey app = this.request.getApplicationKey();
    final Trace trace = Tracer.current();
    if (trace != null && app != null && !trace.containsKey("app")) {
        trace.put("app", app.toString());
    }
    return new WebSocketEndpointImpl(config, this::getScript);
}
Also used : Trace(com.enonic.xp.trace.Trace) ApplicationKey(com.enonic.xp.app.ApplicationKey) WebSocketEndpointImpl(com.enonic.xp.portal.impl.websocket.WebSocketEndpointImpl)

Example 55 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlWithUtf16LeBomEncoding.

@Test
public void testSiteXmlWithUtf16LeBomEncoding() {
    final String xml = loadTestFile("utf16lebom.xml", StandardCharsets.UTF_16LE);
    final SiteDescriptor.Builder siteDescriptorBuilder = SiteDescriptor.create();
    ApplicationKey applicationKey = ApplicationKey.from("myapplication");
    this.parser.source(xml).currentApplication(applicationKey).siteDescriptorBuilder(siteDescriptorBuilder).parse();
    SiteDescriptor siteDescriptor = siteDescriptorBuilder.build();
    assertEquals(1, siteDescriptor.getForm().getFormItems().size());
    assertEquals(2, siteDescriptor.getXDataMappings().getSize());
    assertEquals(2, siteDescriptor.getResponseProcessors().getSize());
    assertEquals(0, siteDescriptor.getMappingDescriptors().getSize());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationKey (com.enonic.xp.app.ApplicationKey)78 Test (org.junit.jupiter.api.Test)40 Application (com.enonic.xp.app.Application)16 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)12 Bundle (org.osgi.framework.Bundle)10 ResourceKey (com.enonic.xp.resource.ResourceKey)6 PropertyTree (com.enonic.xp.data.PropertyTree)5 ExtraData (com.enonic.xp.content.ExtraData)4 Site (com.enonic.xp.site.Site)4 Node (com.enonic.xp.node.Node)3 DescriptorKey (com.enonic.xp.page.DescriptorKey)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 PortalResponse (com.enonic.xp.portal.PortalResponse)3 XDataName (com.enonic.xp.schema.xdata.XDataName)3 ByteSource (com.google.common.io.ByteSource)3 ApplicationInvalidator (com.enonic.xp.app.ApplicationInvalidator)2 ExtraDatas (com.enonic.xp.content.ExtraDatas)2 PropertySet (com.enonic.xp.data.PropertySet)2 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)2 RenderException (com.enonic.xp.portal.impl.rendering.RenderException)2