Search in sources :

Example 1 with ConverterManager

use of org.xwiki.properties.ConverterManager 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 2 with ConverterManager

use of org.xwiki.properties.ConverterManager 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 3 with ConverterManager

use of org.xwiki.properties.ConverterManager in project xwiki-platform by xwiki.

the class CommonsConfigurationSourceTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.source = new CommonsConfigurationSource();
    ConverterManager converterManager = getComponentManager().getInstance(ConverterManager.class);
    ReflectionUtils.setFieldValue(source, "converterManager", converterManager);
    this.configuration = new BaseConfiguration();
    this.source.setConfiguration(this.configuration);
}
Also used : BaseConfiguration(org.apache.commons.configuration2.BaseConfiguration) ConverterManager(org.xwiki.properties.ConverterManager) Before(org.junit.Before)

Example 4 with ConverterManager

use of org.xwiki.properties.ConverterManager in project xwiki-platform by xwiki.

the class CompositeConfigurationSourceTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    this.composite = new CompositeConfigurationSource();
    ConverterManager converterManager = getComponentManager().getInstance(ConverterManager.class);
    CommonsConfigurationSource source1 = new CommonsConfigurationSource();
    ReflectionUtils.setFieldValue(source1, "converterManager", converterManager);
    this.config1 = new PropertiesConfiguration();
    source1.setConfiguration(this.config1);
    this.composite.addConfigurationSource(source1);
    CommonsConfigurationSource source2 = new CommonsConfigurationSource();
    ReflectionUtils.setFieldValue(source2, "converterManager", converterManager);
    this.config2 = new PropertiesConfiguration();
    source2.setConfiguration(this.config2);
    this.composite.addConfigurationSource(source2);
}
Also used : ConverterManager(org.xwiki.properties.ConverterManager) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) Before(org.junit.Before)

Example 5 with ConverterManager

use of org.xwiki.properties.ConverterManager in project xwiki-platform by xwiki.

the class TemplateMimeMessageFactoryTest method createMessageWithToFromCCAndBCCAddressesAsStrings.

@Test
public void createMessageWithToFromCCAndBCCAddressesAsStrings() throws Exception {
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("language", "fr");
    parameters.put("velocityVariables", Collections.<String, Object>singletonMap("company", "XWiki"));
    parameters.put("to", "to@doe.com");
    parameters.put("cc", "cc@doe.com");
    parameters.put("bcc", "bcc@doe.com");
    parameters.put("from", "from@doe.com");
    ConverterManager converterManager = this.mocker.getInstance(ConverterManager.class);
    when(converterManager.convert(Address[].class, "to@doe.com")).thenReturn(InternetAddress.parse("to@doe.com"));
    when(converterManager.convert(Address[].class, "cc@doe.com")).thenReturn(InternetAddress.parse("cc@doe.com"));
    when(converterManager.convert(Address[].class, "bcc@doe.com")).thenReturn(InternetAddress.parse("bcc@doe.com"));
    when(converterManager.convert(Address.class, "from@doe.com")).thenReturn(InternetAddress.parse("from@doe.com")[0]);
    MimeMessage message = this.mocker.getComponentUnderTest().createMessage(this.templateReference, parameters);
    assertEquals("XWiki news", message.getSubject());
    assertArrayEquals(InternetAddress.parse("from@doe.com"), message.getFrom());
    assertArrayEquals(InternetAddress.parse("to@doe.com"), message.getRecipients(Message.RecipientType.TO));
    assertArrayEquals(InternetAddress.parse("cc@doe.com"), message.getRecipients(Message.RecipientType.CC));
    assertArrayEquals(InternetAddress.parse("bcc@doe.com"), message.getRecipients(Message.RecipientType.BCC));
    // Also verify that a body part has been added
    assertEquals(this.mimeBodyPart, ((MimeMultipart) message.getContent()).getBodyPart(0));
}
Also used : ConverterManager(org.xwiki.properties.ConverterManager) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) HashMap(java.util.HashMap) MimeMessage(javax.mail.internet.MimeMessage) Test(org.junit.Test)

Aggregations

ConverterManager (org.xwiki.properties.ConverterManager)5 Before (org.junit.Before)3 Test (org.junit.Test)2 CacheManager (org.xwiki.cache.CacheManager)2 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 HashMap (java.util.HashMap)1 Address (javax.mail.Address)1 InternetAddress (javax.mail.internet.InternetAddress)1 MimeMessage (javax.mail.internet.MimeMessage)1 BaseConfiguration (org.apache.commons.configuration2.BaseConfiguration)1 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)1 DefaultDocumentFormatRegistry (org.artofsolving.jodconverter.document.DefaultDocumentFormatRegistry)1 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)1 Cache (org.xwiki.cache.Cache)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1