use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PostProcessorImplTest method testPostProcessingInstructions.
private void testPostProcessingInstructions(final HttpMethod httpMethod) throws Exception {
final String html = readResource("postProcessSource1.html");
final PostProcessorImpl postProcessor = new PostProcessorImpl();
postProcessor.addInstruction(new TestPostProcessInstruction());
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("postProcessResult1.html");
assertEqualsTrimmed(expectedResult, outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ComponentInstructionTest method testInstruction.
@Test
public void testInstruction() throws Exception {
RendererDelegate rendererDelegate = newRendererFactory("<b>part content</b>");
ComponentService componentService = Mockito.mock(ComponentService.class);
ComponentInstruction instruction = new ComponentInstruction();
instruction.setRendererDelegate(rendererDelegate);
instruction.setComponentService(componentService);
PortalRequest portalRequest = new PortalRequest();
Content content = createPage("content-id", "content-name", "myapplication:content-type");
portalRequest.setContent(content);
Site site = createSite("site-id", "site-name", "myapplication:content-type");
portalRequest.setSite(site);
String outputHtml = instruction.evaluate(portalRequest, "COMPONENT myRegion/0").getAsString();
assertEquals("<b>part content</b>", outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ComponentInstructionTest method testInstructionRenderByName.
@Test
public void testInstructionRenderByName() throws Exception {
RendererDelegate rendererFactory = newRendererFactory("<b>part content</b>");
ComponentService componentService = Mockito.mock(ComponentService.class);
Component component = createPartComponent();
doReturn(component).when(componentService).getByKey(isA(DescriptorKey.class));
ComponentInstruction instruction = new ComponentInstruction();
instruction.setRendererDelegate(rendererFactory);
instruction.setComponentService(componentService);
PortalRequest portalRequest = new PortalRequest();
Content content = createPage("content-id", "content-name", "myapplication:content-type");
portalRequest.setContent(content);
Site site = createSite("site-id", "site-name", "myapplication:content-type");
portalRequest.setSite(site);
PageTemplate pageTemplate = createPageTemplate();
portalRequest.setPageTemplate(pageTemplate);
String outputHtml = instruction.evaluate(portalRequest, "COMPONENT module:myPartComponent").getAsString();
assertEquals("<b>part content</b>", outputHtml);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ProcessorChainResolverTest method before.
@BeforeEach
public void before() {
portalRequest = new PortalRequest();
siteService = Mockito.mock(SiteService.class);
resolver = new ProcessorChainResolver();
resolver.setSiteService(siteService);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class AbstractViewFunctionTest method setup.
@BeforeEach
public final void setup() throws Exception {
this.portalRequest = new PortalRequest();
this.portalRequest.setBranch(Branch.from("draft"));
this.portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
this.portalRequest.setBaseUri("/site");
this.portalRequest.setContentPath(ContentPath.from("context/path"));
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
this.portalRequest.setRawRequest(httpServletRequest);
this.service = new ViewFunctionServiceImpl();
setupFunction();
}
Aggregations