Search in sources :

Example 31 with Site

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

the class ContentResolverTest method resolve_self_in_live_mode.

@Test
void resolve_self_in_live_mode() {
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    request.setContentPath(ContentPath.from("/mysite"));
    when(this.contentService.getByPath(ContentPath.from("/mysite"))).thenReturn(site);
    when(this.contentService.findNearestSiteByPath(ContentPath.from("/mysite"))).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertSame(site, result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/", result.getSiteRelativePath());
}
Also used : Site(com.enonic.xp.site.Site) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 32 with Site

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

the class ContentResolverTest method resolve_existing_but_needs_authentication_in_live_mode.

@Test
void resolve_existing_but_needs_authentication_in_live_mode() {
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    final ContentPath contentPath = ContentPath.from("/mysite/landing-page/non-existing");
    request.setContentPath(contentPath);
    when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(contentPath, null));
    when(this.contentService.contentExists(contentPath)).thenReturn(true);
    when(this.contentService.findNearestSiteByPath(contentPath)).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertNull(result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page/non-existing", result.getSiteRelativePath());
    final WebException e = assertThrows(WebException.class, result::getContentOrElseThrow);
    assertEquals(HttpStatus.UNAUTHORIZED, e.getStatus());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 33 with Site

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

the class ContentResolverTest method resolve_non_existing_in_live_mode.

@Test
void resolve_non_existing_in_live_mode() {
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    final ContentPath contentPath = ContentPath.from("/mysite/landing-page/non-existing");
    request.setContentPath(contentPath);
    when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(contentPath, null));
    when(this.contentService.contentExists(contentPath)).thenReturn(false);
    when(this.contentService.findNearestSiteByPath(contentPath)).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertNull(result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page/non-existing", result.getSiteRelativePath());
    final WebException e = assertThrows(WebException.class, result::getContentOrElseThrow);
    assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
}
Also used : Site(com.enonic.xp.site.Site) WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 34 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 35 with Site

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

the class ContentResolverTest method resolve_in_edit_mode.

@Test
void resolve_in_edit_mode() {
    final Content content = newContent();
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    request.setMode(RenderMode.EDIT);
    request.setContentPath(ContentPath.from("/c8da0c10-0002-4b68-b407-87412f3e45c8"));
    when(this.contentService.getById(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"))).thenReturn(content);
    when(this.contentService.getNearestSite(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"))).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertSame(content, result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page", result.getSiteRelativePath());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) PortalRequest(com.enonic.xp.portal.PortalRequest) 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