Search in sources :

Example 1 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class ControllerMappingsResolverTest method testResolvePatternWithParametersNoMatch.

@Test
public void testResolvePatternWithParametersNoMatch() {
    final Content content = newContent();
    final Site site = newSite();
    final SiteDescriptor siteDescriptor = newSiteDescriptor3();
    Mockito.when(this.siteService.getDescriptor(getAppKey2())).thenReturn(siteDescriptor);
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/api", ImmutableMultimap.of(), content, site.getSiteConfigs());
    assertTrue(mapping.isEmpty());
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) Content(com.enonic.xp.content.Content) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Example 2 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class ControllerMappingsResolverTest method testPatternCatchAllType_not_matches_missing.

@Test
public void testPatternCatchAllType_not_matches_missing() {
    final ControllerMappingDescriptor mapping1 = ControllerMappingDescriptor.create().controller(ResourceKey.from(getAppKey2(), "/other/controller1.js")).contentConstraint("type:'.+:.+'").order(10).build();
    final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping1);
    final Site site = newSite();
    final SiteDescriptor siteDescriptor = SiteDescriptor.create().mappingDescriptors(mappings).build();
    Mockito.when(this.siteService.getDescriptor(getAppKey2())).thenReturn(siteDescriptor);
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/does-not-exist", ImmutableMultimap.of(), null, site.getSiteConfigs());
    assertTrue(mapping.isEmpty());
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors) Test(org.junit.jupiter.api.Test)

Example 3 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlWithUtf16BeBomEncoding.

@Test
public void testSiteXmlWithUtf16BeBomEncoding() {
    final String xml = loadTestFile("utf16bebom.xml", StandardCharsets.UTF_16BE);
    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 4 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlDeserializationWithMappingFilters.

@Test
public void testSiteXmlDeserializationWithMappingFilters() {
    final String xml = loadTestXml("serialized-site-with-mapping-filters.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(2, siteDescriptor.getMappingDescriptors().getSize());
    final ControllerMappingDescriptor mapping1 = siteDescriptor.getMappingDescriptors().get(0);
    final ControllerMappingDescriptor mapping2 = siteDescriptor.getMappingDescriptors().get(1);
    assertEquals("myapplication:/filter1.js", mapping1.getFilter().toString());
    assertEquals("_path:'/*/fisk'", mapping1.getContentConstraint().toString());
    assertEquals("/.*", mapping1.getPattern().toString());
    assertEquals(50, mapping1.getOrder());
    assertEquals("myapplication:/filter2.js", mapping2.getFilter().toString());
    assertEquals("type:'portal:fragment'", mapping2.getContentConstraint().toString());
    assertEquals("/.*", mapping2.getPattern().toString());
    assertEquals(5, mapping2.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 5 with SiteDescriptor

use of com.enonic.xp.site.SiteDescriptor in project xp by enonic.

the class XmlSiteParserTest method testSiteXmlWithUtf8BomEncoding.

@Test
public void testSiteXmlWithUtf8BomEncoding() {
    final String xml = loadTestFile("utf8bom.xml", StandardCharsets.UTF_8);
    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

SiteDescriptor (com.enonic.xp.site.SiteDescriptor)24 Test (org.junit.jupiter.api.Test)17 ApplicationKey (com.enonic.xp.app.ApplicationKey)13 Content (com.enonic.xp.content.Content)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 Site (com.enonic.xp.site.Site)6 SiteConfig (com.enonic.xp.site.SiteConfig)4 ControllerMappingDescriptors (com.enonic.xp.site.mapping.ControllerMappingDescriptors)3 EditableContent (com.enonic.xp.content.EditableContent)2 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)2 PropertyTree (com.enonic.xp.data.PropertyTree)2 Form (com.enonic.xp.form.Form)2 ResponseProcessorDescriptor (com.enonic.xp.site.processor.ResponseProcessorDescriptor)2 ContentPath (com.enonic.xp.content.ContentPath)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 Property (com.enonic.xp.data.Property)1 FormItemSet (com.enonic.xp.form.FormItemSet)1 ContentType (com.enonic.xp.schema.content.ContentType)1 GetContentTypeParams (com.enonic.xp.schema.content.GetContentTypeParams)1 XData (com.enonic.xp.schema.xdata.XData)1