Search in sources :

Example 46 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class PageResolverTest method content_with_Page_but_template_was_deleted_fallback_to_default_not_found.

@Test
public void content_with_Page_but_template_was_deleted_fallback_to_default_not_found() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    Content content = Content.create().parentPath(site.getPath()).id(ContentId.from("content-id")).name("my-content").page(Page.create().template(PageTemplateKey.from("t-not-exists")).build()).type(ContentTypeName.templateFolder()).build();
    final WebException webExceptionInLive = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.LIVE, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInLive.getStatus());
    assertEquals(webExceptionInLive.getMessage(), "Template [t-not-exists] is missing and no default template found for content");
    final WebException webExceptionInInline = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.INLINE, content, site));
    assertEquals(HttpStatus.IM_A_TEAPOT, webExceptionInInline.getStatus());
    final WebException webExceptionInPreview = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.PREVIEW, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInPreview.getStatus());
    final PageResolverResult result = pageResolver.resolve(RenderMode.EDIT, content, site);
    final Page effectivePage = result.getEffectivePage();
    assertSame(content.getPage(), effectivePage);
    assertNull(result.getController());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 47 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class PageResolverTest method given_Content_with_Page_without_regions_then_effective_Page_gets_regions_from_Template.

@Test
public void given_Content_with_Page_without_regions_then_effective_Page_gets_regions_from_Template() {
    // setup
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    PageTemplate template = PageTemplate.newPageTemplate().key(PageTemplateKey.from("t-1")).parentPath(site.getPath()).name("my-template").page(Page.create().descriptor(DescriptorKey.from("myapp:my-descriptor")).config(configA).regions(regionsA).build()).canRender(ContentTypeNames.from(ContentTypeName.templateFolder())).build();
    Content content = Content.create().parentPath(site.getPath()).name("my-content").type(ContentTypeName.templateFolder()).page(Page.create().template(template.getKey()).config(configB).build()).build();
    when(pageTemplateService.getByKey(template.getKey())).thenReturn(template);
    // exercise
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    // verify
    assertEquals(regionsA, effectivePage.getRegions());
    assertEquals(configB, effectivePage.getConfig());
    assertEquals(template.getKey(), effectivePage.getTemplate());
    assertNull(effectivePage.getDescriptor());
    assertEquals(DescriptorKey.from("myapp:my-descriptor"), result.getController());
}
Also used : Site(com.enonic.xp.site.Site) PageTemplate(com.enonic.xp.page.PageTemplate) Content(com.enonic.xp.content.Content) Page(com.enonic.xp.page.Page) Test(org.junit.jupiter.api.Test)

Example 48 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class ContentServiceImpl method getNearestSite.

@Override
public Site getNearestSite(final ContentId contentId) {
    final Trace trace = Tracer.newTrace("content.getNearestSite");
    if (trace == null) {
        return doGetNearestSite(contentId);
    }
    return Tracer.trace(trace, () -> {
        trace.put("id", contentId);
        final Site site = doGetNearestSite(contentId);
        if (site != null) {
            trace.put("path", site.getPath());
        }
        return site;
    });
}
Also used : Trace(com.enonic.xp.trace.Trace) Site(com.enonic.xp.site.Site)

Example 49 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class MoveContentCommandTest method move_fragment_to_the_same_site.

@Test
public void move_fragment_to_the_same_site() throws Exception {
    final PropertyTree existingContentData = new PropertyTree();
    existingContentData.addString("myData", "aaa");
    final Site parentSite = createSite(existingContentData, ContentPath.ROOT);
    final Content existingContent = createContent(existingContentData, parentSite.getPath(), ContentTypeName.fragment());
    final Content existingFolder = createContent(existingContentData, parentSite.getPath(), ContentTypeName.folder());
    MoveContentParams params = MoveContentParams.create().contentId(existingContent.getId()).parentContentPath(existingFolder.getPath()).build();
    final MoveContentCommand command = MoveContentCommand.create(params).contentTypeService(this.contentTypeService).nodeService(this.nodeService).translator(this.translator).eventPublisher(this.eventPublisher).build();
    final Node mockNode = Node.create().parentPath(NodePath.ROOT).build();
    Mockito.when(nodeService.getById(NodeId.from(existingContent.getId()))).thenReturn(mockNode);
    Mockito.when(nodeService.move(Mockito.any(MoveNodeParams.class))).thenReturn(mockNode);
    Mockito.when(translator.fromNode(mockNode, true)).thenReturn(existingContent);
    Mockito.when(translator.fromNode(mockNode, false)).thenReturn(existingContent);
    final Node mockFolderNode = Node.create().parentPath(NodePath.ROOT).build();
    Mockito.when(nodeService.getByPath(ContentNodeHelper.translateContentPathToNodePath(existingFolder.getPath()))).thenReturn(mockFolderNode);
    Mockito.when(translator.fromNode(mockFolderNode, true)).thenReturn(existingFolder);
    Mockito.when(translator.fromNode(mockFolderNode, false)).thenReturn(existingFolder);
    final ContentType contentType = ContentType.create().name("folder").displayName("folder").setBuiltIn().setFinal(false).setAbstract(false).build();
    Mockito.when(contentTypeService.getByName(new GetContentTypeParams().contentTypeName(existingFolder.getType()))).thenReturn(contentType);
    // exercise
    command.execute();
    Mockito.verify(nodeService, Mockito.times(1)).move(Mockito.any(MoveNodeParams.class));
}
Also used : Site(com.enonic.xp.site.Site) MoveNodeParams(com.enonic.xp.node.MoveNodeParams) GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) ContentType(com.enonic.xp.schema.content.ContentType) MoveContentParams(com.enonic.xp.content.MoveContentParams) Content(com.enonic.xp.content.Content) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 50 with Site

use of com.enonic.xp.site.Site in project xp by enonic.

the class GetNearestSiteCommandTest method get_nearest_site_content_is_site.

@Test
public void get_nearest_site_content_is_site() throws Exception {
    final Node node = Node.create().id(NodeId.from("test")).name("myContent").parentPath(ContentConstants.CONTENT_ROOT_PATH).build();
    final ContentId contentId = ContentId.from("aaa");
    final Site site = Site.create().path("/mycontent").id(contentId).build();
    Mockito.when(this.nodeService.getById(Mockito.any(NodeId.class))).thenReturn(node);
    Mockito.when(this.translator.fromNode(node, true)).thenReturn(site);
    assertEquals(site, createCommand(contentId).execute());
}
Also used : Site(com.enonic.xp.site.Site) Node(com.enonic.xp.node.Node) NodeId(com.enonic.xp.node.NodeId) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Aggregations

Site (com.enonic.xp.site.Site)78 Test (org.junit.jupiter.api.Test)51 Content (com.enonic.xp.content.Content)41 PortalRequest (com.enonic.xp.portal.PortalRequest)17 PropertyTree (com.enonic.xp.data.PropertyTree)14 Page (com.enonic.xp.page.Page)12 ContentId (com.enonic.xp.content.ContentId)10 ContentPath (com.enonic.xp.content.ContentPath)10 SiteConfig (com.enonic.xp.site.SiteConfig)10 WebException (com.enonic.xp.web.WebException)10 ApplicationKey (com.enonic.xp.app.ApplicationKey)9 PageTemplate (com.enonic.xp.page.PageTemplate)8 PortalResponse (com.enonic.xp.portal.PortalResponse)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 SiteConfigs (com.enonic.xp.site.SiteConfigs)5 Branch (com.enonic.xp.branch.Branch)4 ContentService (com.enonic.xp.content.ContentService)4