コード例 #1
0
  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();
  }
コード例 #2
0
ファイル: PageHandlerTest.java プロジェクト: mukeshSrana/xp
  @Test
  public void getContentShortcut() throws Exception {
    final PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addReference("target", Reference.from("ref"));

    final Content content =
        Content.create()
            .id(ContentId.from("id"))
            .path(ContentPath.from("site/somepath/shortcut"))
            .owner(PrincipalKey.from("user:myStore:me"))
            .displayName("My Content")
            .modifier(PrincipalKey.from("user:system:admin"))
            .type(ContentTypeName.shortcut())
            .data(rootDataSet)
            .build();

    Mockito.when(this.contentService.getByPath(content.getPath().asAbsolute())).thenReturn(content);
    Mockito.when(this.portalUrlService.pageUrl(Mockito.any(PageUrlParams.class)))
        .thenReturn("/master/site/otherpath");

    this.request.setContentPath(ContentPath.from("/site/somepath/shortcut"));

    final PortalResponse res = this.handler.handle(this.request);
    assertNotNull(res);
    assertEquals(HttpStatus.TEMPORARY_REDIRECT, res.getStatus());
    assertEquals("/master/site/otherpath", res.getHeaders().get("Location"));
  }
コード例 #3
0
ファイル: RenderBaseHandlerTest.java プロジェクト: enonic/xp
  private Content createPage(
      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(PartComponent.create().name(ComponentName.from("mypart")).build())
                      .build())
              .build();

      Page page =
          Page.create()
              .template(PageTemplateKey.from("my-page"))
              .regions(pageRegions)
              .config(rootDataSet)
              .build();
      content.page(page);
    }
    return content.build();
  }
コード例 #4
0
ファイル: EventTest.java プロジェクト: enonic/xp
  @Test
  public void testGetValueAs() {
    final Event testEvent =
        Event.create("type")
            .value("int1", 1)
            .value("long1", 10L)
            .value("obj1", ContentId.from("testId"))
            .build();

    assertTrue(testEvent.getValueAs(Double.class, "int1").get() != null);
    assertTrue(testEvent.getValueAs(Boolean.class, "long1").get() != null);
    assertTrue(testEvent.getValueAs(ContentId.class, "obj1").get() != null);
    assertFalse(testEvent.getValueAs(ContentId.class, "obj2").isPresent());
  }
コード例 #5
0
  private Site createSite(final String id, final String name, final String contentTypeName) {
    PropertyTree rootDataSet = new PropertyTree();
    rootDataSet.addString("property1", "value1");

    Page page = Page.create().template(PageTemplateKey.from("my-page")).config(rootDataSet).build();

    return Site.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();
  }
コード例 #6
0
  @Test
  public void testContentNotFoundById() throws Exception {
    Mockito.when(this.contentService.getByPath(Mockito.any()))
        .thenThrow(
            new ContentNotFoundException(
                ContentId.from("ee70f5d0-025c-4fbd-a835-5e50ff7b76ba"), Branch.from("draft")));

    SecurityService securityService = Mockito.mock(SecurityService.class);
    addService(SecurityService.class, securityService);

    final Optional<? extends Principal> value = Optional.of(User.ANONYMOUS);
    Mockito.<Optional<? extends Principal>>when(
            securityService.getPrincipal(Mockito.any(PrincipalKey.class)))
        .thenReturn(value);

    runFunction("/site/test/SetPermissionsHandlerTest.js", "setPermissionsNotFoundById");
  }
コード例 #7
0
  private Media createMedia(
      final String id, final String contentPath, final Attachment... attachments) {
    final PropertyTree data = new PropertyTree();
    data.addString("media", attachments[0].getName());

    return Media.create()
        .id(ContentId.from(id))
        .path(contentPath)
        .createdTime(Instant.now())
        .type(ContentTypeName.imageMedia())
        .owner(PrincipalKey.from("user:myStore:me"))
        .displayName("My Content")
        .modifiedTime(Instant.now())
        .modifier(PrincipalKey.from("user:system:admin"))
        .data(data)
        .attachments(Attachments.from(attachments))
        .build();
  }