use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class DefaultMailTemplateManagerTest method evaluateWithObjectNotFoundWithDefaultLanguage.
@Test
public void evaluateWithObjectNotFoundWithDefaultLanguage() throws Exception {
DocumentAccessBridge documentBridge = this.mocker.getInstance(DocumentAccessBridge.class);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
// First call with the passed language, return -1 (No XWiki.Mail xobject found)
when(documentBridge.getObjectNumber(any(), any(), eq("language"), eq("fr"))).thenReturn(-1);
// Second call with the default language, return -1 (No XWiki.Mail xobject found)
when(documentBridge.getObjectNumber(any(), any(), eq("language"), eq("en"))).thenReturn(-1);
when(documentBridge.getProperty(any(DocumentReference.class), any(), eq(0), eq("html"))).thenReturn("Salut <b>${name}</b> <br />${email}");
VelocityEngine velocityEngine = mock(VelocityEngine.class);
VelocityManager velocityManager = this.mocker.getInstance(VelocityManager.class);
when(velocityManager.getVelocityEngine()).thenReturn(velocityEngine);
when(velocityEvaluator.evaluateVelocity(eq("Salut <b>${name}</b> <br />${email}"), any(), any(VelocityContext.class))).thenReturn("Salut <b>John Doe</b> <br />john@doe.com");
String result = this.mocker.getComponentUnderTest().evaluate(documentReference, "html", Collections.emptyMap(), Locale.FRENCH);
verify(documentBridge).getObjectNumber(any(), any(), eq("language"), eq("fr"));
verify(documentBridge).getObjectNumber(any(), any(), eq("language"), eq("en"));
assertEquals(result, "Salut <b>John Doe</b> <br />john@doe.com");
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class TemplateMimeBodyPartFactoryTest method createWithAttachmentAndTemplateAttachments.
@Test
public void createWithAttachmentAndTemplateAttachments() throws Exception {
MimeBodyPartFactory<String> htmlMimeBodyPartFactory = this.mocker.getInstance(new DefaultParameterizedType(null, MimeBodyPartFactory.class, String.class), "text/html");
Attachment attachment1 = mock(Attachment.class, "attachment1");
Map<String, Object> bodyPartParameters = new HashMap<>();
bodyPartParameters.put("velocityVariables", new HashMap<String, String>());
bodyPartParameters.put("attachments", Collections.singletonList(attachment1));
bodyPartParameters.put("includeTemplateAttachments", true);
// Mock the retrieval and conversion of attachments from the Template document
DocumentAccessBridge dab = this.mocker.getInstance(DocumentAccessBridge.class);
XWikiDocument xwikiDocument = mock(XWikiDocument.class);
when(dab.getDocumentInstance(this.documentReference)).thenReturn(xwikiDocument);
XWikiAttachment xwikiAttachment = mock(XWikiAttachment.class);
when(xwikiDocument.getAttachmentList()).thenReturn(Collections.singletonList(xwikiAttachment));
AttachmentConverter attachmentConverter = this.mocker.getInstance(AttachmentConverter.class);
Attachment attachment2 = mock(Attachment.class, "attachment2");
when(attachmentConverter.convert(Collections.singletonList(xwikiAttachment))).thenReturn(Collections.singletonList(attachment2));
this.mocker.getComponentUnderTest().create(this.documentReference, bodyPartParameters);
Map<String, Object> htmlParameters = new HashMap<>();
htmlParameters.put("alternate", "Hello John Doe, john@doe.com");
htmlParameters.put("attachments", Arrays.asList(attachment1, attachment2));
verify(htmlMimeBodyPartFactory).create("Hello <b>John Doe</b> <br />john@doe.com", htmlParameters);
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class MessageStreamTest method testPostDirectMessageWithNonExistingTarget.
@Test(expected = IllegalArgumentException.class)
public void testPostDirectMessageWithNonExistingTarget() throws Exception {
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
final DocumentReference targetUser = new DocumentReference("xwiki", "XWiki", "Nobody");
getMockery().checking(new Expectations() {
{
exactly(1).of(mockBridge).exists(targetUser);
will(returnValue(false));
}
});
this.stream.postDirectMessageToUser("Hello Nobody!", targetUser);
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class MessageStreamTest method setupForDirectMessage.
private Event setupForDirectMessage() throws ComponentLookupException, Exception {
final Event e = setupForNewMessage();
final EntityReferenceSerializer<String> mockSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
getMockery().checking(new Expectations() {
{
exactly(1).of(mockBridge).exists(MessageStreamTest.this.targetUser);
will(returnValue(true));
exactly(1).of(mockSerializer).serialize(MessageStreamTest.this.targetUser);
will(returnValue("wiki:XWiki.JaneBuck"));
}
});
return e;
}
use of org.xwiki.bridge.DocumentAccessBridge in project xwiki-platform by xwiki.
the class MessageStreamTest method testGetRecentPersonalMessagesWhenQueryFails.
@Test
public void testGetRecentPersonalMessagesWhenQueryFails() throws Exception {
final Query mockQuery = getMockQuery();
final QueryManager mockQueryManager = getComponentManager().getInstance(QueryManager.class);
final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class);
final DocumentAccessBridge mockBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
final EntityReferenceSerializer<String> mockSerializer = getComponentManager().getInstance(EntityReferenceSerializer.TYPE_STRING);
getMockery().checking(new Expectations() {
{
allowing(mockBridge).getCurrentUserReference();
will(returnValue(MessageStreamTest.this.currentUser));
allowing(mockSerializer).serialize(MessageStreamTest.this.currentUser);
will(returnValue("wiki:XWiki.JohnDoe"));
exactly(1).of(mockQuery).setLimit(30);
will(returnValue(mockQuery));
exactly(1).of(mockQuery).setOffset(0);
will(returnValue(mockQuery));
allowing(mockQuery).bindValue(with(any(String.class)), with("wiki:XWiki.JohnDoe"));
allowing(mockQueryManager).createQuery(with(aNonNull(String.class)), with(aNonNull(String.class)));
will(returnValue(mockQuery));
exactly(1).of(mockEventStream).searchEvents(with(mockQuery));
will(throwException(new QueryException("", null, null)));
}
});
List<Event> result = this.stream.getRecentPersonalMessages();
Assert.assertNotNull(result);
Assert.assertTrue(result.isEmpty());
}
Aggregations