use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DocumentTitleDisplayerTest method configure.
@Before
public void configure() throws Exception {
// The execution context is expected to have the "xwikicontext" property set.
Execution mockExecution = this.mocker.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty("xwikicontext", new HashMap<String, Object>());
Mockito.when(mockExecution.getContext()).thenReturn(executionContext);
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DisplayMacroTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
// Put a fake XWiki context on the execution context.
Execution execution = getComponentManager().getInstance(Execution.class);
execution.getContext().setProperty("xwikicontext", new HashMap<Object, Object>());
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class EventAndFactoryTest method configure.
@Before
public void configure() throws Exception {
final DocumentAccessBridge mockDocumentAccessBridge = getComponentManager().getInstance(DocumentAccessBridge.class);
getMockery().checking(new Expectations() {
{
allowing(mockDocumentAccessBridge).getCurrentUser();
will(returnValue("XWiki.Admin"));
}
});
final ExecutionContext context = new ExecutionContext();
final Execution mockExecution = getComponentManager().getInstance(Execution.class);
getMockery().checking(new Expectations() {
{
allowing(mockExecution).getContext();
will(returnValue(context));
}
});
final EntityReferenceResolver<String> mockResolver = getComponentManager().getInstance(EntityReferenceResolver.TYPE_STRING);
getMockery().checking(new Expectations() {
{
allowing(mockResolver).resolve("XWiki.Admin", EntityType.DOCUMENT);
will(returnValue(new DocumentReference("xwiki", "XWiki", "Admin")));
}
});
this.factory = getComponentManager().getInstance(EventFactory.class);
this.defaultEvent = this.factory.createEvent();
this.rawEvent = this.factory.createRawEvent();
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class DocumentContentDisplayerTest method testBaseMetaDataIsSetBeforeExecutingTransformations.
@Test
public void testBaseMetaDataIsSetBeforeExecutingTransformations() throws Exception {
// The execution context is expected to have the "xwikicontext" property set.
Execution mockExecution = mocker.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
executionContext.setProperty("xwikicontext", new HashMap<String, Object>());
Mockito.when(mockExecution.getContext()).thenReturn(executionContext);
// The document being displayed.
DocumentModelBridge mockDocument = Mockito.mock(DocumentModelBridge.class);
XDOM content = new XDOM(Collections.<Block>emptyList());
Mockito.when(mockDocument.getXDOM()).thenReturn(content);
// The reference of the current document musts be set as the value of the BASE meta data.
DocumentReference currentDocRef = new DocumentReference("wiki", "Space", "Page");
DocumentAccessBridge mockDocumentAccessBridge = mocker.getInstance(DocumentAccessBridge.class);
Mockito.when(mockDocumentAccessBridge.getCurrentDocumentReference()).thenReturn(currentDocRef);
EntityReferenceSerializer<String> serializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
Mockito.when(serializer.serialize(currentDocRef)).thenReturn("foo");
// We can't verify the meta data after the display method is called because we want to make sure the BASE meta
// data is correctly set before XDOM transformations are executed, not after.
TransformationManager mockTransformationManager = mocker.getInstance(TransformationManager.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
XDOM xdom = (XDOM) invocation.getArguments()[0];
// We have to assert the meta data before the transformations are executed not at the end!
Assert.assertEquals("foo", xdom.getMetaData().getMetaData(MetaData.BASE));
return null;
}
}).when(mockTransformationManager).performTransformations(Mockito.any(XDOM.class), Mockito.any(TransformationContext.class));
// Execute the display.
Assert.assertSame(content, mocker.getComponentUnderTest().display(mockDocument, new DocumentDisplayerParameters()));
// Make sure the transformations are executed exactly once, and on the right content.
Mockito.verify(mockTransformationManager, Mockito.times(1)).performTransformations(Mockito.same(content), Mockito.any(TransformationContext.class));
}
use of org.xwiki.context.Execution in project xwiki-platform by xwiki.
the class AuthenticatingIntegrationTest method sendTextMail.
@Test
public void sendTextMail() throws Exception {
// Set the EC
Execution execution = this.componentManager.getInstance(Execution.class);
ExecutionContext executionContext = new ExecutionContext();
XWikiContext xContext = new XWikiContext();
xContext.setWikiId("wiki");
executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, xContext);
when(execution.getContext()).thenReturn(executionContext);
Copier<ExecutionContext> executionContextCloner = this.componentManager.getInstance(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
// Just return the same execution context
when(executionContextCloner.copy(executionContext)).thenReturn(executionContext);
// Step 1: Create a JavaMail Session
Properties properties = this.configuration.getAllProperties();
assertEquals("true", properties.getProperty(DefaultMailSenderConfiguration.JAVAMAIL_SMTP_AUTH));
Session session = Session.getInstance(properties, new XWikiAuthenticator(this.configuration));
// Step 2: Create the Message to send
MimeMessage message = new MimeMessage(session);
message.setSubject("subject");
message.setRecipient(RecipientType.TO, new InternetAddress("john@doe.com"));
// Step 3: Add the Message Body
Multipart multipart = new MimeMultipart("mixed");
// Add text in the body
multipart.addBodyPart(this.defaultBodyPartFactory.create("some text here", Collections.<String, Object>singletonMap("mimetype", "text/plain")));
message.setContent(multipart);
// Step 4: Send the mail
this.sender.sendAsynchronously(Arrays.asList(message), session, null);
// Verify that the mail has been received (wait maximum 30 seconds).
this.mail.waitForIncomingEmail(30000L, 1);
MimeMessage[] messages = this.mail.getReceivedMessages();
assertEquals(1, messages.length);
assertEquals("subject", messages[0].getHeader("Subject", null));
assertEquals("john@doe.com", messages[0].getHeader("To", null));
assertEquals(1, ((MimeMultipart) messages[0].getContent()).getCount());
BodyPart textBodyPart = ((MimeMultipart) messages[0].getContent()).getBodyPart(0);
assertEquals("text/plain", textBodyPart.getHeader("Content-Type")[0]);
assertEquals("some text here", textBodyPart.getContent());
}
Aggregations