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;
}
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);
}
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"));
}
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);
}
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")));
}
Aggregations