Search in sources :

Example 31 with ContentNotFoundException

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

the class PortalUrlServiceImpl_imageUrlTest method createContentNotFound.

private Content createContentNotFound() {
    final Content content = ContentFixtures.newContent();
    Mockito.when(this.contentService.getByPath(content.getPath())).thenThrow(new ContentNotFoundException(content.getPath(), Branch.from("draft")));
    Mockito.when(this.contentService.getById(content.getId())).thenThrow(new ContentNotFoundException(content.getId(), Branch.from("draft")));
    return content;
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) Content(com.enonic.xp.content.Content)

Example 32 with ContentNotFoundException

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

the class PortalUrlServiceImpl_processHtmlTest method process_unknown_content.

@Test
public void process_unknown_content() {
    when(contentService.getById(isA(ContentId.class))).thenAnswer((params) -> {
        final ContentId id = params.getArgument(0);
        throw new ContentNotFoundException(id, ContextAccessor.current().getBranch());
    });
    // Process an html text containing a link to an unknown content
    final ProcessHtmlParams params = new ProcessHtmlParams().portalRequest(this.portalRequest).value("<a href=\"content://123\">Content</a>");
    // Checks that the error 500 page is returned
    final String processedHtml = this.service.processHtml(params);
    assertEquals("<a href=\"/site/default/draft/context/path/_/error/404?message=Content+with+id+%5B123%5D+was+not+found+in+branch+%5Bdraft%5D\">Content</a>", processedHtml);
}
Also used : ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ProcessHtmlParams(com.enonic.xp.portal.url.ProcessHtmlParams) ContentId(com.enonic.xp.content.ContentId) 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