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