Exemplo n.º 1
0
  @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"));
  }
  @Test
  public void createUrl_withId() {
    final Content content = ContentFixtures.newContent();
    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);

    final PageUrlParams params = new PageUrlParams().portalRequest(this.portalRequest).id("123456");

    final String url = this.service.pageUrl(params);
    assertEquals("/portal/draft/a/b/mycontent", url);
  }
Exemplo n.º 3
0
  protected final void setupContentAndSite() throws Exception {
    final Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);

    Mockito.when(
            this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute()))
        .thenReturn(content);

    Mockito.when(this.contentService.getNearestSite(Mockito.isA(ContentId.class)))
        .thenReturn(createSite("id", "site", "myapplication:contenttypename"));

    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
  }
  @Test
  public void createUrl_withId_notFound() {
    final Content content = ContentFixtures.newContent();
    Mockito.when(this.contentService.getById(content.getId()))
        .thenThrow(new ContentNotFoundException(content.getId(), Branch.from("draft")));

    final PageUrlParams params = new PageUrlParams().portalRequest(this.portalRequest).id("123456");

    final String url = this.service.pageUrl(params);
    assertEquals(
        "/portal/draft/context/path/_/error/404?message=Content+with+id+%5B123456%5D+was+not+found+in+branch+%5Bdraft%5D",
        url);
  }
Exemplo n.º 5
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();
  }
Exemplo n.º 6
0
  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();
  }
Exemplo n.º 7
0
  protected final void setupCustomizedTemplateContentAndSite() throws Exception {
    Content content = createPage("id", "site/somepath/content", "myapplication:ctype", true);
    final PageDescriptor controllerDescriptor = createDescriptor();
    Page page =
        Page.create(content.getPage())
            .template(null)
            .controller(controllerDescriptor.getKey())
            .build();
    content = Content.create(content).page(page).build();

    Mockito.when(
            this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute()))
        .thenReturn(content);

    Mockito.when(this.contentService.getNearestSite(Mockito.isA(ContentId.class)))
        .thenReturn(createSite("id", "site", "myapplication:contenttypename"));

    Mockito.when(this.contentService.getById(content.getId())).thenReturn(content);
  }
Exemplo n.º 8
0
 public static Builder create(final ContentTypeName type) {
   if (type.isPageTemplate()) {
     final PageTemplate.Builder builder = PageTemplate.newPageTemplate();
     builder.type(type);
     return builder;
   } else if (type.isSite()) {
     Site.Builder builder = Site.create();
     builder.type(type);
     return builder;
   } else if (type.isDescendantOfMedia()) {
     Media.Builder builder = Media.create();
     builder.type(type);
     return builder;
   } else {
     Builder builder = Content.create();
     builder.type(type);
     return builder;
   }
 }