use of com.enonic.xp.page.PageRegions in project xp by enonic.
the class PageRegionsTest method getRegion.
@Test
public void getRegion() {
final PageRegions regions = PageRegions.create().add(Region.create().name("a-region").build()).add(Region.create().name("b-region").build()).add(Region.create().name("c-region").build()).build();
assertEquals("a-region", regions.getRegion("a-region").getName());
assertEquals("b-region", regions.getRegion("b-region").getName());
assertEquals("c-region", regions.getRegion("c-region").getName());
assertNull(regions.getRegion("no-region"));
}
use of com.enonic.xp.page.PageRegions in project xp by enonic.
the class PageRegionsTest method iterator.
@Test
public void iterator() {
final PageRegions regions = PageRegions.create().add(Region.create().name("a-region").build()).add(Region.create().name("b-region").build()).add(Region.create().name("c-region").build()).build();
Iterator<Region> iterator = regions.iterator();
Region nextRegion = iterator.next();
assertNotNull(nextRegion);
assertEquals("a-region", nextRegion.getName());
nextRegion = iterator.next();
assertNotNull(nextRegion);
assertEquals("b-region", nextRegion.getName());
nextRegion = iterator.next();
assertNotNull(nextRegion);
assertEquals("c-region", nextRegion.getName());
assertFalse(iterator.hasNext());
}
use of com.enonic.xp.page.PageRegions in project xp by enonic.
the class PageRegionsTest method getComponent_throws_exception.
@Test
public void getComponent_throws_exception() {
final PageRegions regions = PageRegions.create().add(Region.create().name("a-region").add(PartComponent.create().build()).add(PartComponent.create().build()).build()).build();
assertThrows(IllegalArgumentException.class, () -> regions.getComponent(ComponentPath.from("a-region/1/2/3")));
}
use of com.enonic.xp.page.PageRegions in project xp by enonic.
the class PageDataSerializer method getPageRegions.
private PageRegions getPageRegions(final DescriptorKey descriptorKey, final List<PropertySet> componentsAsData) {
final PageDescriptor pageDescriptor = pageDescriptorService.getByKey(descriptorKey);
final RegionDescriptors regionDescriptors = pageDescriptor.getRegions();
if (regionDescriptors.numberOfRegions() == 0) {
return null;
}
final PageRegions.Builder pageRegionsBuilder = PageRegions.create();
regionDescriptors.forEach(regionDescriptor -> {
pageRegionsBuilder.add(componentDataSerializerProvider.getRegionDataSerializer().fromData(regionDescriptor, ComponentPath.DIVIDER, componentsAsData));
});
return pageRegionsBuilder.build();
}
use of com.enonic.xp.page.PageRegions in project xp by enonic.
the class ComponentHandlerTest method createPageWithFragment.
private Content createPageWithFragment(final String id, final String path, final String contentTypeName, final boolean withPage) {
PropertyTree rootDataSet = new PropertyTree();
rootDataSet.addString("property1", "value1");
final Content.Builder content = Content.create().id(ContentId.from(id)).path(ContentPath.from(path)).owner(PrincipalKey.from("user:myStore:me")).displayName("My Content").modifier(PrincipalKey.from("user:system:admin")).type(ContentTypeName.from(contentTypeName));
if (withPage) {
PageRegions pageRegions = PageRegions.create().add(Region.create().name("main-region").add(FragmentComponent.create().fragment(ContentId.from("fragmentId")).build()).build()).build();
Page page = Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).config(rootDataSet).build();
content.page(page);
}
return content.build();
}
Aggregations