Search in sources :

Example 56 with ApplicationKey

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

the class XmlSiteParserTest method testSiteXmlDeserializationWithMappings.

@Test
public void testSiteXmlDeserializationWithMappings() {
    final String xml = loadTestXml("serialized-site-with-mappings.xml");
    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(3, siteDescriptor.getMappingDescriptors().getSize());
    final ControllerMappingDescriptor mapping1 = siteDescriptor.getMappingDescriptors().get(0);
    final ControllerMappingDescriptor mapping2 = siteDescriptor.getMappingDescriptors().get(1);
    final ControllerMappingDescriptor mapping3 = siteDescriptor.getMappingDescriptors().get(2);
    assertEquals("myapplication:/site/page/person/person.js", mapping1.getController().toString());
    assertNull(mapping1.getContentConstraint());
    assertEquals("/person/*", mapping1.getPattern().toString());
    assertEquals(10, mapping1.getOrder());
    assertEquals("myapplication:/controller1.js", mapping2.getController().toString());
    assertEquals("_path:'/*/fisk'", mapping2.getContentConstraint().toString());
    assertEquals("/.*", mapping2.getPattern().toString());
    assertEquals(50, mapping2.getOrder());
    assertEquals("myapplication:/controller2.js", mapping3.getController().toString());
    assertEquals("type:'portal:fragment'", mapping3.getContentConstraint().toString());
    assertEquals("/.*", mapping3.getPattern().toString());
    assertEquals(5, mapping3.getOrder());
}
Also used : SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Example 57 with ApplicationKey

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

the class XmlSiteParserTest method testSiteXmlDeserialization.

@Test
public void testSiteXmlDeserialization() {
    final String xml = loadTestXml("serialized-site.xml");
    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)

Example 58 with ApplicationKey

use of com.enonic.xp.app.ApplicationKey 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 59 with ApplicationKey

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

the class StyleDescriptorServiceImplTest method getAll.

@Test
public void getAll() {
    final ApplicationKey appKey = ApplicationKey.from("myapp1");
    final StyleDescriptors descriptors = this.service.getAll();
    assertNotNull(descriptors);
    assertEquals(2, descriptors.getSize());
}
Also used : ApplicationKey(com.enonic.xp.app.ApplicationKey) StyleDescriptors(com.enonic.xp.style.StyleDescriptors) Test(org.junit.jupiter.api.Test)

Example 60 with ApplicationKey

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

the class LocaleScriptBean method getMessageBundle.

private MessageBundle getMessageBundle(final String locale, final String... bundleNames) {
    final ApplicationKey applicationKey = getApplication();
    final Locale resolvedLocale = resolveLocale(locale);
    return this.localeService.get().getBundle(applicationKey, resolvedLocale, bundleNames);
}
Also used : Locale(java.util.Locale) ApplicationKey(com.enonic.xp.app.ApplicationKey)

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