예제 #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"));
  }
예제 #2
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();
  }
예제 #3
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();
  }
예제 #4
0
  protected final void setupNonPageContent() throws Exception {
    Mockito.when(
            this.contentService.getByPath(ContentPath.from("site/somepath/content").asAbsolute()))
        .thenReturn(createPage("id", "site/somepath/content", "myapplication:ctype", false));

    Mockito.when(this.contentService.getNearestSite(Mockito.isA(ContentId.class)))
        .thenReturn(createSite("id", "site", "myapplication:contenttypename"));
  }
예제 #5
0
  @Override
  protected void configure() throws Exception {
    this.contentService = Mockito.mock(ContentService.class);
    this.handler = new AttachmentHandler();
    this.handler.setContentService(this.contentService);

    this.request.setMethod(HttpMethod.GET);
    this.request.setContentPath(ContentPath.from("/path/to/content"));
    this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");

    setupMedia();
  }
예제 #6
0
  @Test
  public void getContentNotFound() throws Exception {
    Mockito.when(this.contentService.getByPath(Mockito.anyObject())).thenReturn(null);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));

    try {
      this.handler.handle(this.request);
      fail("Should throw exception");
    } catch (final PortalException e) {
      assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
      assertEquals("Page [/site/somepath/content] not found", e.getMessage());
    }
  }
예제 #7
0
  @Test
  public void getContentWithTemplateNotFound() throws Exception {
    setupContentAndSite();
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));

    try {
      this.handler.handle(this.request);
      fail("Should throw exception");
    } catch (final PortalException e) {
      assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
      assertEquals("Page template [my-page] not found", e.getMessage());
    }
  }
예제 #8
0
  @Override
  protected void configure() throws Exception {
    super.configure();

    this.handler = new PageHandler();
    this.handler.setContentService(this.contentService);
    this.handler.setPageDescriptorService(this.pageDescriptorService);
    this.handler.setPageTemplateService(this.pageTemplateService);
    this.handler.setRendererFactory(this.rendererFactory);
    this.handler.setPortalUrlService(this.portalUrlService);

    this.request.setMethod(HttpMethod.GET);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    this.request.setEndpointPath(null);
  }
예제 #9
0
  @Test
  public void getContentNotEnoughPermissions() throws Exception {
    Mockito.when(this.contentService.getByPath(Mockito.anyObject())).thenReturn(null);
    Mockito.when(this.contentService.contentExists(Mockito.any(ContentPath.class)))
        .thenReturn(true);

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

    try {
      this.handler.handle(this.request);
      fail("Should throw exception");
    } catch (final PortalException e) {
      assertEquals(HttpStatus.FORBIDDEN, e.getStatus());
      assertEquals("You don't have permission to access [/site/somepath/content]", e.getMessage());
    }
  }
예제 #10
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();
  }
예제 #11
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);
  }
예제 #12
0
  @Test
  public void getContentFound() throws Exception {
    setupContentAndSite();
    setupTemplates();

    final PortalResponse portalResponse =
        PortalResponse.create()
            .body("component rendered")
            .header("some-header", "some-value")
            .status(HttpStatus.OK)
            .build();

    setRendererResult(portalResponse);

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

    final PortalResponse res = this.handler.handle(this.request);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.PLAIN_TEXT_UTF_8, res.getContentType());
    assertEquals("some-value", res.getHeaders().get("some-header"));
    assertEquals("component rendered", res.getBody());
  }