Search in sources :

Example 1 with RegionDescriptor

use of com.enonic.xp.region.RegionDescriptor in project xp by enonic.

the class RegionDataSerializerTest method region.

@Test
public void region() {
    final PropertyTree myPartConfig = new PropertyTree();
    myPartConfig.addString("some", "config");
    final String layoutName = "MyOtherPart";
    final DescriptorKey layoutDescriptorKey = DescriptorKey.from("app-descr:layout-name");
    final Region region = Region.create().name("main").add(createPartComponent("MyPart", "app-descr:part-name", myPartConfig)).add(ImageComponent.create().build()).add(LayoutComponent.create().descriptor(layoutDescriptorKey).build()).build();
    Mockito.when(layoutDescriptorService.getByKey(layoutDescriptorKey)).thenReturn(LayoutDescriptor.create().key(layoutDescriptorKey).displayName(layoutName).config(Form.create().build()).regions(RegionDescriptors.create().build()).build());
    final PropertyTree regionAsData = new PropertyTree();
    // exercise
    regionSerializer.toData(region, regionAsData.getRoot());
    final RegionDescriptor regionDescriptor = RegionDescriptor.create().name("main").build();
    final List<PropertySet> components = regionAsData.getProperties(ComponentDataSerializer.COMPONENTS).stream().map(item -> item.getSet()).collect(Collectors.toList());
    final Region parsedRegion = regionSerializer.fromData(regionDescriptor, ComponentPath.DIVIDER, components);
    // verify
    assertEquals(region, parsedRegion);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) PropertySet(com.enonic.xp.data.PropertySet) RegionDescriptors(com.enonic.xp.region.RegionDescriptors) Collectors(java.util.stream.Collectors) ComponentPath(com.enonic.xp.region.ComponentPath) LayoutDescriptor(com.enonic.xp.region.LayoutDescriptor) Test(org.junit.jupiter.api.Test) Form(com.enonic.xp.form.Form) Region(com.enonic.xp.region.Region) Mockito(org.mockito.Mockito) List(java.util.List) LayoutComponent(com.enonic.xp.region.LayoutComponent) DescriptorKey(com.enonic.xp.page.DescriptorKey) AbstractDataSerializerTest(com.enonic.xp.core.impl.content.page.AbstractDataSerializerTest) ImageComponent(com.enonic.xp.region.ImageComponent) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) RegionDescriptor(com.enonic.xp.region.RegionDescriptor) PropertyTree(com.enonic.xp.data.PropertyTree) DescriptorKey(com.enonic.xp.page.DescriptorKey) Region(com.enonic.xp.region.Region) PropertySet(com.enonic.xp.data.PropertySet) 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 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 ComponentPath (com.enonic.xp.region.ComponentPath)1 ImageComponent (com.enonic.xp.region.ImageComponent)1 LayoutComponent (com.enonic.xp.region.LayoutComponent)1 LayoutDescriptor (com.enonic.xp.region.LayoutDescriptor)1 Region (com.enonic.xp.region.Region)1 RegionDescriptor (com.enonic.xp.region.RegionDescriptor)1 RegionDescriptors (com.enonic.xp.region.RegionDescriptors)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 Mockito (org.mockito.Mockito)1