Search in sources :

Example 6 with ResourceService

use of com.enonic.xp.resource.ResourceService in project xp by enonic.

the class AbstractContentSynchronizerTest method setUpContentService.

private void setUpContentService() {
    final Map<String, List<String>> metadata = new HashMap<>();
    metadata.put(HttpHeaders.CONTENT_TYPE, List.of("image/jpg"));
    final ExtractedData extractedData = ExtractedData.create().metadata(metadata).build();
    final BinaryExtractor extractor = mock(BinaryExtractor.class);
    when(extractor.extract(isA(ByteSource.class))).thenReturn(extractedData);
    mediaInfoService = new MediaInfoServiceImpl();
    mediaInfoService.setBinaryExtractor(extractor);
    XDataService xDataService = mock(XDataService.class);
    MixinService mixinService = mock(MixinService.class);
    when(mixinService.inlineFormItems(isA(Form.class))).then(AdditionalAnswers.returnsFirstArg());
    pageDescriptorService = mock(PageDescriptorService.class);
    partDescriptorService = mock(PartDescriptorService.class);
    layoutDescriptorService = mock(LayoutDescriptorService.class);
    contentTypeService = new ContentTypeServiceImpl(null, null, mixinService);
    final ResourceService resourceService = mock(ResourceService.class);
    final SiteServiceImpl siteService = new SiteServiceImpl();
    siteService.setResourceService(resourceService);
    siteService.setMixinService(mixinService);
    final AuditLogService auditLogService = mock(AuditLogService.class);
    final ContentConfig contentConfig = mock(ContentConfig.class);
    final ContentAuditLogSupportImpl contentAuditLogSupport = new ContentAuditLogSupportImpl(contentConfig, new ContentAuditLogExecutorImpl(), auditLogService);
    contentService = new ContentServiceImpl(nodeService, pageDescriptorService, partDescriptorService, layoutDescriptorService);
    contentService.setEventPublisher(eventPublisher);
    contentService.setMediaInfoService(mediaInfoService);
    contentService.setSiteService(siteService);
    contentService.setContentTypeService(contentTypeService);
    contentService.setxDataService(xDataService);
    contentService.setFormDefaultValuesProcessor((form, data) -> {
    });
    contentService.setContentAuditLogSupport(contentAuditLogSupport);
    contentService.initialize(mock(ContentConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
}
Also used : PartDescriptorService(com.enonic.xp.region.PartDescriptorService) CONTENT_ROOT_PATH_ATTRIBUTE(com.enonic.xp.content.ContentConstants.CONTENT_ROOT_PATH_ATTRIBUTE) IdProviderKey(com.enonic.xp.security.IdProviderKey) TaskServiceImpl(com.enonic.xp.impl.task.TaskServiceImpl) SecurityAuditLogSupportImpl(com.enonic.xp.core.impl.security.SecurityAuditLogSupportImpl) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) HttpHeaders(com.google.common.net.HttpHeaders) ContextAccessor(com.enonic.xp.context.ContextAccessor) Map(java.util.Map) ContextBuilder(com.enonic.xp.context.ContextBuilder) Bundle(org.osgi.framework.Bundle) SystemConstants(com.enonic.xp.security.SystemConstants) EnumSet(java.util.EnumSet) ProjectPermissionsContextManagerImpl(com.enonic.xp.core.impl.project.ProjectPermissionsContextManagerImpl) Media(com.enonic.xp.content.Media) User(com.enonic.xp.security.User) ContentServiceImpl(com.enonic.xp.core.impl.content.ContentServiceImpl) TaskManagerCleanupScheduler(com.enonic.xp.impl.task.TaskManagerCleanupScheduler) Project(com.enonic.xp.project.Project) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) AdditionalAnswers(org.mockito.AdditionalAnswers) BinaryExtractor(com.enonic.xp.extractor.BinaryExtractor) CreateProjectParams(com.enonic.xp.project.CreateProjectParams) List(java.util.List) AbstractNodeTest(com.enonic.xp.repo.impl.node.AbstractNodeTest) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ByteStreams(com.google.common.io.ByteStreams) RoleKeys(com.enonic.xp.security.RoleKeys) Context(com.enonic.xp.context.Context) ProjectServiceImpl(com.enonic.xp.core.impl.project.ProjectServiceImpl) MixinService(com.enonic.xp.schema.mixin.MixinService) ContentAuditLogExecutorImpl(com.enonic.xp.core.impl.content.ContentAuditLogExecutorImpl) ContentAuditLogSupportImpl(com.enonic.xp.core.impl.content.ContentAuditLogSupportImpl) SiteServiceImpl(com.enonic.xp.core.impl.site.SiteServiceImpl) Mockito.mock(org.mockito.Mockito.mock) CreateContentParams(com.enonic.xp.content.CreateContentParams) SecurityServiceImpl(com.enonic.xp.core.impl.security.SecurityServiceImpl) ContentConstants(com.enonic.xp.content.ContentConstants) RecurringJob(com.enonic.xp.core.internal.concurrent.RecurringJob) HashMap(java.util.HashMap) ContentTypeName(com.enonic.xp.schema.content.ContentTypeName) MediaInfoServiceImpl(com.enonic.xp.core.impl.media.MediaInfoServiceImpl) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) ContentTypeServiceImpl(com.enonic.xp.core.impl.schema.content.ContentTypeServiceImpl) ProjectName(com.enonic.xp.project.ProjectName) AuditLogService(com.enonic.xp.audit.AuditLogService) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ByteSource(com.google.common.io.ByteSource) XDataService(com.enonic.xp.schema.xdata.XDataService) OsgiSupportMock(com.enonic.xp.core.internal.osgi.OsgiSupportMock) PropertyTree(com.enonic.xp.data.PropertyTree) ArgumentMatchers.isA(org.mockito.ArgumentMatchers.isA) PartDescriptorService(com.enonic.xp.region.PartDescriptorService) ResourceService(com.enonic.xp.resource.ResourceService) ContentPath(com.enonic.xp.content.ContentPath) ContentInheritType(com.enonic.xp.content.ContentInheritType) NodePath(com.enonic.xp.node.NodePath) Content(com.enonic.xp.content.Content) IOException(java.io.IOException) SecurityConfig(com.enonic.xp.core.impl.security.SecurityConfig) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) LocalTaskManagerImpl(com.enonic.xp.impl.task.LocalTaskManagerImpl) Mockito.when(org.mockito.Mockito.when) Form(com.enonic.xp.form.Form) ExtractedData(com.enonic.xp.extractor.ExtractedData) PrincipalKey(com.enonic.xp.security.PrincipalKey) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) CreateMediaParams(com.enonic.xp.content.CreateMediaParams) NamedTaskFactory(com.enonic.xp.impl.task.script.NamedTaskFactory) InputStream(java.io.InputStream) PageDescriptorService(com.enonic.xp.page.PageDescriptorService) AuditLogService(com.enonic.xp.audit.AuditLogService) MediaInfoServiceImpl(com.enonic.xp.core.impl.media.MediaInfoServiceImpl) ContentAuditLogExecutorImpl(com.enonic.xp.core.impl.content.ContentAuditLogExecutorImpl) HashMap(java.util.HashMap) Form(com.enonic.xp.form.Form) ContentTypeServiceImpl(com.enonic.xp.core.impl.schema.content.ContentTypeServiceImpl) XDataService(com.enonic.xp.schema.xdata.XDataService) ResourceService(com.enonic.xp.resource.ResourceService) SiteServiceImpl(com.enonic.xp.core.impl.site.SiteServiceImpl) MixinService(com.enonic.xp.schema.mixin.MixinService) LayoutDescriptorService(com.enonic.xp.region.LayoutDescriptorService) ContentConfig(com.enonic.xp.core.impl.content.ContentConfig) BinaryExtractor(com.enonic.xp.extractor.BinaryExtractor) ExtractedData(com.enonic.xp.extractor.ExtractedData) ContentAuditLogSupportImpl(com.enonic.xp.core.impl.content.ContentAuditLogSupportImpl) ContentServiceImpl(com.enonic.xp.core.impl.content.ContentServiceImpl) ByteSource(com.google.common.io.ByteSource) List(java.util.List)

Example 7 with ResourceService

use of com.enonic.xp.resource.ResourceService in project xp by enonic.

the class IOHandlerBean method getResource.

public Resource getResource(final Object key) {
    final ResourceKey resourceKey = toResourceKey(key);
    final ResourceService service = this.context.getService(ResourceService.class).get();
    return service.getResource(resourceKey);
}
Also used : ResourceService(com.enonic.xp.resource.ResourceService) ResourceKey(com.enonic.xp.resource.ResourceKey)

Example 8 with ResourceService

use of com.enonic.xp.resource.ResourceService 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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ResourceService(com.enonic.xp.resource.ResourceService) ContentService(com.enonic.xp.content.ContentService) ErrorHandlerScriptFactory(com.enonic.xp.portal.impl.error.ErrorHandlerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with ResourceService

use of com.enonic.xp.resource.ResourceService in project xp by enonic.

the class MappingHandlerTest method setup.

@BeforeEach
public final void setup() throws Exception {
    this.request = new PortalRequest();
    final ControllerScriptFactory controllerScriptFactory = mock(ControllerScriptFactory.class);
    ControllerScript controllerScript = mock(ControllerScript.class);
    when(controllerScriptFactory.fromDir(Mockito.any())).thenReturn(controllerScript);
    final PortalResponse portalResponse = PortalResponse.create().build();
    when(controllerScript.execute(Mockito.any())).thenReturn(portalResponse);
    FilterScriptFactory filterScriptFactory = mock(FilterScriptFactory.class);
    FilterScript filterScript = mock(FilterScript.class);
    when(filterScriptFactory.fromScript(Mockito.any())).thenReturn(filterScript);
    when(filterScript.execute(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(portalResponse);
    this.resourceService = mock(ResourceService.class);
    final Resource resourceNotFound = mock(Resource.class);
    when(resourceNotFound.exists()).thenReturn(false);
    final Resource resource = mock(Resource.class);
    when(resource.exists()).thenReturn(true);
    when(this.resourceService.getResource(ResourceKey.from("demo:/services/test"))).thenReturn(resource);
    this.contentService = mock(ContentService.class);
    this.rendererDelegate = mock(RendererDelegate.class);
    this.siteService = mock(SiteService.class);
    this.handler = new MappingHandler(resourceService, controllerScriptFactory, filterScriptFactory, rendererDelegate, new ControllerMappingsResolver(siteService), new ContentResolver(contentService));
    this.request.setMethod(HttpMethod.GET);
}
Also used : FilterScriptFactory(com.enonic.xp.portal.filter.FilterScriptFactory) ControllerScript(com.enonic.xp.portal.controller.ControllerScript) FilterScript(com.enonic.xp.portal.filter.FilterScript) ResourceService(com.enonic.xp.resource.ResourceService) Resource(com.enonic.xp.resource.Resource) ContentService(com.enonic.xp.content.ContentService) ControllerScriptFactory(com.enonic.xp.portal.controller.ControllerScriptFactory) PortalRequest(com.enonic.xp.portal.PortalRequest) ContentResolver(com.enonic.xp.portal.impl.ContentResolver) PortalResponse(com.enonic.xp.portal.PortalResponse) SiteService(com.enonic.xp.site.SiteService) RendererDelegate(com.enonic.xp.portal.impl.rendering.RendererDelegate) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ResourceService (com.enonic.xp.resource.ResourceService)9 BeforeEach (org.junit.jupiter.api.BeforeEach)5 ResourceKey (com.enonic.xp.resource.ResourceKey)4 Application (com.enonic.xp.app.Application)3 ApplicationService (com.enonic.xp.app.ApplicationService)3 PropertyTree (com.enonic.xp.data.PropertyTree)3 PortalRequest (com.enonic.xp.portal.PortalRequest)3 UrlResource (com.enonic.xp.resource.UrlResource)3 ScriptAsyncService (com.enonic.xp.script.impl.async.ScriptAsyncService)3 ScriptRuntimeFactoryImpl (com.enonic.xp.script.impl.standard.ScriptRuntimeFactoryImpl)3 URL (java.net.URL)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 ApplicationKey (com.enonic.xp.app.ApplicationKey)2 AuditLogService (com.enonic.xp.audit.AuditLogService)2 Content (com.enonic.xp.content.Content)2 ContentConstants (com.enonic.xp.content.ContentConstants)2 ContentPath (com.enonic.xp.content.ContentPath)2 ContentService (com.enonic.xp.content.ContentService)2 CreateContentParams (com.enonic.xp.content.CreateContentParams)2