Search in sources :

Example 1 with ModelContext

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"));
}
Also used : ModelContext(org.xwiki.model.ModelContext) ExecutionContext(org.xwiki.context.ExecutionContext) EnvironmentConfiguration(org.xwiki.environment.internal.EnvironmentConfiguration) Copier(org.xwiki.mail.internal.thread.context.Copier) XWikiContext(com.xpn.xwiki.XWikiContext) Properties(java.util.Properties) WikiReference(org.xwiki.model.reference.WikiReference) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) BeforeComponent(org.xwiki.test.annotation.BeforeComponent)

Example 2 with ModelContext

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);
}
Also used : ModelContext(org.xwiki.model.ModelContext) Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext)

Example 3 with ModelContext

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;
}
Also used : ModelContext(org.xwiki.model.ModelContext) Expectations(org.jmock.Expectations) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) EventStream(org.xwiki.eventstream.EventStream) EventFactory(org.xwiki.eventstream.EventFactory) Event(org.xwiki.eventstream.Event) DefaultEvent(org.xwiki.eventstream.internal.DefaultEvent) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 4 with ModelContext

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"));
}
Also used : ModelContext(org.xwiki.model.ModelContext) ChartMacroParameters(org.xwiki.rendering.macro.chart.ChartMacroParameters) Environment(org.xwiki.environment.Environment) WikiReference(org.xwiki.model.reference.WikiReference) File(java.io.File) Test(org.junit.Test)

Example 5 with ModelContext

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");
}
Also used : ModelContext(org.xwiki.model.ModelContext) DocumentDisplayerParameters(org.xwiki.display.internal.DocumentDisplayerParameters) DocumentDisplayer(org.xwiki.display.internal.DocumentDisplayer) XDOM(org.xwiki.rendering.block.XDOM) DocumentModelBridge(org.xwiki.bridge.DocumentModelBridge) InputStreamReader(java.io.InputStreamReader) DocumentAccessBridge(org.xwiki.bridge.DocumentAccessBridge) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Parser(org.xwiki.rendering.parser.Parser)

Aggregations

ModelContext (org.xwiki.model.ModelContext)12 WikiReference (org.xwiki.model.reference.WikiReference)7 ExecutionContext (org.xwiki.context.ExecutionContext)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Test (org.junit.Test)4 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)4 XWikiContext (com.xpn.xwiki.XWikiContext)3 Properties (java.util.Properties)3 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)3 EnvironmentConfiguration (org.xwiki.environment.internal.EnvironmentConfiguration)3 Copier (org.xwiki.mail.internal.thread.context.Copier)3 BeforeComponent (org.xwiki.test.annotation.BeforeComponent)3 VelocityContext (org.apache.velocity.VelocityContext)2 Before (org.junit.Before)2 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)2 Execution (org.xwiki.context.Execution)2 XDOM (org.xwiki.rendering.block.XDOM)2 ChartMacroParameters (org.xwiki.rendering.macro.chart.ChartMacroParameters)2 Parser (org.xwiki.rendering.parser.Parser)2 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)2