Search in sources :

Example 71 with Site

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();
}
Also used : Site(com.enonic.xp.site.Site) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig)

Example 72 with Site

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"));
}
Also used : Site(com.enonic.xp.site.Site) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ContentService(com.enonic.xp.content.ContentService) WebException(com.enonic.xp.web.WebException) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ErrorHandlerScript(com.enonic.xp.portal.impl.error.ErrorHandlerScript) ResourceKey(com.enonic.xp.resource.ResourceKey) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Branch(com.enonic.xp.branch.Branch) ContentId(com.enonic.xp.content.ContentId) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHeaders(com.google.common.net.HttpHeaders) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PortalRequest(com.enonic.xp.portal.PortalRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) MediaType(com.google.common.net.MediaType) ResourceService(com.enonic.xp.resource.ResourceService) ContentPath(com.enonic.xp.content.ContentPath) SiteConfig(com.enonic.xp.site.SiteConfig) ErrorHandlerScriptFactory(com.enonic.xp.portal.impl.error.ErrorHandlerScriptFactory) Mockito.when(org.mockito.Mockito.when) RenderMode(com.enonic.xp.portal.RenderMode) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test) Site(com.enonic.xp.site.Site) RunMode(com.enonic.xp.server.RunMode) Resource(com.enonic.xp.resource.Resource) SiteConfigs(com.enonic.xp.site.SiteConfigs) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) HttpStatus(com.enonic.xp.web.HttpStatus) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) Mockito.mock(org.mockito.Mockito.mock) PortalResponse(com.enonic.xp.portal.PortalResponse) WebException(com.enonic.xp.web.WebException) Resource(com.enonic.xp.resource.Resource) ErrorHandlerScript(com.enonic.xp.portal.impl.error.ErrorHandlerScript) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 73 with Site

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());
}
Also used : Site(com.enonic.xp.site.Site) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ContentService(com.enonic.xp.content.ContentService) WebException(com.enonic.xp.web.WebException) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ErrorHandlerScript(com.enonic.xp.portal.impl.error.ErrorHandlerScript) ResourceKey(com.enonic.xp.resource.ResourceKey) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Branch(com.enonic.xp.branch.Branch) ContentId(com.enonic.xp.content.ContentId) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpHeaders(com.google.common.net.HttpHeaders) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PortalRequest(com.enonic.xp.portal.PortalRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) PropertyTree(com.enonic.xp.data.PropertyTree) MediaType(com.google.common.net.MediaType) ResourceService(com.enonic.xp.resource.ResourceService) ContentPath(com.enonic.xp.content.ContentPath) SiteConfig(com.enonic.xp.site.SiteConfig) ErrorHandlerScriptFactory(com.enonic.xp.portal.impl.error.ErrorHandlerScriptFactory) Mockito.when(org.mockito.Mockito.when) RenderMode(com.enonic.xp.portal.RenderMode) ApplicationKey(com.enonic.xp.app.ApplicationKey) Test(org.junit.jupiter.api.Test) Site(com.enonic.xp.site.Site) RunMode(com.enonic.xp.server.RunMode) Resource(com.enonic.xp.resource.Resource) SiteConfigs(com.enonic.xp.site.SiteConfigs) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) HttpStatus(com.enonic.xp.web.HttpStatus) AdditionalMatchers.not(org.mockito.AdditionalMatchers.not) Mockito.mock(org.mockito.Mockito.mock) PortalResponse(com.enonic.xp.portal.PortalResponse) WebException(com.enonic.xp.web.WebException) Resource(com.enonic.xp.resource.Resource) ErrorHandlerScript(com.enonic.xp.portal.impl.error.ErrorHandlerScript) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 74 with Site

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);
}
Also used : Site(com.enonic.xp.site.Site) SiteDescriptor(com.enonic.xp.site.SiteDescriptor) ApplicationKey(com.enonic.xp.app.ApplicationKey) Content(com.enonic.xp.content.Content) ContentPath(com.enonic.xp.content.ContentPath) ControllerMappingDescriptors(com.enonic.xp.site.mapping.ControllerMappingDescriptors)

Example 75 with Site

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();
}
Also used : Site(com.enonic.xp.site.Site) PropertyTree(com.enonic.xp.data.PropertyTree) SiteConfig(com.enonic.xp.site.SiteConfig)

Aggregations

Site (com.enonic.xp.site.Site)78 Test (org.junit.jupiter.api.Test)51 Content (com.enonic.xp.content.Content)41 PortalRequest (com.enonic.xp.portal.PortalRequest)17 PropertyTree (com.enonic.xp.data.PropertyTree)14 Page (com.enonic.xp.page.Page)12 ContentId (com.enonic.xp.content.ContentId)10 ContentPath (com.enonic.xp.content.ContentPath)10 SiteConfig (com.enonic.xp.site.SiteConfig)10 WebException (com.enonic.xp.web.WebException)10 ApplicationKey (com.enonic.xp.app.ApplicationKey)9 PageTemplate (com.enonic.xp.page.PageTemplate)8 PortalResponse (com.enonic.xp.portal.PortalResponse)7 ControllerMappingDescriptor (com.enonic.xp.site.mapping.ControllerMappingDescriptor)7 SiteDescriptor (com.enonic.xp.site.SiteDescriptor)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 DescriptorKey (com.enonic.xp.page.DescriptorKey)5 SiteConfigs (com.enonic.xp.site.SiteConfigs)5 Branch (com.enonic.xp.branch.Branch)4 ContentService (com.enonic.xp.content.ContentService)4