Search in sources :

Example 6 with Site

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

the class ContentFixtures method newSite.

public static Site newSite() {
    final PropertyTree siteConfigConfig = new PropertyTree();
    siteConfigConfig.setLong("Field", 42L);
    final SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapplication")).config(siteConfigConfig).build();
    final Site.Builder site = Site.create();
    site.id(ContentId.from("100123"));
    site.siteConfigs(SiteConfigs.from(siteConfig));
    site.name("my-content");
    site.parentPath(ContentPath.ROOT);
    return site.build();
}
Also used : Site(com.enonic.xp.site.Site) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 7 with Site

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

the class ControllerMappingsResolverTest method testNoDescriptors.

@Test
public void testNoDescriptors() {
    final Content content = newContent();
    final Site site = newSite();
    final ControllerMappingsResolver resolver = new ControllerMappingsResolver(this.siteService);
    final Optional<ControllerMappingDescriptor> mapping = resolver.resolve("/landing-page", ImmutableMultimap.of(), content, site.getSiteConfigs());
    assertTrue(mapping.isEmpty());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) Test(org.junit.jupiter.api.Test)

Example 8 with Site

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

the class PageResolverTest method given_Content_without_Page_then_effective_Page_is_same_as_in_Template.

@Test
public void given_Content_without_Page_then_effective_Page_is_same_as_in_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()).build();
    Content content = Content.create().parentPath(site.getPath()).name("my-content").build();
    when(pageTemplateService.getDefault(notNull())).thenReturn(template);
    // exercise
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    // verify
    assertEquals(configA, effectivePage.getConfig());
    assertEquals(regionsA, effectivePage.getRegions());
    assertNull(effectivePage.getDescriptor());
    assertEquals(template.getKey(), effectivePage.getTemplate());
    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 9 with Site

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

the class PageResolverTest method given_Content_with_Page_without_config_then_effective_Page_gets_config_from_Template.

@Test
public void given_Content_with_Page_without_config_then_effective_Page_gets_config_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").page(Page.create().template(template.getKey()).regions(regionsB).build()).type(ContentTypeName.templateFolder()).build();
    when(pageTemplateService.getByKey(template.getKey())).thenReturn(template);
    // exercise
    PageResolverResult result = pageResolver.resolve(RenderMode.LIVE, content, site);
    final Page effectivePage = result.getEffectivePage();
    // verify
    assertEquals(configA, effectivePage.getConfig());
    assertEquals(regionsB, effectivePage.getRegions());
    assertEquals(template.getKey(), effectivePage.getTemplate());
    assertNull(effectivePage.getDescriptor());
}
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 10 with Site

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

the class PageResolverTest method content_with_Page_without_template_or_descriptor.

@Test
public void content_with_Page_without_template_or_descriptor() {
    Site site = Site.create().id(ContentId.from("site-id")).path(ContentPath.from("/site")).displayName("My Site").type(ContentTypeName.from("portal:site")).build();
    final Page page = Page.create().build();
    Content content = Content.create().page(page).parentPath(site.getPath()).name("my-content").build();
    final WebException webExceptionInLive = assertThrows(WebException.class, () -> pageResolver.resolve(RenderMode.LIVE, content, site));
    assertEquals(HttpStatus.NOT_FOUND, webExceptionInLive.getStatus());
    assertEquals(webExceptionInLive.getMessage(), "Content page has neither template nor descriptor");
    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(page, effectivePage);
    assertNull(result.getController());
    verifyNoInteractions(pageTemplateService);
}
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)

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