use of com.enonic.xp.web.WebException in project xp by enonic.
the class PageHandlerTest method getContentExistsButNeedsAuthentication.
@Test
public void getContentExistsButNeedsAuthentication() {
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, () -> this.handler.handle(this.request, PortalResponse.create().build(), null));
assertEquals(HttpStatus.UNAUTHORIZED, e.getStatus());
assertEquals("You don't have permission to access [/site/somepath/content]", e.getMessage());
}
use of com.enonic.xp.web.WebException 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.web.WebException 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.web.WebException in project xp by enonic.
the class AssetHandlerTest method testSiteResourceNotFound.
@Test
public void testSiteResourceNotFound() throws Exception {
addResource("demo:/site/assets/css/main.css");
final WebException ex = assertThrows(WebException.class, () -> {
this.handler.handle(this.request, PortalResponse.create().build(), null);
});
assertEquals("Resource [demo:/assets/css/main.css] not found", ex.getMessage());
}
use of com.enonic.xp.web.WebException in project xp by enonic.
the class MappingHandlerTest method methodNotAllowed.
@Test
public void methodNotAllowed() {
final PortalResponse response = PortalResponse.create().build();
this.request.setBaseUri("/admin/site");
this.request.setContentPath(ContentPath.from("/site/content"));
this.request.setMethod(HttpMethod.LOCK);
final WebException webException = assertThrows(WebException.class, () -> this.handler.handle(this.request, response, null));
assertEquals(HttpStatus.METHOD_NOT_ALLOWED, webException.getStatus());
}
Aggregations