Hi Sergiu,
Shouldn't your code be in the initialize() method instead?
Thanks
-Vincent
On Oct 15, 2008, at 1:31 AM, sdumitriu (SVN) wrote:
Author: sdumitriu
Date: 2008-10-15 01:31:44 +0200 (Wed, 15 Oct 2008)
New Revision: 13554
Added:
platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/com/
xpn/xwiki/test/TestApplicationContext.java
Modified:
platform/xwiki-tools/trunk/xwiki-shared-tests/pom.xml
platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/com/
xpn/xwiki/test/XWikiComponentInitializer.java
Log:
XTSHAREDTESTS-10: Set a default application context in the container
Done. This fixes the build.
Modified: platform/xwiki-tools/trunk/xwiki-shared-tests/pom.xml
===================================================================
--- platform/xwiki-tools/trunk/xwiki-shared-tests/pom.xml 2008-10-14
23:25:42 UTC (rev 13553)
+++ platform/xwiki-tools/trunk/xwiki-shared-tests/pom.xml 2008-10-14
23:31:44 UTC (rev 13554)
@@ -64,9 +64,18 @@
<version>${platform.core.version}</version>
</dependency>
<dependency>
+ <groupId>org.xwiki.platform</groupId>
+ <artifactId>xwiki-core-container-api</artifactId>
+ <version>${platform.core.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.0</version>
</dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ </dependency>
</dependencies>
</project>
Added: platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/
com/xpn/xwiki/test/TestApplicationContext.java
===================================================================
--- platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/com/
xpn/xwiki/test/TestApplicationContext.java
(rev 0)
+++ platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/com/
xpn/xwiki/test/TestApplicationContext.java 2008-10-14 23:31:44 UTC
(rev 13554)
@@ -0,0 +1,37 @@
+package com.xpn.xwiki.test;
+
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import org.apache.commons.lang.StringUtils;
+import org.xwiki.container.ApplicationContext;
+
+/**
+ * Simple {@link ApplicationContext} implementation that uses the
classloader's <code>getResource</code> and
+ * <code>getResourceAsStream</code> methods to access resources.
Useful for running tests without a real live container.
+ *
+ * @version $Id$
+ */
+public class TestApplicationContext implements ApplicationContext
+{
+ /**
+ * {@inheritDoc}
+ *
+ * @see ApplicationContext#getResource(String)
+ */
+ public URL getResource(String resourceName) throws
MalformedURLException
+ {
+ return
getClass
().getClassLoader
().getResource(StringUtils.removeStart(resourceName, "/"));
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see ApplicationContext#getResourceAsStream(String)
+ */
+ public InputStream getResourceAsStream(String resourceName)
+ {
+ return
getClass().getResourceAsStream(StringUtils.removeStart(resourceName,
"/"));
+ }
+}
Property changes on: platform/xwiki-tools/trunk/xwiki-shared-tests/
src/main/java/com/xpn/xwiki/test/TestApplicationContext.java
___________________________________________________________________
Name: svn:keywords
+ Author Id Revision HeadURL
Name: svn:eol-style
+ native
Modified: platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/
java/com/xpn/xwiki/test/XWikiComponentInitializer.java
===================================================================
--- platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/com/
xpn/xwiki/test/XWikiComponentInitializer.java 2008-10-14 23:25:42
UTC (rev 13553)
+++ platform/xwiki-tools/trunk/xwiki-shared-tests/src/main/java/com/
xpn/xwiki/test/XWikiComponentInitializer.java 2008-10-14 23:31:44
UTC (rev 13554)
@@ -19,14 +19,14 @@
*/
package com.xpn.xwiki.test;
+import org.codehaus.plexus.DefaultContainerConfiguration;
+import org.codehaus.plexus.DefaultPlexusContainer;
import org.xwiki.component.manager.ComponentManager;
-import org.xwiki.plexus.manager.PlexusComponentManager;
-import org.xwiki.context.ExecutionContextInitializerManager;
+import org.xwiki.container.Container;
import org.xwiki.context.Execution;
import org.xwiki.context.ExecutionContext;
-import org.codehaus.plexus.DefaultContainerConfiguration;
-import org.codehaus.plexus.DefaultPlexusContainer;
-import
org
.codehaus
.plexus.personality.plexus.lifecycle.phase.PlexusContainerLocator;
+import org.xwiki.context.ExecutionContextInitializerManager;
+import org.xwiki.plexus.manager.PlexusComponentManager;
public class XWikiComponentInitializer
{
@@ -57,8 +57,8 @@
}
/**
- * @return a configured Component Manager (which uses the
plexus.xml file in the test resources directory)
- * which can then be put in the XWiki Context for
testing.
+ * @return a configured Component Manager (which uses the
plexus.xml file in the test resources directory) which can
+ * then be put in the XWiki Context for testing.
*/
public ComponentManager getComponentManager() throws Exception
{
@@ -67,6 +67,10 @@
configuration.setContainerConfiguration("/plexus.xml");
DefaultPlexusContainer container = new
DefaultPlexusContainer(configuration);
this.componentManager = new
PlexusComponentManager(container);
+
+ // Set a simple application context, as some components
fail to start without one.
+ Container c = (Container)
this.componentManager.lookup(Container.ROLE);
+ c.setApplicationContext(new TestApplicationContext());
}
return this.componentManager;