use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ExceptionRendererImplTest method setup.
@BeforeEach
void setup() {
this.resourceService = mock(ResourceService.class);
this.contentService = mock(ContentService.class);
this.errorHandlerScriptFactory = mock(ErrorHandlerScriptFactory.class);
this.postProcessor = new MockPostProcessor();
this.renderer = new ExceptionRendererImpl(resourceService, errorHandlerScriptFactory, contentService, null, postProcessor, RunMode.DEV);
this.request = new PortalRequest();
final HttpServletRequest rawRequest = mock(HttpServletRequest.class);
this.request.setRawRequest(rawRequest);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class FilterScriptImplTest method setup.
@BeforeEach
public void setup() throws Exception {
this.portalRequest = new PortalRequest();
this.portalResponse = PortalResponse.create().build();
final BundleContext bundleContext = Mockito.mock(BundleContext.class);
final Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = Mockito.mock(Application.class);
Mockito.when(application.getBundle()).thenReturn(bundle);
Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
Mockito.when(application.isStarted()).thenReturn(true);
Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
this.resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = FilterScriptImplTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, this.resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
this.factory = new FilterScriptFactoryImpl();
this.factory.setScriptService(scriptService);
final HttpServletRequest req = Mockito.mock(HttpServletRequest.class);
ServletRequestHolder.setRequest(req);
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalRequestSerializerTest method serializeMultiParams.
@Test
public void serializeMultiParams() throws Exception {
final PortalRequest sourceRequest = new PortalRequest();
final String jsonRequest = readResource("PortalRequestSerializer_request3.json");
final Object obj = execute("var result = " + jsonRequest + "; result;");
final ScriptValue value = this.factory.newValue(obj);
PortalRequestSerializer reqSerializer = new PortalRequestSerializer(sourceRequest, value);
final PortalRequest portalRequest = reqSerializer.serialize();
assertNotNull(portalRequest);
assertEquals(Map.of("key1", "value1", "key2", 42), portalRequest.getBody());
assertEquals(0, portalRequest.getHeaders().size());
assertEquals(0, portalRequest.getCookies().size());
assertEquals(4, portalRequest.getParams().size());
assertEquals("param-value", portalRequest.getParams().get("param").iterator().next());
final List<String> param2Values = new ArrayList<>(portalRequest.getParams().get("param2"));
assertEquals("param-value2-a", param2Values.get(0));
assertEquals("param-value2-b", param2Values.get(1));
assertEquals("param-value2-c", param2Values.get(2));
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class PortalRequestSerializerTest method serializeComplete.
@Test
public void serializeComplete() throws Exception {
final PortalRequest sourceRequest = new PortalRequest();
final String jsonRequest = readResource("PortalRequestSerializer_request.json");
final Object obj = execute("var result = " + jsonRequest + "; result;");
final ScriptValue value = this.factory.newValue(obj);
PortalRequestSerializer reqSerializer = new PortalRequestSerializer(sourceRequest, value);
final PortalRequest portalRequest = reqSerializer.serialize();
assertNotNull(portalRequest);
assertEquals(HttpMethod.POST, portalRequest.getMethod());
assertEquals("https", portalRequest.getScheme());
assertEquals("myhost", portalRequest.getHost());
assertEquals(1234, portalRequest.getPort());
assertEquals("/some/path", portalRequest.getPath());
assertEquals("https://myhost:1234/some/path/url", portalRequest.getUrl());
assertEquals("127.0.0.42", portalRequest.getRemoteAddress());
assertEquals(RenderMode.EDIT, portalRequest.getMode());
assertEquals(true, portalRequest.isValidTicket());
assertEquals(Branch.from("draft"), portalRequest.getBranch());
assertEquals("application/json", portalRequest.getContentType());
assertEquals("POST BODY", portalRequest.getBody());
assertEquals(2, portalRequest.getHeaders().size());
assertEquals("header-value", portalRequest.getHeaders().get("header"));
assertEquals("header-value2", portalRequest.getHeaders().get("header2"));
assertEquals(2, portalRequest.getCookies().size());
assertEquals("cookie-value", portalRequest.getCookies().get("cookie"));
assertEquals("cookie-value2", portalRequest.getCookies().get("cookie2"));
assertEquals(2, portalRequest.getParams().size());
assertEquals("param-value", portalRequest.getParams().get("param").iterator().next());
assertEquals("param-value2", portalRequest.getParams().get("param2").iterator().next());
}
use of com.enonic.xp.portal.PortalRequest in project xp by enonic.
the class ErrorHandlerTest method setup.
@BeforeEach
public final void setup() throws Exception {
this.request = new PortalRequest();
this.handler = new ErrorHandler();
this.request.setMethod(HttpMethod.GET);
this.request.setEndpointPath("/_/error/401");
}
Aggregations