Search in sources :

Example 11 with PortalResponse

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

the class AttachmentHandlerTest method inline.

@Test
void inline() throws Exception {
    this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
    final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals(MediaType.PNG.withoutParameters(), res.getContentType());
    assertNull(res.getHeaders().get("Content-Disposition"));
    assertSame(this.mediaBytes, res.getBody());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 12 with PortalResponse

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

the class IdProviderControllerServiceImplTest method executeWithoutVirtualHost.

@Test
public void executeWithoutVirtualHost() throws IOException {
    final HttpServletRequest httpServletRequest = createHttpServletRequest();
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().servletRequest(httpServletRequest).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 13 with PortalResponse

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

the class IdProviderControllerServiceImplTest method executeIdProviderWithoutApplication.

@Test
public void executeIdProviderWithoutApplication() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myemptyidprovider")).functionName("myfunction").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 14 with PortalResponse

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

the class IdProviderControllerServiceImplTest method execute.

@Test
public void execute() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myidprovider")).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNotNull(portalResponse);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("myapplication/myfunction", portalResponse.getBody());
}
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 15 with PortalResponse

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

the class IdProviderControllerServiceImplTest method executeWithVirtualHost.

@Test
public void executeWithVirtualHost() throws IOException {
    final HttpServletRequest httpServletRequest = createHttpServletRequest();
    final VirtualHost virtualHost = Mockito.mock(VirtualHost.class);
    Mockito.when(virtualHost.getDefaultIdProviderKey()).thenReturn(IdProviderKey.from("myuserstore"));
    Mockito.when(virtualHost.getTarget()).thenReturn("/");
    Mockito.when(httpServletRequest.getAttribute(VirtualHost.class.getName())).thenReturn(virtualHost);
    VirtualHostHelper.setVirtualHost(httpServletRequest, virtualHost);
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().servletRequest(httpServletRequest).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNotNull(portalResponse);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("myapplication/myfunction", portalResponse.getBody());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PortalResponse(com.enonic.xp.portal.PortalResponse) VirtualHost(com.enonic.xp.web.vhost.VirtualHost) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) 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