Search in sources :

Example 6 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class GetContentHandlerTest method getByPathAndVersionId_NotFound.

@Test
public void getByPathAndVersionId_NotFound() {
    final ContentPath path = ContentPath.from("/a/b/mycontent");
    final ContentVersionId versionId = ContentVersionId.from("versionId");
    Mockito.when(this.contentService.getByPathAndVersionId(path, versionId)).thenThrow(new ContentNotFoundException(path, versionId, ContextAccessor.current().getBranch()));
    runFunction("/test/GetContentHandlerTest.js", "getByPathAndVersionId_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) ContentVersionId(com.enonic.xp.content.ContentVersionId) Test(org.junit.jupiter.api.Test)

Example 7 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class GetAttachmentStreamHandlerTest method getByPath_notFound.

@Test
public void getByPath_notFound() throws Exception {
    final ContentPath path = ContentPath.from("/a/b/mycontent");
    Mockito.when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, null));
    runFunction("/test/GetAttachmentStreamHandlerTest.js", "getAttachmentStreamByPath_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 8 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class MoveContentHandlerTest method testExample.

@Test
public void testExample() {
    // example 1
    final Content sourceContent = mockContent("/my-site/my-content-name");
    mockGetByPath("/my-site/my-content-name", sourceContent);
    mockRename(sourceContent.getId(), "new-name", mockContent("/my-site/new-name"));
    // example 2
    mockMove(sourceContent.getId(), "/my-site/folder/", mockContent("/my-site/folder/my-content-name"));
    // example 3
    mockGetById("8d933461-ede7-4dd5-80da-cb7de0cd7bba", sourceContent);
    final ContentPath cp = ContentPath.from("/my-site/folder/existing-content");
    when(contentService.contentExists(cp)).thenReturn(true);
    runScript("/lib/xp/examples/content/move.js");
}
Also used : Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 9 with ContentPath

use of com.enonic.xp.content.ContentPath 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 10 with ContentPath

use of com.enonic.xp.content.ContentPath in project xp by enonic.

the class PageHandlerTest method getSiteNotFound.

@Test
public void getSiteNotFound() {
    setupContent();
    final ContentPath path = ContentPath.from("/site/somepath/content");
    when(this.contentService.findNearestSiteByPath(path)).thenReturn(null);
    this.request.setContentPath(path);
    final WebException e = assertThrows(WebException.class, () -> this.handler.handle(this.request, PortalResponse.create().build(), null));
    assertEquals(HttpStatus.NOT_FOUND, e.getStatus());
    assertEquals("Site for [/site/somepath/content] not found", e.getMessage());
}
Also used : WebException(com.enonic.xp.web.WebException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Aggregations

ContentPath (com.enonic.xp.content.ContentPath)56 Content (com.enonic.xp.content.Content)30 Test (org.junit.jupiter.api.Test)30 ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)13 ContentId (com.enonic.xp.content.ContentId)11 FindContentByParentParams (com.enonic.xp.content.FindContentByParentParams)10 WebException (com.enonic.xp.web.WebException)8 FindContentByParentResult (com.enonic.xp.content.FindContentByParentResult)6 ArrayList (java.util.ArrayList)5 FindContentIdsByParentResult (com.enonic.xp.content.FindContentIdsByParentResult)4 Node (com.enonic.xp.node.Node)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 ContentInheritType (com.enonic.xp.content.ContentInheritType)3 Context (com.enonic.xp.context.Context)3 Site (com.enonic.xp.site.Site)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 CONTENT_ROOT_PATH_ATTRIBUTE (com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE)2 ContentVersionId (com.enonic.xp.content.ContentVersionId)2 List (java.util.List)2 Set (java.util.Set)2