Search in sources :

Example 1 with COMPONENTS

use of com.enonic.xp.core.impl.content.serializer.ComponentDataSerializer.COMPONENTS 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)

Aggregations

AbstractDataSerializerTest (com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest)1 COMPONENTS (com.enonic.xp.core.impl.content.serializer.ComponentDataSerializer.COMPONENTS)1 Property (com.enonic.xp.data.Property)1 PropertySet (com.enonic.xp.data.PropertySet)1 PropertyTree (com.enonic.xp.data.PropertyTree)1 Form (com.enonic.xp.form.Form)1 DescriptorKey (com.enonic.xp.page.DescriptorKey)1 Page (com.enonic.xp.page.Page)1 PageDescriptor (com.enonic.xp.page.PageDescriptor)1 PageDescriptorService (com.enonic.xp.page.PageDescriptorService)1 PageRegions (com.enonic.xp.page.PageRegions)1 PageTemplateKey (com.enonic.xp.page.PageTemplateKey)1 ImageComponent (com.enonic.xp.region.ImageComponent)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)1 LayoutRegions (com.enonic.xp.region.LayoutRegions)1 PartComponent (com.enonic.xp.region.PartComponent)1 Region (com.enonic.xp.region.Region)1 RegionDescriptor (com.enonic.xp.region.RegionDescriptor)1 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)1