Search in sources :

Example 26 with Page

use of com.enonic.xp.page.Page in project xp by enonic.

the class PageDataSerializerTest method createPage.

private Page createPage() {
    final PropertyTree myPartConfig = new PropertyTree();
    myPartConfig.addString("some", "somevalue");
    final PropertyTree imageConfig = new PropertyTree();
    imageConfig.addString("caption", "Caption");
    final DescriptorKey pageDescriptorKey = DescriptorKey.from("app-key:d-name");
    final String regionName1 = "top";
    final String regionName2 = "bottom";
    final Region mainRegion1 = Region.create().name(regionName1).add(createPartComponent("MyPart1", "app-descriptor-x:name-x", myPartConfig)).add(createLayoutComponent()).add(LayoutComponent.create().build()).build();
    final Region mainRegion2 = Region.create().name(regionName2).add(createPartComponent("MyPart2", "app-descriptor-y:name-y", myPartConfig)).add(createImageComponent("img-id-x", "Image Component", imageConfig)).add(ImageComponent.create().build()).build();
    final PageRegions regions = PageRegions.create().add(mainRegion1).add(mainRegion2).build();
    final PropertyTree pageConfig = new PropertyTree();
    pageConfig.addString("some", "config");
    pageConfig.addDouble("aim", 42.0);
    final Page page = Page.create().config(pageConfig).descriptor(pageDescriptorKey).regions(regions).build();
    Mockito.when(pageDescriptorService.getByKey(pageDescriptorKey)).thenReturn(PageDescriptor.create().config(Form.create().build()).key(pageDescriptorKey).regions(RegionDescriptors.create().add(RegionDescriptor.create().name(regionName1).build()).add(RegionDescriptor.create().name(regionName2).build()).build()).build());
    return page;
}
Also used : PageRegions(com.enonic.xp.page.PageRegions) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Region(com.enonic.xp.region.Region) Page(com.enonic.xp.page.Page)

Example 27 with Page

use of com.enonic.xp.page.Page in project xp by enonic.

the class PageDataSerializerTest method page_template.

@Test
public void page_template() {
    Page page = Page.create().template(PageTemplateKey.from("template-id")).build();
    PropertyTree pageAsData = new PropertyTree();
    pageDataSerializer.toData(page, pageAsData.getRoot());
    Page parsedPage = pageDataSerializer.fromData(pageAsData.getRoot());
    // verify
    assertEquals(page, parsedPage);
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

Example 28 with Page

use of com.enonic.xp.page.Page in project xp by enonic.

the class PageDataSerializerTest method page_config.

@Test
public void page_config() {
    final Page page = createPage();
    final PropertyTree pageAsData = new PropertyTree();
    pageDataSerializer.toData(page, pageAsData.getRoot());
    final PropertySet pageOnlyData = pageAsData.getRoot().getProperties(COMPONENTS).get(0).getSet();
    assertTrue(pageOnlyData.hasProperty("page.config.app-key.d-name"));
    assertEquals("42.0", pageOnlyData.getString("page.config.app-key.d-name.aim"));
}
Also used : PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

Example 29 with Page

use of com.enonic.xp.page.Page in project xp by enonic.

the class PageDataSerializerTest method page_deserialize_custom_order_of_components.

@Test
public void page_deserialize_custom_order_of_components() {
    final Page page = createPage();
    final PropertyTree pageAsData = new PropertyTree();
    pageDataSerializer.toData(page, pageAsData.getRoot());
    final List<PropertySet> componentsAsData = pageAsData.getRoot().getProperties(COMPONENTS).stream().filter(Property::hasNotNullValue).map(item -> item.getSet()).collect(Collectors.toList());
    final List<PropertySet> customOrdercomponentsAsData = new ArrayList<>();
    customOrdercomponentsAsData.add(componentsAsData.get(7));
    customOrdercomponentsAsData.add(componentsAsData.get(11));
    customOrdercomponentsAsData.add(componentsAsData.get(4));
    customOrdercomponentsAsData.add(componentsAsData.get(3));
    customOrdercomponentsAsData.add(componentsAsData.get(1));
    customOrdercomponentsAsData.add(componentsAsData.get(10));
    customOrdercomponentsAsData.add(componentsAsData.get(5));
    customOrdercomponentsAsData.add(componentsAsData.get(6));
    customOrdercomponentsAsData.add(componentsAsData.get(8));
    customOrdercomponentsAsData.add(componentsAsData.get(2));
    customOrdercomponentsAsData.add(componentsAsData.get(0));
    customOrdercomponentsAsData.add(componentsAsData.get(9));
    final PropertySet root = new PropertySet();
    customOrdercomponentsAsData.forEach(componentData -> root.addSet(COMPONENTS, componentData));
    final Page parsedPage = pageDataSerializer.fromData(root);
    assertEquals(page, parsedPage);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PageDescriptor(com.enonic.xp.page.PageDescriptor) RegionDescriptors(com.enonic.xp.region.RegionDescriptors) Page(com.enonic.xp.page.Page) ArrayList(java.util.ArrayList) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Region(com.enonic.xp.region.Region) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ImageComponent(com.enonic.xp.region.ImageComponent) PageRegions(com.enonic.xp.page.PageRegions) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) TextComponent(com.enonic.xp.region.TextComponent) Property(com.enonic.xp.data.Property) PropertySet(com.enonic.xp.data.PropertySet) PageTemplateKey(com.enonic.xp.page.PageTemplateKey) Collectors(java.util.stream.Collectors) COMPONENTS(com.enonic.xp.core.impl.content.serializer.ComponentDataSerializer.COMPONENTS) Test(org.junit.jupiter.api.Test) Form(com.enonic.xp.form.Form) Mockito(org.mockito.Mockito) List(java.util.List) LayoutComponent(com.enonic.xp.region.LayoutComponent) DescriptorKey(com.enonic.xp.page.DescriptorKey) LayoutRegions(com.enonic.xp.region.LayoutRegions) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest) PartComponent(com.enonic.xp.region.PartComponent) PropertyTree(com.enonic.xp.data.PropertyTree) ArrayList(java.util.ArrayList) PropertySet(com.enonic.xp.data.PropertySet) Page(com.enonic.xp.page.Page) Property(com.enonic.xp.data.Property) Test(org.junit.jupiter.api.Test) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)

Example 30 with Page

use of com.enonic.xp.page.Page in project xp by enonic.

the class PageRegionsConfigProcessorTest method test_complex_component_config.

@Test
public void test_complex_component_config() throws Exception {
    final PropertyTree config = new PropertyTree();
    final PropertySet items = config.addSet("items");
    items.addStrings("input", "a", "b", "c");
    final Page page = Page.create().regions(PageRegions.create().add(Region.create().name("region1").add(PartComponent.create().descriptor(DescriptorKey.from("appKey1:partName1")).config(new PropertyTree()).build()).add(LayoutComponent.create().descriptor(DescriptorKey.from("appKey2:layoutName")).config(new PropertyTree()).regions(LayoutRegions.create().add(Region.create().name("region").add(PartComponent.create().descriptor(DescriptorKey.from("appKey3:partName2")).config(new PropertyTree()).build()).build()).build()).build()).build()).build()).build();
    final Form form = Form.create().addFormItem(FormItemSet.create().name("items").addFormItem(Input.create().name("input").label("input").inputType(InputTypeName.TEXT_LINE).occurrences(0, 5).build()).build()).build();
    final PatternIndexConfigDocument result = processPage(page, Arrays.asList(form, form).listIterator(), singletonList(form).listIterator());
    assertEquals(8, result.getPathIndexConfigs().size());
    assertEquals(IndexConfig.BY_TYPE, result.getConfigForPath(PropertyPath.from("components.part.config.appKey1.partName1")));
    assertEquals(IndexConfig.BY_TYPE, result.getConfigForPath(PropertyPath.from("components.part.config.appKey2.layoutName")));
    assertEquals(IndexConfig.BY_TYPE, result.getConfigForPath(PropertyPath.from("components.part.config.appkey3.partname2")));
}
Also used : Form(com.enonic.xp.form.Form) PropertyTree(com.enonic.xp.data.PropertyTree) PropertySet(com.enonic.xp.data.PropertySet) Page(com.enonic.xp.page.Page) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) Test(org.junit.jupiter.api.Test)

Aggregations

Page (com.enonic.xp.page.Page)58 PropertyTree (com.enonic.xp.data.PropertyTree)30 Test (org.junit.jupiter.api.Test)28 Content (com.enonic.xp.content.Content)25 Site (com.enonic.xp.site.Site)12 DescriptorKey (com.enonic.xp.page.DescriptorKey)9 PageRegions (com.enonic.xp.page.PageRegions)9 AbstractDataSerializerTest (com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)7 PageDescriptor (com.enonic.xp.page.PageDescriptor)7 PageTemplate (com.enonic.xp.page.PageTemplate)7 PropertySet (com.enonic.xp.data.PropertySet)6 Form (com.enonic.xp.form.Form)5 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)5 LayoutComponent (com.enonic.xp.region.LayoutComponent)5 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)4 EditableContent (com.enonic.xp.content.EditableContent)4 Component (com.enonic.xp.region.Component)4 PartComponent (com.enonic.xp.region.PartComponent)4 ContentId (com.enonic.xp.content.ContentId)3 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)3