Search in sources :

Example 11 with PortalRequest

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

the class AssetHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    this.resources = new HashMap<>();
    resourceService = Mockito.mock(ResourceService.class);
    when(resourceService.getResource(Mockito.any())).then(this::getResource);
    this.handler = new AssetHandler(resourceService);
    this.handler.activate(mock(PortalConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
    this.nullResource = Mockito.mock(Resource.class);
    when(this.nullResource.exists()).thenReturn(false);
    this.request.setMethod(HttpMethod.GET);
    this.request.setEndpointPath("/_/asset/demo/css/main.css");
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) WebException(com.enonic.xp.web.WebException) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ResourceKey(com.enonic.xp.resource.ResourceKey) MockResource(com.enonic.xp.resource.MockResource) WebResponse(com.enonic.xp.web.WebResponse) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HttpMethod(com.enonic.xp.web.HttpMethod) PortalRequest(com.enonic.xp.portal.PortalRequest) Map(java.util.Map) PortalResponse(com.enonic.xp.portal.PortalResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) MediaType(com.google.common.net.MediaType) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) ResourceService(com.enonic.xp.resource.ResourceService) Mockito.when(org.mockito.Mockito.when) RenderMode(com.enonic.xp.portal.RenderMode) ApplicationKey(com.enonic.xp.app.ApplicationKey) PortalConfig(com.enonic.xp.portal.impl.PortalConfig) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) Resource(com.enonic.xp.resource.Resource) HttpStatus(com.enonic.xp.web.HttpStatus) Mockito.mock(org.mockito.Mockito.mock) PortalConfig(com.enonic.xp.portal.impl.PortalConfig) ResourceService(com.enonic.xp.resource.ResourceService) MockResource(com.enonic.xp.resource.MockResource) Resource(com.enonic.xp.resource.Resource) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 12 with PortalRequest

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

the class ImageHandlerTest method setup.

@BeforeEach
final void setup() {
    this.request = new PortalRequest();
    this.contentService = mock(ContentService.class);
    this.imageService = mock(ImageService.class);
    this.mediaInfoService = mock(MediaInfoService.class);
    this.handler = new ImageHandler();
    this.handler.setContentService(this.contentService);
    this.handler.setImageService(this.imageService);
    this.handler.setMediaInfoService(this.mediaInfoService);
    this.handler.activate(mock(PortalConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
    this.request.setMethod(HttpMethod.GET);
    this.request.setBranch(ContentConstants.BRANCH_MASTER);
    this.request.setBaseUri("/site");
    this.request.setContentPath(ContentPath.from("/path/to/content"));
    this.request.setEndpointPath("/_/image/123456/scale-100-100/image-name.jpg");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) WebException(com.enonic.xp.web.WebException) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Permission(com.enonic.xp.security.acl.Permission) ContentId(com.enonic.xp.content.ContentId) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ImageService(com.enonic.xp.image.ImageService) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) BinaryReference(com.enonic.xp.util.BinaryReference) Media(com.enonic.xp.content.Media) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) ReadImageParams(com.enonic.xp.image.ReadImageParams) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) ContentNotFoundException(com.enonic.xp.content.ContentNotFoundException) PortalConfig(com.enonic.xp.portal.impl.PortalConfig) Test(org.junit.jupiter.api.Test) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RoleKeys(com.enonic.xp.security.RoleKeys) HttpStatus(com.enonic.xp.web.HttpStatus) AccessControlEntry(com.enonic.xp.security.acl.AccessControlEntry) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ContentService(com.enonic.xp.content.ContentService) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) WebResponse(com.enonic.xp.web.WebResponse) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Attachment(com.enonic.xp.attachment.Attachment) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) HttpMethod(com.enonic.xp.web.HttpMethod) MediaInfoService(com.enonic.xp.media.MediaInfoService) PortalRequest(com.enonic.xp.portal.PortalRequest) ImageOrientation(com.enonic.xp.media.ImageOrientation) PortalResponse(com.enonic.xp.portal.PortalResponse) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) PropertyTree(com.enonic.xp.data.PropertyTree) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) MediaType(com.google.common.net.MediaType) ContentPath(com.enonic.xp.content.ContentPath) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) PrincipalKey(com.enonic.xp.security.PrincipalKey) Attachments(com.enonic.xp.attachment.Attachments) PortalConfig(com.enonic.xp.portal.impl.PortalConfig) MediaInfoService(com.enonic.xp.media.MediaInfoService) ContentService(com.enonic.xp.content.ContentService) ImageService(com.enonic.xp.image.ImageService) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with PortalRequest

use of com.enonic.xp.portal.PortalRequest 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 14 with PortalRequest

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

the class IdProviderControllerServiceImplTest method executeIdProviderWithoutApplication.

@Test
public void executeIdProviderWithoutApplication() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myemptyidprovider")).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNull(portalResponse);
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Example 15 with PortalRequest

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

the class IdProviderControllerServiceImplTest method execute.

@Test
public void execute() throws IOException {
    final IdProviderControllerExecutionParams executionParams = IdProviderControllerExecutionParams.create().portalRequest(new PortalRequest()).idProviderKey(IdProviderKey.from("myidprovider")).functionName("myfunction").build();
    final PortalResponse portalResponse = idProviderControllerService.execute(executionParams);
    assertNotNull(portalResponse);
    assertEquals(HttpStatus.OK, portalResponse.getStatus());
    assertEquals("myapplication/myfunction", portalResponse.getBody());
}
Also used : PortalResponse(com.enonic.xp.portal.PortalResponse) IdProviderControllerExecutionParams(com.enonic.xp.portal.idprovider.IdProviderControllerExecutionParams) PortalRequest(com.enonic.xp.portal.PortalRequest) AbstractControllerTest(com.enonic.xp.portal.impl.controller.AbstractControllerTest) Test(org.junit.jupiter.api.Test)

Aggregations

PortalRequest (com.enonic.xp.portal.PortalRequest)103 Test (org.junit.jupiter.api.Test)47 BeforeEach (org.junit.jupiter.api.BeforeEach)35 PortalResponse (com.enonic.xp.portal.PortalResponse)25 Site (com.enonic.xp.site.Site)19 Content (com.enonic.xp.content.Content)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ApplicationKey (com.enonic.xp.app.ApplicationKey)10 ContentPath (com.enonic.xp.content.ContentPath)10 ContentService (com.enonic.xp.content.ContentService)10 ControllerScriptFactory (com.enonic.xp.portal.controller.ControllerScriptFactory)10 ControllerScript (com.enonic.xp.portal.controller.ControllerScript)9 ResourceKey (com.enonic.xp.resource.ResourceKey)9 ResourceService (com.enonic.xp.resource.ResourceService)9 ContentId (com.enonic.xp.content.ContentId)7 Matcher (java.util.regex.Matcher)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)7 Assertions.fail (org.junit.jupiter.api.Assertions.fail)7 Mockito.when (org.mockito.Mockito.when)7