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);
}
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);
}
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());
}
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());
}
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");
}
Aggregations