Search in sources :

Example 1 with IdProviderControllerService

use of com.enonic.xp.portal.idprovider.IdProviderControllerService in project xp by enonic.

the class IdentityHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ContentService contentService = Mockito.mock(ContentService.class);
    final IdProviderControllerService idProviderControllerService = Mockito.mock(IdProviderControllerService.class);
    final HttpServletRequest rawRequest = Mockito.mock(HttpServletRequest.class);
    Mockito.when(idProviderControllerService.execute(Mockito.any())).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        final IdProviderControllerExecutionParams arg = (IdProviderControllerExecutionParams) args[0];
        if (IdProviderKey.from("myidprovider").equals(arg.getIdProviderKey()) && "get".equals(arg.getFunctionName())) {
            return PortalResponse.create().build();
        }
        return null;
    });
    this.handler = new IdentityHandler();
    this.handler.setContentService(contentService);
    this.handler.setIdProviderControllerService(idProviderControllerService);
    this.request.setMethod(HttpMethod.GET);
    this.request.setEndpointPath("/_/idprovider/myidprovider?param1=value1");
    this.request.setRawPath("/site/draft/_/idprovider/myidprovider?param1=value1");
    this.request.setRawRequest(rawRequest);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IdProviderControllerService(com.enonic.xp.portal.idprovider.IdProviderControllerService) ContentService(com.enonic.xp.content.ContentService) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with IdProviderControllerService

use of com.enonic.xp.portal.idprovider.IdProviderControllerService in project xp by enonic.

the class IdentityHandlerTest method testOptions.

@Test
public void testOptions() throws Exception {
    final IdProviderControllerService idProviderControllerService = Mockito.mock(IdProviderControllerService.class);
    final PortalResponse response = PortalResponse.create().status(HttpStatus.METHOD_NOT_ALLOWED).build();
    Mockito.when(idProviderControllerService.execute(Mockito.any())).thenReturn(response);
    this.handler.setIdProviderControllerService(idProviderControllerService);
    this.request.setMethod(HttpMethod.OPTIONS);
    final WebResponse res = this.handler.handle(this.request, PortalResponse.create().build(), null);
    assertNotNull(res);
    assertEquals(HttpStatus.OK, res.getStatus());
    assertEquals("GET,POST,HEAD,OPTIONS,PUT,DELETE,TRACE", res.getHeaders().get("Allow"));
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) WebResponse(com.enonic.xp.web.WebResponse) IdProviderControllerService(com.enonic.xp.portal.idprovider.IdProviderControllerService) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) Test(org.junit.jupiter.api.Test)

Example 3 with IdProviderControllerService

use of com.enonic.xp.portal.idprovider.IdProviderControllerService in project xp by enonic.

the class IdProviderResponseWrapperTest method setup.

@BeforeEach
public void setup() throws IOException {
    this.idProviderControllerService = Mockito.mock(IdProviderControllerService.class);
    Mockito.when(idProviderControllerService.execute(Mockito.any())).thenReturn(PortalResponse.create().build());
    final HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
    final HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
    this.idProviderResponseWrapper = new IdProviderResponseWrapper(idProviderControllerService, httpServletRequest, httpServletResponse);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) IdProviderControllerService(com.enonic.xp.portal.idprovider.IdProviderControllerService) HttpServletResponse(javax.servlet.http.HttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

IdProviderControllerService (com.enonic.xp.portal.idprovider.IdProviderControllerService)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ContentService (com.enonic.xp.content.ContentService)1 PortalRequest (com.enonic.xp.portal.PortalRequest)1 PortalResponse (com.enonic.xp.portal.PortalResponse)1 IdProviderControllerExecutionParams (com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams)1 WebResponse (com.enonic.xp.web.WebResponse)1 BaseHandlerTest (com.enonic.xp.web.handler.BaseHandlerTest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Test (org.junit.jupiter.api.Test)1