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"));
}
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());
}
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);
}
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);
}
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));
}
Aggregations