use of org.xwiki.model.ModelContext in project xwiki-platform by xwiki.
the class JavaIntegrationTest method registerConfiguration.
@BeforeComponent
public void registerConfiguration() throws Exception {
this.configuration = new TestMailSenderConfiguration(this.mail.getSmtp().getPort(), null, null, new Properties());
this.componentManager.registerComponent(MailSenderConfiguration.class, this.configuration);
// Set the current wiki in the Context
ModelContext modelContext = this.componentManager.registerMockComponent(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("wiki"));
XWikiContext xcontext = mock(XWikiContext.class);
when(xcontext.getWikiId()).thenReturn("wiki");
Provider<XWikiContext> xwikiContextProvider = this.componentManager.registerMockComponent(XWikiContext.TYPE_PROVIDER);
when(xwikiContextProvider.get()).thenReturn(xcontext);
this.componentManager.registerMockComponent(ExecutionContextManager.class);
this.componentManager.registerMockComponent(Execution.class);
this.componentManager.registerMockComponent(new DefaultParameterizedType(null, Copier.class, ExecutionContext.class));
EnvironmentConfiguration environmentConfiguration = this.componentManager.registerMockComponent(EnvironmentConfiguration.class);
when(environmentConfiguration.getPermanentDirectoryPath()).thenReturn(System.getProperty("java.io.tmpdir"));
}
use of org.xwiki.model.ModelContext in project xwiki-platform by xwiki.
the class RestoreJobTest method configure.
@Override
public void configure() throws Exception {
super.configure();
Execution execution = mocker.getInstance(Execution.class);
ExecutionContext executionContext = mock(ExecutionContext.class);
when(execution.getContext()).thenReturn(executionContext);
modelContext = mocker.getInstance(ModelContext.class);
}
use of org.xwiki.model.ModelContext in project xwiki-platform by xwiki.
the class MessageStreamTest method setupForNewMessage.
private Event setupForNewMessage() throws ComponentLookupException, Exception {
final EventFactory mockEventFactory = getComponentManager().getInstance(EventFactory.class);
final Event e = new DefaultEvent();
e.setId(UUID.randomUUID().toString());
final ModelContext mockContext = getComponentManager().getInstance(ModelContext.class);
final EventStream mockEventStream = getComponentManager().getInstance(EventStream.class);
getMockery().checking(new Expectations() {
{
exactly(1).of(mockEventFactory).createEvent();
will(returnValue(e));
exactly(1).of(mockContext).getCurrentEntityReference();
will(returnValue(new DocumentReference("wiki", "Space", "Page")));
exactly(1).of(mockEventStream).addEvent(e);
}
});
return e;
}
use of org.xwiki.model.ModelContext in project xwiki-platform by xwiki.
the class TemporaryChartImageWriterTest method getStorageLocation.
@Test
public void getStorageLocation() throws Exception {
WikiReference currentWikiReference = new WikiReference("wiki");
ModelContext modelContext = this.componentManager.getInstance(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(currentWikiReference);
Environment environment = this.componentManager.getInstance(Environment.class);
when(environment.getTemporaryDirectory()).thenReturn(new File("/tmpdir"));
File location = this.componentManager.getComponentUnderTest().getStorageLocation(new ImageId(new ChartMacroParameters()));
Assert.assertTrue("Got: " + location.toString(), location.toString().matches("/tmpdir/temp/chart/wiki/space/page/.*\\.png"));
}
use of org.xwiki.model.ModelContext in project xwiki-platform by xwiki.
the class IntegrationTests method initialize.
@RenderingTestSuite.Initialized
public void initialize(MockitoComponentManager componentManager) throws Exception {
ModelContext modelContext = componentManager.registerMockComponent(ModelContext.class);
when(modelContext.getCurrentEntityReference()).thenReturn(new WikiReference("currentWiki"));
// Document Access Bridge mock
DocumentAccessBridge dab = componentManager.registerMockComponent(DocumentAccessBridge.class);
DocumentReference documentReference = new DocumentReference("wiki", "space", "page");
DocumentReference currentDocumentReference = new DocumentReference("currentwiki", "currentspace", "currentpage");
DocumentModelBridge document = Mockito.mock(DocumentModelBridge.class);
when(dab.getDocumentURL(new DocumentReference("currentWiki", "space", "page"), "temp", null, null)).thenReturn("temppath");
when(dab.getCurrentDocumentReference()).thenReturn(currentDocumentReference);
when(dab.exists(documentReference)).thenReturn(true);
when(dab.getDocumentInstance(documentReference)).thenReturn(document);
when(dab.getCurrentUserReference()).thenReturn(null);
DocumentDisplayer displayer = componentManager.registerMockComponent(DocumentDisplayer.class);
Parser parser = componentManager.getInstance(Parser.class, Syntax.XWIKI_2_0.toIdString());
final XDOM xdom = parser.parse(new InputStreamReader(getClass().getClassLoader().getResourceAsStream(WIKI_CONTENT_FILE)));
when(displayer.display(eq(document), any(DocumentDisplayerParameters.class))).thenReturn(xdom);
AuthorizationManager authorizationManager = componentManager.registerMockComponent(AuthorizationManager.class);
when(authorizationManager.hasAccess(Right.VIEW, null, documentReference)).thenReturn(true);
componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_STRING, "current");
componentManager.registerMockComponent(SpaceReferenceResolver.TYPE_STRING, "current");
}
Aggregations