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