Search in sources :

Example 41 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class ExceptionRendererImplTest method render_with_tip.

@Test
void render_with_tip() {
    this.renderer = new ExceptionRendererImpl(resourceService, errorHandlerScriptFactory, contentService, null, postProcessor);
    this.request.getHeaders().put(HttpHeaders.ACCEPT, "text/html,text/*");
    this.request.setBaseUri("/site");
    this.request.setBranch(Branch.from("master"));
    final PortalResponse res = this.renderer.render(this.request, new WebException(HttpStatus.NOT_FOUND, "Custom message"));
    assertEquals(HttpStatus.NOT_FOUND, res.getStatus());
    assertEquals(MediaType.HTML_UTF_8.withoutParameters(), res.getContentType());
    final String body = res.getBody().toString();
    assertThat(body).contains("404 - Not Found");
    assertThat(body).doesNotContain("Custom message");
    assertThat(body).contains("Tip: Did you remember to publish the site?");
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebException(com.enonic.xp.web.WebException) Test(org.junit.jupiter.api.Test)

Example 42 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class MappingHandlerTest method testNoMatch_no_site_based.

@Test
public void testNoMatch_no_site_based() throws Exception {
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setContentPath(ContentPath.from("/site/content"));
    this.request.setBaseUri("/something");
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 43 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class MappingHandlerTest method testNoMatch_endpointPath.

@Test
public void testNoMatch_endpointPath() throws Exception {
    this.request.setEndpointPath("something");
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) Test(org.junit.jupiter.api.Test)

Example 44 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class MappingHandlerTest method executeNothing.

@Test
public void executeNothing() throws Exception {
    final ResourceKey controller = ResourceKey.from("demo:/services/test");
    final ControllerMappingDescriptor mapping = ControllerMappingDescriptor.create().controller(controller).pattern("/nomatch").build();
    setupContentAndSite(mapping);
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setBaseUri("/site");
    this.request.setContentPath(ContentPath.from("/site/somesite/content"));
    this.handler.handle(this.request, response, chain);
    verify(chain).handle(this.request, response);
    verifyNoInteractions(rendererDelegate);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerMappingDescriptor(com.enonic.xp.site.mapping.ControllerMappingDescriptor) WebHandlerChain(com.enonic.xp.web.handler.WebHandlerChain) ResourceKey(com.enonic.xp.resource.ResourceKey) Test(org.junit.jupiter.api.Test)

Example 45 with PortalResponse

use of com.enonic.xp.portal.PortalResponse in project xp by enonic.

the class MacroProcessorScriptTest method testMissingMacro.

@Test
public void testMissingMacro() {
    final PortalResponse response = execute("myapplication:/macro/missing-macro.js");
    assertNull(response);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) Test(org.junit.jupiter.api.Test)

Aggregations

PortalResponse (com.enonic.xp.portal.PortalResponse)104 Test (org.junit.jupiter.api.Test)78 PortalRequest (com.enonic.xp.portal.PortalRequest)21 WebException (com.enonic.xp.web.WebException)14 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)13 PostProcessInstruction (com.enonic.xp.portal.postprocess.PostProcessInstruction)10 WebResponse (com.enonic.xp.web.WebResponse)10 ContentService (com.enonic.xp.content.ContentService)9 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 RenderMode (com.enonic.xp.portal.RenderMode)8 HtmlTag (com.enonic.xp.portal.postprocess.HtmlTag)8 PostProcessInjection (com.enonic.xp.portal.postprocess.PostProcessInjection)8 ByteSource (com.google.common.io.ByteSource)8 InputStream (java.io.InputStream)8 StandardCharsets (java.nio.charset.StandardCharsets)8 Arrays (java.util.Arrays)8 Collections (java.util.Collections)8 List (java.util.List)8