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());
}
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();
}
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();
}
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();
}
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;
}
Aggregations