Search in sources :

Example 11 with ContentPath

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

the class PageHandlerTest method getContentExistsButInsufficientRights.

@Test
public void getContentExistsButInsufficientRights() {
    final AuthenticationInfo authenticationInfo = AuthenticationInfo.create().user(User.ANONYMOUS).build();
    final Context authenticatedContext = ContextBuilder.from(ContextAccessor.current()).authInfo(authenticationInfo).build();
    final ContentPath path = ContentPath.from("/site/somepath/content");
    when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, Branch.from("draft")));
    when(this.contentService.contentExists(path)).thenReturn(true);
    this.request.setContentPath(path);
    final WebException e = assertThrows(WebException.class, () -> authenticatedContext.callWith(() -> this.handler.handle(this.request, PortalResponse.create().build(), null)));
    assertEquals(HttpStatus.FORBIDDEN, e.getStatus());
    assertEquals("You don't have permission to access [/site/somepath/content]", e.getMessage());
}
Also used : Context(com.enonic.xp.context.Context) WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Test(org.junit.jupiter.api.Test)

Example 12 with ContentPath

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

the class PageHandlerTest method getContentNotFound.

@Test
public void getContentNotFound() {
    final ContentPath path = ContentPath.from("/site/somepath/content");
    when(this.contentService.getByPath(path)).thenThrow(new ContentNotFoundException(path, Branch.from("draft")));
    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("Page [/site/somepath/content] not found", e.getMessage());
}
Also used : WebException(com.enonic.xp.web.WebException) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) ContentPath(com.enonic.xp.content.ContentPath) Test(org.junit.jupiter.api.Test)

Example 13 with ContentPath

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

the class GetContentHandlerTest method getByPathAndVersionId.

@Test
public void getByPathAndVersionId() {
    final Content content = TestDataFixtures.newExampleContent();
    final ContentPath path = ContentPath.from("/a/b/mycontent");
    final ContentVersionId versionId = ContentVersionId.from("versionId");
    Mockito.when(this.contentService.getByPathAndVersionId(path, versionId)).thenReturn(content);
    runFunction("/test/GetContentHandlerTest.js", "getByPathAndVersionId");
}
Also used : Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) ContentVersionId(com.enonic.xp.content.ContentVersionId) Test(org.junit.jupiter.api.Test)

Example 14 with ContentPath

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

the class PageUrlBuilder method buildUrl.

@Override
protected void buildUrl(final StringBuilder url, final Multimap<String, String> params) {
    super.buildUrl(url, params);
    final ContentPath resolved = resolvePath();
    appendPart(url, resolved.toString());
}
Also used : ContentPath(com.enonic.xp.content.ContentPath)

Example 15 with ContentPath

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

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