Search in sources :

Example 6 with ContentNotFoundException

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

the class GetContentHandlerTest method getByIdAndVersionId_NotFound.

@Test
public void getByIdAndVersionId_NotFound() {
    final ContentId contentId = ContentId.from("mycontentId");
    final ContentVersionId versionId = ContentVersionId.from("versionId");
    Mockito.when(this.contentService.getByIdAndVersionId(contentId, versionId)).thenThrow(new ContentNotFoundException(contentId, versionId, ContextAccessor.current().getBranch()));
    runFunction("/test/GetContentHandlerTest.js", "getByIdAndVersionId_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentId(com.enonic.xp.content.ContentId) ContentVersionId(com.enonic.xp.content.ContentVersionId) Test(org.junit.jupiter.api.Test)

Example 7 with ContentNotFoundException

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

the class DeleteContentHandlerTest method deleteByPath_notFound.

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

Example 8 with ContentNotFoundException

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

the class GetAttachmentsHandlerTest method getById_notFound.

@Test
public void getById_notFound() throws Exception {
    final ContentId id = ContentId.from("123456");
    Mockito.when(this.contentService.getById(id)).thenThrow(new ContentNotFoundException(id, null));
    runFunction("/test/GetAttachmentsHandlerTest.js", "getById_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentId(com.enonic.xp.content.ContentId) Test(org.junit.jupiter.api.Test)

Example 9 with ContentNotFoundException

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

the class GetAttachmentsHandlerTest 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/GetAttachmentsHandlerTest.js", "getByPath_notFound");
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 10 with ContentNotFoundException

use of com.enonic.xp.content.ContentNotFoundException 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

ContentNotFoundException (com.enonic.xp.content.ContentNotFoundException)32 Test (org.junit.jupiter.api.Test)26 ContentPath (com.enonic.xp.content.ContentPath)13 ContentId (com.enonic.xp.content.ContentId)12 Content (com.enonic.xp.content.Content)8 WebException (com.enonic.xp.web.WebException)6 Page (com.enonic.xp.page.Page)4 PortalRequest (com.enonic.xp.portal.PortalRequest)4 Site (com.enonic.xp.site.Site)4 ProcessHtmlParams (com.enonic.xp.portal.url.ProcessHtmlParams)3 ContentVersionId (com.enonic.xp.content.ContentVersionId)2 PrincipalKey (com.enonic.xp.security.PrincipalKey)2 SecurityService (com.enonic.xp.security.SecurityService)2 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)1 UpdateContentParams (com.enonic.xp.content.UpdateContentParams)1 Context (com.enonic.xp.context.Context)1 Node (com.enonic.xp.node.Node)1 NodeIds (com.enonic.xp.node.NodeIds)1 NodePath (com.enonic.xp.node.NodePath)1 EditablePage (com.enonic.xp.page.EditablePage)1