Search in sources :

Example 71 with PortalResponse

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

the class ComponentHandlerTest method testOptions.

@Test
public void testOptions() throws Exception {
    setupSite();
    setupContent();
    setupTemplates();
    final PortalResponse portalResponse = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
    setRendererResult(portalResponse);
    Mockito.when(this.postProcessor.processResponseInstructions(Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    this.request.setMethod(HttpMethod.OPTIONS);
    this.request.setEndpointPath("/_/component/main-region/0");
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals("GET,POST,HEAD,OPTIONS,PUT,DELETE,TRACE", res.getHeaders().get("Allow"));
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) Test(org.junit.jupiter.api.Test)

Example 72 with PortalResponse

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

the class IdProviderControllerServiceImplTest method executeMissingIdProvider.

@Test
public void executeMissingIdProvider() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("missingidprovider")).functionName("missingfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 73 with PortalResponse

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

the class IdProviderControllerServiceImplTest method executeMissingFunction.

@Test
public void executeMissingFunction() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myemptyidprovider")).functionName("missingfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 74 with PortalResponse

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

the class PostProcessorImplTest method testPostProcessingInjections.

private void testPostProcessingInjections(final HttpMethod httpMethod) throws Exception {
    final String html = readResource("postProcessSource2.html");
    final PostProcessorImpl postProcessor = new PostProcessorImpl();
    postProcessor.addInjection(new TestPostProcessInjection());
    final PortalResponse.Builder portalResponseBuilder = PortalResponse.create().contentType(MediaType.HTML_UTF_8).body(html);
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(httpMethod);
    final PortalResponse portalResponse = postProcessor.processResponse(portalRequest, portalResponseBuilder.build());
    final String outputHtml = portalResponse.getBody().toString();
    final String expectedResult = readResource("postProcessResult2.html");
    assertEqualsTrimmed(expectedResult, outputHtml);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 75 with PortalResponse

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

the class PostProcessorImplTest method processResponse_skip_non_html.

@Test
public void processResponse_skip_non_html() throws Exception {
    final PostProcessorImpl postProcessor = new PostProcessorImpl();
    final PortalResponse portalResponse = PortalResponse.create().contentType(MediaType.JAVASCRIPT_UTF_8).body("").build();
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(HttpMethod.GET);
    final PortalResponse result = postProcessor.processResponse(portalRequest, portalResponse);
    assertSame(portalResponse, result);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) PortalRequest(com.enonic.xp.portal.PortalRequest) 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