Search in sources :

Example 31 with PortalRequest

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());
}
Also used : 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 32 with PortalRequest

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());
}
Also used : Content(com.enonic.xp.content.Content) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 33 with PortalRequest

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());
}
Also used : Site(com.enonic.xp.site.Site) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 34 with PortalRequest

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());
}
Also used : Site(com.enonic.xp.site.Site) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 35 with PortalRequest

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

Aggregations

PortalRequest (com.enonic.xp.portal.PortalRequest)103 Test (org.junit.jupiter.api.Test)47 BeforeEach (org.junit.jupiter.api.BeforeEach)35 PortalResponse (com.enonic.xp.portal.PortalResponse)25 Site (com.enonic.xp.site.Site)19 Content (com.enonic.xp.content.Content)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ApplicationKey (com.enonic.xp.app.ApplicationKey)10 ContentPath (com.enonic.xp.content.ContentPath)10 ContentService (com.enonic.xp.content.ContentService)10 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)10 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ResourceService (com.enonic.xp.resource.ResourceService)9 ContentId (com.enonic.xp.content.ContentId)7 Matcher (java.util.regex.Matcher)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)7 Assertions.fail (org.junit.jupiter.api.Assertions.fail)7 Mockito.when (org.mockito.Mockito.when)7