use of com.enonic.xp.site.Site in project xp by enonic.
the class ExceptionRendererImplTest method newSite.
private Site newSite() {
final PropertyTree siteConfigConfig = new PropertyTree();
siteConfigConfig.setLong("Field", 42L);
final SiteConfig siteConfig = SiteConfig.create().application(ApplicationKey.from("myapplication")).config(siteConfigConfig).build();
final Site.Builder site = Site.create();
site.id(ContentId.from("100123"));
site.siteConfigs(SiteConfigs.from(siteConfig));
site.name("my-content");
site.parentPath(ContentPath.ROOT);
return site.build();
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class ExceptionRendererImplTest method render_default_error_page_when_error_in_custom_handler.
@Test
void render_default_error_page_when_error_in_custom_handler() {
this.request.getHeaders().put(HttpHeaders.ACCEPT, "text/html,text/*");
final Site site = newSite();
this.request.setSite(site);
final ResourceKey errorResource = ResourceKey.from(ApplicationKey.from("myapplication"), "site/error/error.js");
final ErrorHandlerScript errorHandlerScript = (portalError, handleMethod) -> {
throw new RuntimeException("Something went wrong in the handler script");
};
when(this.errorHandlerScriptFactory.errorScript(errorResource)).thenReturn(errorHandlerScript);
final Resource resource = mock(Resource.class);
when(resource.exists()).thenReturn(true);
when(this.resourceService.getResource(errorResource)).thenReturn(resource);
final RuntimeException cause = new RuntimeException("Custom message");
final PortalResponse res = this.renderer.render(this.request, new WebException(HttpStatus.BAD_REQUEST, cause));
final String body = res.getBody().toString();
assertTrue(body.contains("400 Bad Request"));
assertTrue(body.contains("Custom message"));
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class ExceptionRendererImplTest method render_custom_error_for_404_in_site_path.
@Test
void render_custom_error_for_404_in_site_path() {
this.request.getHeaders().put(HttpHeaders.ACCEPT, "text/html,text/*");
this.request.setContentPath(ContentPath.from("/mysite/some/long/path"));
final Site site = newSite();
when(contentService.findNearestSiteByPath(eq(ContentPath.from("/mysite/some/long/path")))).thenReturn(site);
final ResourceKey errorResource = ResourceKey.from(ApplicationKey.from("myapplication"), "site/error/error.js");
final ErrorHandlerScript errorHandlerScript = (portalError, handleMethod) -> PortalResponse.create().body("Custom message page").status(HttpStatus.NOT_FOUND).postProcess(false).build();
when(this.errorHandlerScriptFactory.errorScript(errorResource)).thenReturn(errorHandlerScript);
final Resource resource = mock(Resource.class);
when(resource.exists()).thenReturn(true);
when(this.resourceService.getResource(errorResource)).thenReturn(resource);
final RuntimeException cause = new RuntimeException("Custom message");
final PortalResponse res = this.renderer.render(this.request, new WebException(HttpStatus.NOT_FOUND, cause));
assertEquals(HttpStatus.NOT_FOUND, res.getStatus());
assertEquals("Custom message page", res.getBody().toString());
assertFalse(postProcessor.isExecuted());
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class MappingHandlerTest method setupContentAndSite.
private void setupContentAndSite(final ControllerMappingDescriptor mapping) {
final Content content = createPage("id", "site/somesite/content", "myapplication:ctype", true);
final Site site = createSite("id", "site", "myapplication:contenttypename");
final ContentPath path = ContentPath.from("site/somesite/content").asAbsolute();
when(this.contentService.getByPath(path)).thenReturn(content);
when(this.contentService.findNearestSiteByPath(eq(path))).thenReturn(site);
when(this.contentService.getById(content.getId())).thenReturn(content);
final ControllerMappingDescriptors mappings = ControllerMappingDescriptors.from(mapping);
final SiteDescriptor siteDescriptor = SiteDescriptor.create().mappingDescriptors(mappings).build();
when(this.siteService.getDescriptor(any(ApplicationKey.class))).thenReturn(siteDescriptor);
}
use of com.enonic.xp.site.Site in project xp by enonic.
the class ControllerMappingsResolverTest method newSite.
private Site newSite() {
final SiteConfig siteConfig = SiteConfig.create().application(getAppKey()).config(new PropertyTree()).build();
final SiteConfig siteConfig2 = SiteConfig.create().application(getAppKey2()).config(new PropertyTree()).build();
final Site.Builder site = Site.create();
site.id(ContentId.from("100123"));
site.siteConfigs(SiteConfigs.from(siteConfig, siteConfig2));
site.name("mysite");
site.parentPath(ContentPath.ROOT);
return site.build();
}
Aggregations