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