@Test
  public void testBuilder() {
    final LayoutDescriptors layoutDescriptors =
        LayoutDescriptors.create()
            .add(
                LayoutDescriptor.create()
                    .name("fancy-layout")
                    .displayName("Fancy layout")
                    .config(Form.create().build())
                    .regions(RegionDescriptors.create().build())
                    .key(DescriptorKey.from("module:fancy-layout"))
                    .build())
            .add(
                LayoutDescriptor.create()
                    .name("fancy-layout2")
                    .displayName("Fancy layout2")
                    .config(Form.create().build())
                    .regions(RegionDescriptors.create().build())
                    .key(DescriptorKey.from("module:fancy-layout2"))
                    .build())
            .build();

    assertEquals(2, layoutDescriptors.getSize());
    assertNotNull(layoutDescriptors.getDescriptor("fancy-layout"));
    assertNotNull(layoutDescriptors.getDescriptor(DescriptorKey.from("module:fancy-layout2")));
  }
  @Test
  public void test_get_widgets_by_interface() throws Exception {

    final WidgetDescriptor widgetDescriptor1 =
        WidgetDescriptor.create()
            .displayName("My widget")
            .addInterface("com.enonic.xp.my-interface")
            .addInterface("com.enonic.xp.my-interface-2")
            .key(DescriptorKey.from("myapp:my-widget"))
            .build();

    final WidgetDescriptor widgetDescriptor2 =
        WidgetDescriptor.create()
            .displayName("My second widget")
            .key(DescriptorKey.from("myapp:my-second-widget"))
            .build();

    WidgetDescriptors widgetDescriptors =
        WidgetDescriptors.from(widgetDescriptor1, widgetDescriptor2);

    Mockito.when(widgetDescriptorService.getByInterface(Mockito.any()))
        .thenReturn(widgetDescriptors);

    String jsonString =
        request().path("widget").queryParam("interface", "someInterfaceName").get().getAsString();

    assertJson("get_widgets_by_interface.json", jsonString);
  }
  private Content createPage(final String id, final String name, final String contentTypeName) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");

    Region region =
        Region.create()
            .name("myRegion")
            .add(
                PartComponent.create()
                    .name("myPartComponent")
                    .descriptor(DescriptorKey.from("myapplication:myparttemplate"))
                    .build())
            .build();

    PageRegions pageRegions = PageRegions.create().add(region).build();
    Page page =
        Page.create().template(PageTemplateKey.from("my-page")).regions(pageRegions).build();

    return Content.create()
        .id(ContentId.from(id))
        .path(ContentPath.from(name))
        .owner(PrincipalKey.from("user:myStore:me"))
        .displayName("My Content")
        .modifier(PrincipalKey.from("user:system:admin"))
        .type(ContentTypeName.from(contentTypeName))
        .page(page)
        .build();
  }
Exemple #4
0
  private PageTemplate createPageTemplate() {
    final PropertyTree pageTemplateConfig = new PropertyTree();
    pageTemplateConfig.addLong("pause", 10000L);

    PageRegions pageRegions =
        PageRegions.create()
            .add(
                Region.create()
                    .name("main-region")
                    .add(PartComponent.create().name(ComponentName.from("mypart")).build())
                    .build())
            .build();

    final PageTemplate.Builder builder =
        PageTemplate.newPageTemplate()
            .key(PageTemplateKey.from("abc"))
            .canRender(ContentTypeNames.from("myapplication:article", "myapplication:banner"))
            .regions(pageRegions)
            .config(pageTemplateConfig);

    builder.controller(DescriptorKey.from("mainapplication:landing-page"));

    builder.displayName("Main page template");
    builder.displayName("Main page template");
    builder.name("main-page-template");
    builder.parentPath(ContentPath.ROOT);

    return builder.build();
  }
 private PageTemplate createPageTemplate() {
   return PageTemplate.newPageTemplate()
       .key(PageTemplateKey.from("my-page"))
       .controller(DescriptorKey.from("myapplication:mypagetemplate"))
       .name("my-page-template")
       .parentPath(ContentPath.ROOT)
       .build();
 }
Exemple #6
0
  private PageDescriptor createDescriptor() throws Exception {
    final ApplicationKey applicationKey = ApplicationKey.from("mainapplication");
    final String name = "mypage";
    final DescriptorKey key = DescriptorKey.from(applicationKey, name);

    final String xml =
        "<?xml version=\"1.0\"?>\n"
            + "<page>\n"
            + "  <display-name>Landing page</display-name>\n"
            + "  <config/>\n"
            + "</page>";
    final PageDescriptor.Builder builder = PageDescriptor.create();

    parseXml(applicationKey, builder, xml);

    return builder.key(key).displayName("Landing page").build();
  }
 private Component createPartComponent() {
   return PartComponent.create()
       .name("myPartComponent")
       .descriptor(DescriptorKey.from("myapplication:myparttemplate"))
       .build();
 }
Exemple #8
0
 public static ResourceKey toResourceKey(final DescriptorKey key) {
   return ResourceKey.from(
       key.getApplicationKey(), "site/layouts/" + key.getName() + "/" + key.getName() + ".xml");
 }
Exemple #9
0
 @Override
 public ResourceKey getComponentPath() {
   final DescriptorKey key = this.getKey();
   return ResourceKey.from(key.getApplicationKey(), "site/layouts/" + key.getName());
 }