use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ContentResolverTest method resolve_not_found_edit_mode.
@Test
void resolve_not_found_edit_mode() {
final PortalRequest request = new PortalRequest();
request.setMode(RenderMode.EDIT);
final ContentPath contentPath = ContentPath.from("/c8da0c10-0002-4b68-b407-87412f3e45c8");
request.setContentPath(contentPath);
when(this.contentService.getById(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"))).thenThrow(new ContentNotFoundException(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"), null));
when(this.contentService.getByPath(contentPath)).thenThrow(new ContentNotFoundException(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"), null));
final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
assertNull(result.getContent());
assertNull(result.getNearestSite());
assertNull(result.getSiteRelativePath());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ContentResolverTest method resolve_root_edit_mode.
@Test
void resolve_root_edit_mode() {
final PortalRequest request = new PortalRequest();
request.setMode(RenderMode.EDIT);
request.setContentPath(ContentPath.from("/c8da0c10-0002-4b68-b407-87412f3e45c8"));
final Content rootContent = mock(Content.class);
when(rootContent.getPath()).thenReturn(ContentPath.ROOT);
when(this.contentService.getById(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"))).thenReturn(rootContent);
final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
assertNull(result.getContent());
assertNull(result.getNearestSite());
assertNull(result.getSiteRelativePath());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ContentResolverTest method resolve_found_by_path_edit_mode.
@Test
void resolve_found_by_path_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"))).thenThrow(new ContentNotFoundException(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"), null));
when(this.contentService.getByPath(ContentPath.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());
}
use of com.enonic.xp.portal.PortalRequest 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.portal.PortalRequest 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());
}
Aggregations