use of com.enonic.xp.resource.ResourceService 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");
}
use of com.enonic.xp.resource.ResourceService in project xp by enonic.
the class IdProviderControllerServiceImplTest method setupPortalScriptService.
private PortalScriptService setupPortalScriptService() {
final BundleContext bundleContext = Mockito.mock(BundleContext.class);
final Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = Mockito.mock(Application.class);
Mockito.when(application.getBundle()).thenReturn(bundle);
Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
Mockito.when(application.isStarted()).thenReturn(true);
Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("defaultapplication"))).thenReturn(application);
Mockito.when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
ResourceService resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = AbstractControllerTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
return scriptService;
}
use of com.enonic.xp.resource.ResourceService in project xp by enonic.
the class AbstractScriptTest method createScriptRuntimeFactory.
private ScriptRuntimeFactory createScriptRuntimeFactory() {
final BundleContext bundleContext = Mockito.mock(BundleContext.class);
final Bundle bundle = Mockito.mock(Bundle.class);
Mockito.when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = Mockito.mock(Application.class);
Mockito.when(application.getBundle()).thenReturn(bundle);
Mockito.when(application.getKey()).thenReturn(APPLICATION_KEY);
Mockito.when(application.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
Mockito.when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
Mockito.when(application.isStarted()).thenReturn(true);
Mockito.when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
final ApplicationService applicationService = Mockito.mock(ApplicationService.class);
Mockito.when(applicationService.getInstalledApplication(APPLICATION_KEY)).thenReturn(application);
final ResourceService resourceService = Mockito.mock(ResourceService.class);
Mockito.when(resourceService.getResource(Mockito.any())).thenAnswer(invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = AbstractScriptTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
});
final ScriptAsyncService scriptAsyncService = Mockito.mock(ScriptAsyncService.class);
return new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
}
use of com.enonic.xp.resource.ResourceService in project xp by enonic.
the class NamedTaskFactoryImplTest method setupPortalScriptService.
private PortalScriptService setupPortalScriptService() {
final BundleContext bundleContext = mock(BundleContext.class);
final Bundle bundle = mock(Bundle.class);
when(bundle.getBundleContext()).thenReturn(bundleContext);
final Application application = mock(Application.class);
when(application.getBundle()).thenReturn(bundle);
when(application.getClassLoader()).thenReturn(getClass().getClassLoader());
when(application.isStarted()).thenReturn(true);
when(application.getConfig()).thenReturn(ConfigBuilder.create().build());
final ApplicationService applicationService = mock(ApplicationService.class);
when(applicationService.getInstalledApplication(ApplicationKey.from("myapplication"))).thenReturn(application);
ResourceService resourceService = mock(ResourceService.class);
final Answer<Object> getResource = invocation -> {
final ResourceKey resourceKey = (ResourceKey) invocation.getArguments()[0];
final URL resourceUrl = NamedTaskFactoryImplTest.class.getResource("/" + resourceKey.getApplicationKey() + resourceKey.getPath());
return new UrlResource(resourceKey, resourceUrl);
};
when(resourceService.getResource(any())).thenAnswer(getResource);
final ScriptAsyncService scriptAsyncService = mock(ScriptAsyncService.class);
final ScriptRuntimeFactoryImpl runtimeFactory = new ScriptRuntimeFactoryImpl(applicationService, resourceService, scriptAsyncService);
final PortalScriptServiceImpl scriptService = new PortalScriptServiceImpl(runtimeFactory);
scriptService.initialize();
return scriptService;
}
use of com.enonic.xp.resource.ResourceService in project xp by enonic.
the class AbstractContentServiceTest method setUpAbstractContentServiceTest.
@BeforeEach
public void setUpAbstractContentServiceTest() {
executorService = Executors.newSingleThreadExecutor();
deleteAllIndices();
ContextAccessor.INSTANCE.set(ctxDefault());
final MemoryBlobStore blobStore = new MemoryBlobStore();
binaryService = new BinaryServiceImpl();
binaryService.setBlobStore(blobStore);
final StorageDaoImpl storageDao = new StorageDaoImpl();
storageDao.setClient(client);
final EventPublisherImpl eventPublisher = new EventPublisherImpl(executorService);
SearchDaoImpl searchDao = new SearchDaoImpl();
searchDao.setClient(client);
BranchServiceImpl branchService = new BranchServiceImpl();
branchService.setStorageDao(storageDao);
branchService.setSearchDao(searchDao);
VersionServiceImpl versionService = new VersionServiceImpl();
versionService.setStorageDao(storageDao);
CommitServiceImpl commitService = new CommitServiceImpl();
commitService.setStorageDao(storageDao);
IndexServiceInternalImpl indexServiceInternal = new IndexServiceInternalImpl();
indexServiceInternal.setClient(client);
indexService = new IndexServiceImpl();
indexService.setIndexServiceInternal(indexServiceInternal);
NodeVersionServiceImpl nodeDao = new NodeVersionServiceImpl();
nodeDao.setBlobStore(blobStore);
IndexDataServiceImpl indexedDataService = new IndexDataServiceImpl();
indexedDataService.setStorageDao(storageDao);
NodeStorageServiceImpl storageService = new NodeStorageServiceImpl();
storageService.setBranchService(branchService);
storageService.setVersionService(versionService);
storageService.setCommitService(commitService);
storageService.setNodeVersionService(nodeDao);
storageService.setIndexDataService(indexedDataService);
NodeSearchServiceImpl searchService = new NodeSearchServiceImpl();
searchService.setSearchDao(searchDao);
final NodeRepositoryServiceImpl nodeRepositoryService = new NodeRepositoryServiceImpl();
nodeRepositoryService.setIndexServiceInternal(indexServiceInternal);
final IndexServiceInternalImpl elasticsearchIndexService = new IndexServiceInternalImpl();
elasticsearchIndexService.setClient(client);
final RepositoryEntryServiceImpl repositoryEntryService = new RepositoryEntryServiceImpl();
repositoryEntryService.setIndexServiceInternal(elasticsearchIndexService);
repositoryEntryService.setNodeStorageService(storageService);
repositoryEntryService.setNodeSearchService(searchService);
repositoryEntryService.setEventPublisher(eventPublisher);
repositoryEntryService.setBinaryService(binaryService);
repositoryService = new RepositoryServiceImpl(repositoryEntryService, elasticsearchIndexService, nodeRepositoryService, storageService, searchService);
repositoryService.initialize();
nodeService = new NodeServiceImpl();
nodeService.setIndexServiceInternal(indexServiceInternal);
nodeService.setNodeStorageService(storageService);
nodeService.setNodeSearchService(searchService);
nodeService.setEventPublisher(eventPublisher);
nodeService.setBinaryService(binaryService);
nodeService.setRepositoryService(repositoryService);
nodeService.initialize();
mixinService = Mockito.mock(MixinService.class);
Mockito.when(mixinService.inlineFormItems(Mockito.isA(Form.class))).then(AdditionalAnswers.returnsFirstArg());
xDataService = Mockito.mock(XDataService.class);
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 = Mockito.mock(BinaryExtractor.class);
Mockito.when(extractor.extract(Mockito.isA(ByteSource.class))).thenReturn(extractedData);
mediaInfoService = new MediaInfoServiceImpl();
mediaInfoService.setBinaryExtractor(extractor);
final ResourceService resourceService = Mockito.mock(ResourceService.class);
final SiteServiceImpl siteService = new SiteServiceImpl();
siteService.setResourceService(resourceService);
siteService.setMixinService(mixinService);
contentTypeService = new ContentTypeServiceImpl(null, null, mixinService);
PageDescriptorService pageDescriptorService = Mockito.mock(PageDescriptorService.class);
PartDescriptorService partDescriptorService = Mockito.mock(PartDescriptorService.class);
LayoutDescriptorService layoutDescriptorService = Mockito.mock(LayoutDescriptorService.class);
auditLogService = Mockito.mock(AuditLogService.class);
final ContentConfig contentConfig = Mockito.mock(ContentConfig.class);
Mockito.when(contentConfig.auditlog_enabled()).thenReturn(Boolean.TRUE);
final ContentAuditLogSupportImpl contentAuditLogSupport = new ContentAuditLogSupportImpl(contentConfig, new ContentAuditLogExecutorImpl(), auditLogService);
final SecurityServiceImpl securityService = new SecurityServiceImpl(nodeService, indexService);
securityService.initialize();
final ProjectPermissionsContextManagerImpl projectAccessContextManager = new ProjectPermissionsContextManagerImpl();
final ProjectServiceImpl projectService = new ProjectServiceImpl(repositoryService, indexService, nodeService, securityService, projectAccessContextManager, eventPublisher);
projectService.initialize();
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.addContentValidator(new ContentNameValidator());
contentService.addContentValidator(new SiteConfigsValidator(siteService));
contentService.addContentValidator(new OccurrenceValidator());
contentService.addContentValidator(new ExtraDataValidator(xDataService));
contentService.initialize(mock(ContentConfig.class, invocation -> invocation.getMethod().getDefaultValue()));
}
Aggregations