Search in sources :

Example 56 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class IncludeMacroTest 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>());
}
Also used : Execution(org.xwiki.context.Execution)

Example 57 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class DatabasePingDataProviderTest method provideData.

@Test
public void provideData() throws Exception {
    Execution execution = this.mocker.getInstance(Execution.class);
    ExecutionContext executionContext = mock(ExecutionContext.class);
    when(execution.getContext()).thenReturn(executionContext);
    XWikiContext xwikiContext = mock(XWikiContext.class);
    when(executionContext.getProperty(XWikiContext.EXECUTIONCONTEXT_KEY)).thenReturn(xwikiContext);
    com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class);
    when(xwikiContext.getWiki()).thenReturn(xwiki);
    XWikiCacheStoreInterface cacheStore = mock(XWikiCacheStoreInterface.class);
    when(xwiki.getStore()).thenReturn(cacheStore);
    XWikiHibernateStore store = mock(XWikiHibernateStore.class);
    when(cacheStore.getStore()).thenReturn(store);
    DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
    when(store.getDatabaseMetaData()).thenReturn(databaseMetaData);
    when(databaseMetaData.getDatabaseProductName()).thenReturn("HSQL Database Engine");
    when(databaseMetaData.getDatabaseProductVersion()).thenReturn("2.2.9");
    Map<String, Object> data = this.mocker.getComponentUnderTest().provideData();
    assertEquals(2, data.size());
    assertEquals("HSQL Database Engine", data.get("dbName"));
    assertEquals("2.2.9", data.get("dbVersion"));
}
Also used : Execution(org.xwiki.context.Execution) ExecutionContext(org.xwiki.context.ExecutionContext) XWikiHibernateStore(com.xpn.xwiki.store.XWikiHibernateStore) XWikiCacheStoreInterface(com.xpn.xwiki.store.XWikiCacheStoreInterface) XWikiContext(com.xpn.xwiki.XWikiContext) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 58 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class HibernateStoreTest method before.

@Before
public void before() throws ComponentLookupException {
    ExecutionContext executionContext = mock(ExecutionContext.class);
    Execution execution = this.mocker.getInstance(Execution.class);
    when(execution.getContext()).thenReturn(executionContext);
    when(executionContext.getProperty("hibtransaction")).thenReturn(transaction);
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) Before(org.junit.Before)

Example 59 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class AbstractBridgedComponentTestCase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // Statically store the component manager in {@link Utils} to be able to access it without
    // the context.
    Utils.setComponentManager(getComponentManager());
    this.context = new XWikiContext();
    this.context.setWikiId("xwiki");
    this.context.setMainXWiki("xwiki");
    // We need to initialize the Component Manager so that the components can be looked up
    getContext().put(ComponentManager.class.getName(), getComponentManager());
    // Bridge with old XWiki Context, required for old code.
    Execution execution = getComponentManager().getInstance(Execution.class);
    execution.getContext().setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.context);
    XWikiStubContextProvider stubContextProvider = getComponentManager().getInstance(XWikiStubContextProvider.class);
    stubContextProvider.initialize(this.context);
    // Since the oldcore module draws the Servlet Environment in its dependencies we need to ensure it's set up
    // correctly with a Servlet Context.
    ServletEnvironment environment = (ServletEnvironment) getComponentManager().getInstance(Environment.class);
    final ServletContext mockServletContext = getMockery().mock(ServletContext.class);
    environment.setServletContext(mockServletContext);
    getMockery().checking(new Expectations() {

        {
            allowing(mockServletContext).getResourceAsStream("/WEB-INF/cache/infinispan/config.xml");
            will(returnValue(null));
            allowing(mockServletContext).getResourceAsStream("/WEB-INF/xwiki.cfg");
            will(returnValue(null));
            allowing(mockServletContext).getAttribute("javax.servlet.context.tempdir");
            will(returnValue(new File(System.getProperty("java.io.tmpdir"))));
        }
    });
    final CoreConfiguration mockCoreConfiguration = registerMockComponent(CoreConfiguration.class);
    getMockery().checking(new Expectations() {

        {
            allowing(mockCoreConfiguration).getDefaultDocumentSyntax();
            will(returnValue(Syntax.XWIKI_1_0));
        }
    });
}
Also used : XWikiStubContextProvider(com.xpn.xwiki.util.XWikiStubContextProvider) Expectations(org.jmock.Expectations) Execution(org.xwiki.context.Execution) ComponentManager(org.xwiki.component.manager.ComponentManager) XWikiContext(com.xpn.xwiki.XWikiContext) ServletEnvironment(org.xwiki.environment.internal.ServletEnvironment) Environment(org.xwiki.environment.Environment) ServletContext(javax.servlet.ServletContext) ServletEnvironment(org.xwiki.environment.internal.ServletEnvironment) CoreConfiguration(com.xpn.xwiki.CoreConfiguration) File(java.io.File) Before(org.junit.Before)

Example 60 with Execution

use of org.xwiki.context.Execution in project xwiki-platform by xwiki.

the class DocumentSolrMetadataExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    this.mocker.registerMockComponent(SolrReferenceResolver.class, "document");
    // XWikiContext Provider
    Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(this.xcontext);
    // XWikiContext trough Execution
    ExecutionContext executionContext = new ExecutionContext();
    executionContext.setProperty(XWikiContext.EXECUTIONCONTEXT_KEY, this.xcontext);
    Execution execution = this.mocker.registerMockComponent(Execution.class);
    when(execution.getContext()).thenReturn(executionContext);
    // XWiki
    XWiki wiki = mock(XWiki.class);
    when(this.xcontext.getWiki()).thenReturn(wiki);
    // XWikiDocument
    when(wiki.getDocument(this.documentReference, this.xcontext)).thenReturn(this.document);
    when(this.document.getDocumentReference()).thenReturn(this.documentReference);
    when(this.document.isHidden()).thenReturn(false);
    when(this.document.getLocale()).thenReturn(Locale.ROOT);
    when(this.document.getRealLocale()).thenReturn(Locale.US);
    when(this.document.getTranslatedDocument(Locale.FRENCH, this.xcontext)).thenReturn(this.translatedDocument);
    when(this.translatedDocument.getRealLocale()).thenReturn(Locale.FRENCH);
    when(this.translatedDocument.getLocale()).thenReturn(Locale.FRENCH);
    when(this.translatedDocument.getDocumentReference()).thenReturn(this.frenchDocumentReference);
    // Field Name Serializer
    EntityReferenceSerializer<String> fieldNameSerializer = this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "solr");
    when(fieldNameSerializer.serialize(any())).then(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            EntityReference reference = (EntityReference) invocation.getArguments()[0];
            StringBuilder result = new StringBuilder();
            for (EntityReference parent : reference.getReversedReferenceChain()) {
                result.append('.').append(parent.getName());
            }
            return result.substring(1);
        }
    });
    // Field Name Encoder
    SolrFieldNameEncoder fieldNameEncoder = this.mocker.getInstance(SolrFieldNameEncoder.class);
    when(fieldNameEncoder.encode(any())).then(AdditionalAnswers.returnsFirstArg());
}
Also used : SolrFieldNameEncoder(org.xwiki.search.solr.internal.api.SolrFieldNameEncoder) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) ExecutionContext(org.xwiki.context.ExecutionContext) Execution(org.xwiki.context.Execution) InvocationOnMock(org.mockito.invocation.InvocationOnMock) EntityReference(org.xwiki.model.reference.EntityReference) Before(org.junit.Before)

Aggregations

Execution (org.xwiki.context.Execution)82 ExecutionContext (org.xwiki.context.ExecutionContext)58 Before (org.junit.Before)36 XWikiContext (com.xpn.xwiki.XWikiContext)30 Test (org.junit.Test)19 DocumentReference (org.xwiki.model.reference.DocumentReference)17 XWiki (com.xpn.xwiki.XWiki)13 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)13 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)11 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)10 DocumentAccessBridge (org.xwiki.bridge.DocumentAccessBridge)8 ComponentManager (org.xwiki.component.manager.ComponentManager)8 HashMap (java.util.HashMap)7 Expectations (org.jmock.Expectations)7 VelocityContext (org.apache.velocity.VelocityContext)5 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)5 BaseObject (com.xpn.xwiki.objects.BaseObject)4 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)4 XDOM (org.xwiki.rendering.block.XDOM)4 AuthorizationManager (org.xwiki.security.authorization.AuthorizationManager)4