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());
}
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());
}
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());
}
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();
}
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());
}
Aggregations