Search in sources :

Example 36 with PortalRequest

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

the class ContentResolverTest method resolve_in_edit_mode.

@Test
void resolve_in_edit_mode() {
    final Content content = newContent();
    final Site site = newSite();
    final PortalRequest request = new PortalRequest();
    request.setMode(RenderMode.EDIT);
    request.setContentPath(ContentPath.from("/c8da0c10-0002-4b68-b407-87412f3e45c8"));
    when(this.contentService.getById(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"))).thenReturn(content);
    when(this.contentService.getNearestSite(ContentId.from("c8da0c10-0002-4b68-b407-87412f3e45c8"))).thenReturn(site);
    final ContentResolverResult result = new ContentResolver(contentService).resolve(request);
    assertSame(content, result.getContent());
    assertSame(site, result.getNearestSite());
    assertEquals("/landing-page", result.getSiteRelativePath());
}
Also used : Site(com.enonic.xp.site.Site) Content(com.enonic.xp.content.Content) PortalRequest(com.enonic.xp.portal.PortalRequest) Test(org.junit.jupiter.api.Test)

Example 37 with PortalRequest

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

the class EmbedIframeMacroProcessorTest method makeContext.

private MacroContext makeContext(final String body, final RenderMode renderMode) {
    final PortalRequest request = new PortalRequest();
    request.setMode(renderMode);
    return MacroContext.create().name("name").request(request).body(body).build();
}
Also used : PortalRequest(com.enonic.xp.portal.PortalRequest)

Example 38 with PortalRequest

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

the class PortalErrorMapperTest method setup.

@BeforeEach
public void setup() {
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setMethod(HttpMethod.GET);
    portalRequest.setScheme("http");
    portalRequest.setHost("localhost");
    portalRequest.setPort(80);
    portalRequest.setPath("/site/live/master/a/b");
    portalRequest.setRawPath("/site/live/master/a/b");
    portalRequest.setContextPath("/site/live/master/a");
    portalRequest.setUrl("http://localhost/site/live/master/a/b?param1=value1");
    portalRequest.setRemoteAddress("10.0.0.1");
    portalRequest.getParams().put("param1", "value1");
    portalRequest.getParams().put("param2", "value2");
    portalRequest.getParams().put("param3", "value3-A");
    portalRequest.getParams().put("param3", "value3-B");
    portalRequest.getHeaders().put("header1", "value1");
    portalRequest.getHeaders().put("header2", "value2");
    portalRequest.getHeaders().put("header3", "value3");
    portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
    portalRequest.setContent(ContentFixtures.newContent());
    portalRequest.setSite(ContentFixtures.newSite());
    portalRequest.setPageDescriptor(ContentFixtures.newPageDescriptor());
    final NotFoundException exception = new NotFoundException("Not found.") {
    };
    final PortalError.Builder errorBuilder = PortalError.create();
    errorBuilder.status(HttpStatus.NOT_FOUND).message("Message: Not found.").exception(exception).request(portalRequest);
    this.error = errorBuilder.build();
}
Also used : PortalError(com.enonic.xp.portal.impl.error.PortalError) NotFoundException(com.enonic.xp.exception.NotFoundException) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 39 with PortalRequest

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

the class AttachmentHandlerTest method setup.

@BeforeEach
final void setup() throws Exception {
    this.contentService = mock(ContentService.class);
    this.handler = new AttachmentHandler(this.contentService);
    this.handler.activate(mock(PortalConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
    this.request = new PortalRequest();
    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("/_/attachment/inline/123456/logo.png");
    setupMedia();
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) ContentService(com.enonic.xp.content.ContentService) WebException(com.enonic.xp.web.WebException) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContentConstants(com.enonic.xp.content.ContentConstants) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) 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) Permission(com.enonic.xp.security.acl.Permission) ContentId(com.enonic.xp.content.ContentId) HttpMethod(com.enonic.xp.web.HttpMethod) PortalRequest(com.enonic.xp.portal.PortalRequest) 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) BinaryReference(com.enonic.xp.util.BinaryReference) MediaType(com.google.common.net.MediaType) Media(com.enonic.xp.content.Media) BaseHandlerTest(com.enonic.xp.web.handler.BaseHandlerTest) ContentPath(com.enonic.xp.content.ContentPath) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) AccessControlList(com.enonic.xp.security.acl.AccessControlList) StandardCharsets(java.nio.charset.StandardCharsets) PortalConfig(com.enonic.xp.portal.impl.PortalConfig) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) PrincipalKey(com.enonic.xp.security.PrincipalKey) Attachments(com.enonic.xp.attachment.Attachments) 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) PortalConfig(com.enonic.xp.portal.impl.PortalConfig) ContentService(com.enonic.xp.content.ContentService) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 40 with PortalRequest

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

the class ImageUrlBuilderTest method init.

@BeforeEach
public void init() {
    final PortalRequest portalRequest = new PortalRequest();
    portalRequest.setBranch(Branch.from("draft"));
    portalRequest.setApplicationKey(ApplicationKey.from("myapplication"));
    portalRequest.setBaseUri("/site");
    portalRequest.setContentPath(ContentPath.from("context/path"));
    this.imageUrlParams = new ImageUrlParams().portalRequest(portalRequest).scale("testScale");
    urlBuilder = new ImageUrlBuilder();
    urlBuilder.setParams(imageUrlParams);
    final Attachment attachment = Attachment.create().name("attachmentName").mimeType("attachmentMimeType").size(1).build();
    media = Mockito.mock(Media.class);
    final ContentId contentId = ContentId.from("testID");
    Mockito.when(media.getId()).thenReturn(contentId);
    Mockito.when(media.getName()).thenReturn(ContentName.from("testName"));
    Mockito.when(media.getType()).thenReturn(ContentTypeName.imageMedia());
    Mockito.when(media.getMediaAttachment()).thenReturn(attachment);
    final ContentService contentService = Mockito.mock(ContentService.class);
    Mockito.when(contentService.getByPath(Mockito.any())).thenReturn(media);
    Mockito.when(contentService.getById(Mockito.any())).thenReturn(media);
    Mockito.when(contentService.getBinaryKey(contentId, attachment.getBinaryReference())).thenReturn("binaryHash");
    urlBuilder.contentService = contentService;
}
Also used : Media(com.enonic.xp.content.Media) Attachment(com.enonic.xp.attachment.Attachment) ContentId(com.enonic.xp.content.ContentId) ContentService(com.enonic.xp.content.ContentService) PortalRequest(com.enonic.xp.portal.PortalRequest) ImageUrlParams(com.enonic.xp.portal.url.ImageUrlParams) BeforeEach(org.junit.jupiter.api.BeforeEach)

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