Search in sources :

Example 1 with CacheManager

use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.

the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenNoSendMailConfigClassXObject.

@Test
public void getPropertyWhenNoSendMailConfigClassXObject() throws Exception {
    Cache<Object> cache = mock(Cache.class);
    CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
    when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
    LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
    XWikiDocument document = mock(XWikiDocument.class);
    when(document.getXObject(classReference)).thenReturn(null);
    DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
    XWiki xwiki = mock(XWiki.class);
    when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
    XWikiContext xcontext = mock(XWikiContext.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(xcontext);
    assertEquals("defaultValue", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) CacheManager(org.xwiki.cache.CacheManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Example 2 with CacheManager

use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.

the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenSendMailConfigClassXObjectExists.

@Test
public void getPropertyWhenSendMailConfigClassXObjectExists() throws Exception {
    ConverterManager converterManager = this.mocker.getInstance(ConverterManager.class);
    when(converterManager.convert(String.class, "value")).thenReturn("value");
    Cache<Object> cache = mock(Cache.class);
    CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
    when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
    LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
    BaseProperty property = mock(BaseProperty.class);
    when(property.toText()).thenReturn("value");
    BaseObject object = mock(BaseObject.class);
    when(object.getField("key")).thenReturn(property);
    XWikiDocument document = mock(XWikiDocument.class);
    when(document.getXObject(classReference)).thenReturn(object);
    DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
    XWiki xwiki = mock(XWiki.class);
    when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
    XWikiContext xcontext = mock(XWikiContext.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(xcontext);
    assertEquals("value", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) ConverterManager(org.xwiki.properties.ConverterManager) CacheManager(org.xwiki.cache.CacheManager) BaseObject(com.xpn.xwiki.objects.BaseObject) BaseProperty(com.xpn.xwiki.objects.BaseProperty) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Example 3 with CacheManager

use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCacheTest method setUp.

@Before
public void setUp() throws Exception {
    cacheManager = mocker.getInstance(CacheManager.class);
    cache = mock(Cache.class);
    CacheFactory cacheFactory = mock(CacheFactory.class);
    when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
    CacheConfiguration configuration = new CacheConfiguration("lesscss.skinfiles.cache");
    when(cacheFactory.<String>newCache(eq(configuration))).thenReturn(cache);
    cacheKeyFactory = mocker.getInstance(CacheKeyFactory.class);
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("lessResource", null, null);
    when(cacheKeyFactory.getCacheKey(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("12_lessResource_4_skin_10_colorTheme");
}
Also used : NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) CacheManager(org.xwiki.cache.CacheManager) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) CacheFactory(org.xwiki.cache.CacheFactory) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Cache(org.xwiki.cache.Cache) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Before(org.junit.Before)

Example 4 with CacheManager

use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.

the class DefaultOfficeResourceViewerTest method configure.

/**
 * Test fixture.
 *
 * @throws Exception in case of an exception raised during the fixture preparation
 */
@Before
public void configure() throws Exception {
    final CacheManager cacheManager = mocker.getInstance(CacheManager.class);
    attachmentCache = mock(Cache.class, "attachment");
    externalCache = mock(Cache.class, "external");
    when(cacheManager.<OfficeDocumentView>createNewCache(notNull(CacheConfiguration.class))).thenReturn(attachmentCache, externalCache);
    EntityReferenceSerializer<String> entityReferenceSerializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
    when(entityReferenceSerializer.serialize(ATTACHMENT_REFERENCE)).thenReturn(STRING_ATTACHMENT_REFERENCE);
    when(entityReferenceSerializer.serialize(ATTACHMENT_REFERENCE.getDocumentReference())).thenReturn(STRING_DOCUMENT_REFERENCE);
    AttachmentReferenceResolver<String> attachmentReferenceResolver = mocker.getInstance(AttachmentReferenceResolver.TYPE_STRING, "current");
    when(attachmentReferenceResolver.resolve(STRING_ATTACHMENT_REFERENCE)).thenReturn(ATTACHMENT_REFERENCE);
    this.resourceReferenceSerializer = mocker.getInstance(ResourceReferenceTypeSerializer.class);
    when(this.resourceReferenceSerializer.serialize(ATTACHMENT_RESOURCE_REFERENCE)).thenReturn(STRING_ATTACHMENT_RESOURCE_REFERENCE);
    ConverterManager converterManager = mocker.getInstance(ConverterManager.class);
    when(converterManager.convert(boolean.class, null)).thenReturn(false);
    when(converterManager.convert(DocumentReference.class, ATTACHMENT_REFERENCE.getDocumentReference())).thenReturn(ATTACHMENT_REFERENCE.getDocumentReference());
    documentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
    officeDocumentBuilder = mocker.getInstance(XDOMOfficeDocumentBuilder.class);
    OfficeServer officeServer = mocker.getInstance(OfficeServer.class);
    OfficeConverter officeConverter = mock(OfficeConverter.class);
    when(officeServer.getConverter()).thenReturn(officeConverter);
    when(officeConverter.getFormatRegistry()).thenReturn(new DefaultDocumentFormatRegistry());
}
Also used : DefaultDocumentFormatRegistry(org.artofsolving.jodconverter.document.DefaultDocumentFormatRegistry) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) OfficeServer(org.xwiki.officeimporter.server.OfficeServer) OfficeConverter(org.xwiki.officeimporter.converter.OfficeConverter) ConverterManager(org.xwiki.properties.ConverterManager) ResourceReferenceTypeSerializer(org.xwiki.rendering.renderer.reference.ResourceReferenceTypeSerializer) CacheManager(org.xwiki.cache.CacheManager) XDOMOfficeDocumentBuilder(org.xwiki.officeimporter.builder.XDOMOfficeDocumentBuilder) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Cache(org.xwiki.cache.Cache) Before(org.junit.Before)

Example 5 with CacheManager

use of org.xwiki.cache.CacheManager in project xwiki-platform by xwiki.

the class DefaultIconSetCacheTest method setUp.

@Before
public void setUp() throws Exception {
    cacheManager = mocker.getInstance(CacheManager.class);
    entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
    cache = mock(Cache.class);
    CacheFactory cacheFactory = mock(CacheFactory.class);
    when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
    CacheConfiguration configuration = new CacheConfiguration("iconset");
    when(cacheFactory.<IconSet>newCache(eq(configuration))).thenReturn(cache);
}
Also used : CacheManager(org.xwiki.cache.CacheManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) CacheFactory(org.xwiki.cache.CacheFactory) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Cache(org.xwiki.cache.Cache) IconSet(org.xwiki.icon.IconSet) Before(org.junit.Before)

Aggregations

CacheManager (org.xwiki.cache.CacheManager)12 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)10 Before (org.junit.Before)6 Cache (org.xwiki.cache.Cache)6 DocumentReference (org.xwiki.model.reference.DocumentReference)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 BaseObject (com.xpn.xwiki.objects.BaseObject)3 Test (org.junit.Test)3 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)3 ConverterManager (org.xwiki.properties.ConverterManager)3 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)3 XWiki (com.xpn.xwiki.XWiki)2 CacheFactory (org.xwiki.cache.CacheFactory)2 WikiReference (org.xwiki.model.reference.WikiReference)2 XWikiBridge (org.xwiki.security.internal.XWikiBridge)2 BeforeComponent (org.xwiki.test.annotation.BeforeComponent)2 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)1 XWikiAttachmentContent (com.xpn.xwiki.doc.XWikiAttachmentContent)1