use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.
the class ImagePluginTest method testCacheOfScaledAttachment.
@Test
public void testCacheOfScaledAttachment() throws Exception {
XWikiContext xcontext = this.oldCore.getXWikiContext();
XWikiAttachment attachment = Mockito.mock(XWikiAttachment.class);
Mockito.when(attachment.getMimeType(xcontext)).thenReturn("image/png");
InputStream attachmentInputStream = new ByteArrayInputStream(testPngImageContent);
Mockito.when(attachment.getContentInputStream(xcontext)).thenReturn(attachmentInputStream);
Mockito.when(attachment.clone()).thenReturn(attachment);
XWikiAttachmentContent attachmentContent = Mockito.mock(XWikiAttachmentContent.class);
Mockito.when(attachment.getAttachment_content()).thenReturn(attachmentContent);
Mockito.when(attachmentContent.getContentInputStream()).thenReturn(attachmentInputStream);
OutputStream attachmentOutputStream = Mockito.mock(OutputStream.class);
Mockito.when(attachmentContent.getContentOutputStream()).thenReturn(attachmentOutputStream);
CacheManager cacheManager = this.oldCore.getMocker().getInstance(CacheManager.class);
Cache<Object> imageCache = Mockito.mock(Cache.class);
Mockito.when(cacheManager.createNewLocalCache(ArgumentMatchers.any())).thenReturn(imageCache);
XWikiServletRequest request = Mockito.mock(XWikiServletRequest.class);
Mockito.when(request.getParameter("width")).thenReturn("30");
Mockito.when(request.getParameter("height")).thenReturn("30");
xcontext.setRequest(request);
Image image = Mockito.mock(Image.class);
Mockito.when(image.getWidth(null)).thenReturn(400);
Mockito.when(image.getHeight(null)).thenReturn(300);
Mockito.when(imageProcessor.readImage(attachmentInputStream)).thenReturn(image);
RenderedImage renderedImage = Mockito.mock(RenderedImage.class);
Mockito.when(imageProcessor.scaleImage(image, 30, 30)).thenReturn(renderedImage);
XWikiAttachment scaled = plugin.downloadAttachment(attachment, xcontext);
String cacheKey = "0;null;30;30;false;-1.0";
Mockito.when(imageCache.get(cacheKey)).thenReturn(scaled);
// Load again, this time from cache.
Assert.assertSame(scaled, plugin.downloadAttachment(attachment, xcontext));
Mockito.verify(imageProcessor, Mockito.times(1)).writeImage(renderedImage, "image/png", .5F, attachmentOutputStream);
Mockito.verify(imageCache, Mockito.times(1)).set(cacheKey, attachment);
}
use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.
the class PageTest method setUpComponentsForPageTest.
/**
* Set up components before Components declared in {@link org.xwiki.test.annotation.ComponentList} are handled.
*
* @throws Exception in case of errors
*/
@BeforeComponent
public void setUpComponentsForPageTest() throws Exception {
mocker.registerMockComponent(JMXBeanRegistration.class);
mocker.registerMockComponent(Environment.class);
mocker.registerMockComponent(JobProgressManager.class);
mocker.registerMockComponent(RenderingCache.class);
mocker.registerMockComponent(EntityResourceActionLister.class);
CacheManager cacheManager = mocker.registerMockComponent(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(mock(Cache.class));
}
use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.
the class FeedPlugin method initCache.
public void initCache(int iCapacity, XWikiContext context) throws XWikiException {
try {
CacheConfiguration configuration = new CacheConfiguration();
configuration.setConfigurationId("xwiki.plugin.feedcache");
LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
lru.setMaxEntries(iCapacity);
lru.setMaxIdle(this.refreshPeriod);
configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
CacheManager cacheManager = Utils.getComponent(CacheManager.class);
this.feedCache = cacheManager.createNewLocalCache(configuration);
} catch (CacheException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create cache");
}
}
use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.
the class DefaultAuthorizationManagerIntegrationTest method initializeMocks.
@BeforeComponent
public void initializeMocks() throws Exception {
cache = new TestCache<Object>();
final CacheManager cacheManager = componentManager.registerMockComponent(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
xWikiBridge = componentManager.registerMockComponent(XWikiBridge.class);
userBridge = componentManager.registerMockComponent(UserBridge.class);
securityEntryReader = componentManager.registerMockComponent(SecurityEntryReader.class);
securityCacheRulesInvalidator = componentManager.registerMockComponent(SecurityCacheRulesInvalidator.class);
}
use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.
the class DefaultSecurityCacheTest method configure.
@Before
public void configure() throws Exception {
if (cache == null) {
cache = new TestCache<Object>();
final CacheManager cacheManager = securityCacheMocker.getInstance(CacheManager.class);
when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
}
XWikiBridge xwikiBridge = securityReferenceFactoryMocker.getInstance(XWikiBridge.class);
when(xwikiBridge.getMainWikiReference()).thenReturn(new WikiReference("xwiki"));
this.factory = securityReferenceFactoryMocker.getComponentUnderTest();
this.securityCache = securityCacheMocker.getComponentUnderTest();
aMissingParentRef = factory.newEntityReference(new SpaceReference("space", new WikiReference("missing")));
aMissingEntityRef = factory.newEntityReference(new DocumentReference("missingPage", xspaceRef.getOriginalSpaceReference()));
aMissingUserRef = factory.newUserReference(new DocumentReference("missingUser", xXWikiSpace.getOriginalSpaceReference()));
aMissingGroupRef = factory.newGroupReference(new DocumentReference("missingGroup", xXWikiSpace.getOriginalSpaceReference()));
aMissingWikiRef = factory.newEntityReference(new WikiReference("missingWiki"));
}
Aggregations