Search in sources :

Example 96 with PortalResponse

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

the class MappingHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ControllerScriptFactory controllerScriptFactory = mock(ControllerScriptFactory.class);
    ControllerScript controllerScript = mock(ControllerScript.class);
    when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(controllerScript);
    final PortalResponse portalResponse = PortalResponse.create().build();
    when(controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    FilterScriptFactory filterScriptFactory = mock(FilterScriptFactory.class);
    FilterScript filterScript = mock(FilterScript.class);
    when(filterScriptFactory.fromScript(Mockito.any())).thenReturn(filterScript);
    when(filterScript.execute(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    this.resourceService = mock(ResourceService.class);
    final Resource resourceNotFound = mock(Resource.class);
    when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = mock(Resource.class);
    when(resource.exists()).thenReturn(true);
    when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resource);
    this.contentService = mock(ContentService.class);
    this.rendererDelegate = mock(RendererDelegate.class);
    this.siteService = mock(SiteService.class);
    this.handler = new MappingHandler(resourceService, controllerScriptFactory, filterScriptFactory, rendererDelegate, new ControllerMappingsResolver(siteService), new ContentResolver(contentService));
    this.request.setMethod(HttpMethod.GET);
}
Also used : FilterScriptFactory(com.enonic.xp.portal.filter.FilterScriptFactory) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) FilterScript(com.enonic.xp.portal.filter.FilterScript) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver) PortalResponse(com.enonic.xp.portal.PortalResponse) SiteService(com.enonic.xp.site.SiteService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 97 with PortalResponse

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

the class MappingHandlerTest method testNoMatch_no_site.

@Test
public void testNoMatch_no_site() throws Exception {
    final WebHandlerChain chain = mock(WebHandlerChain.class);
    final PortalResponse response = PortalResponse.create().build();
    this.request.setBaseUri("/admin/site");
    this.request.setContentPath(ContentPath.from("/site/content"));
    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 98 with PortalResponse

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

the class MacroProcessorScriptTest method testMacro.

@Test
public void testMacro() {
    final PortalResponse response = execute("myapplication:/macro/macro.js");
    assertEquals("Macro context: {\"name\":\"macroName\",\"body\":\"body\",\"params\":{\"firstParam\":\"firstParamValue\",\"secondParam\":\"secondParamValue\"},\"request\":{},\"document\":\"<h1>document</h1>\"}", response.getBody());
    assertEquals(1, response.getContributions(HtmlTag.HEAD_END).size());
    assertEquals(1, response.getContributions(HtmlTag.BODY_END).size());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) Test(org.junit.jupiter.api.Test)

Example 99 with PortalResponse

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

the class AttachmentHandlerTest method download.

@Test
void download() throws Exception {
    this.request.setEndpointPath("/_/attachment/download/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, res.getContentType());
    assertEquals("attachment; filename=\"logo.png\"; filename*=UTF-8''logo.png", 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 100 with PortalResponse

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

the class ServiceHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ControllerScriptFactory controllerScriptFactory = Mockito.mock(ControllerScriptFactory.class);
    this.controllerScript = Mockito.mock(ControllerScript.class);
    Mockito.when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(this.controllerScript);
    final PortalResponse portalResponse = PortalResponse.create().build();
    Mockito.when(this.controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    this.resourceService = Mockito.mock(ResourceService.class);
    final Resource resourceNotFound = Mockito.mock(Resource.class);
    Mockito.when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.exists()).thenReturn(true);
    Mockito.when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resourceNotFound);
    this.serviceDescriptorService = Mockito.mock(ServiceDescriptorService.class);
    final DescriptorKey serviceDescriptorKey = DescriptorKey.from("demo:test");
    final ServiceDescriptor serviceDescriptor = ServiceDescriptor.create().key(serviceDescriptorKey).build();
    Mockito.when(this.serviceDescriptorService.getByKey(serviceDescriptorKey)).thenReturn(serviceDescriptor);
    this.contentService = Mockito.mock(ContentService.class);
    this.handler = new ServiceHandler();
    this.handler.setControllerScriptFactory(controllerScriptFactory);
    this.handler.setContentService(this.contentService);
    this.handler.setResourceService(this.resourceService);
    this.handler.setServiceDescriptorService(this.serviceDescriptorService);
    this.request.setMethod(HttpMethod.GET);
    this.request.setContentPath(ContentPath.from("/site/somepath/content"));
    this.request.setEndpointPath("/_/service/demo/myservice");
    this.request.setRawPath("/site/draft/site/somepath/content/_/service/demo/myservice");
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) ServiceDescriptor(com.enonic.xp.service.ServiceDescriptor) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) DescriptorKey(com.enonic.xp.page.DescriptorKey) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ServiceDescriptorService(com.enonic.xp.service.ServiceDescriptorService) BeforeEach(org.junit.jupiter.api.BeforeEach)

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