0
votes

I want to test some classes from a alfresco module (AMP) project. The project is based to maven 3.

I'm quite new to Alfresco and Maven, so please be patient ... :) The folder src/main/java includes all classes of the module. Now I've created a test class in src/test/java with the same package as the class I want to test. The test class extends the BaseAlfrescoTestCase class.

I added JUnit 4.11 to the POM dependencies.

Executing mvn clean integration-test -P webapp I got an exception, that the application-context.xml was not found:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.189 sec <<< FAILURE! testCreateinitialSpaces(AlfresoTest) Time elapsed: 0.158 sec <<< ERROR! org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [alfresco/application-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [alfresco/application-context.xml] cannot be opened because it does not exist at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:458) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:388) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) at org.alfresco.util.BaseApplicationContextHelper.getApplicationContext(BaseApplicationContextHelper.java:67) at org.alfresco.util.ApplicationContextHelper.getApplicationContext(ApplicationContextHelper.java:46) at org.alfresco.util.BaseAlfrescoTestCase.setUpContext(BaseAlfrescoTestCase.java:84) at org.alfresco.util.BaseAlfrescoTestCase.setUp(BaseAlfrescoTestCase.java:102)

Apparently the BaseAlfrescoTestCase.setUp method is not able to get the injected properties (as serviceRegistry etc ...) from Spring Framework.

The application-context.xml actually doesn't exist, but unfortunately I have no clue how to set up a proper application-context.xml for test purpose.

I thought the application-context is provided by jetty? The pom.xml was original configured by a colleague and he is not reachable right now. Jetty starts properly when I am skipping the tests: mvn clean -Dmaven.test.skip=true integration-test -P webapp

I searched a lot, but I did not find many tutorials for Alfresco in combination with Maven and Junit. All tutorials I've found did not work for me... Thanks for your help

EDIT: here are all dependencies in my pom.xml:

<dependencies>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-core</artifactId>
            <version>4.0.b</version>
            <scope>provided</scope>
            <classifier>community</classifier>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-repository</artifactId>
            <version>4.2.c</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-datamodel</artifactId>
            <version>4.2.c</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.alfresco</groupId>
            <artifactId>alfresco-web-client</artifactId>
            <version>4.2.c</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.0.5.RELEASE</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>3.0.5.RELEASE</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.opensymphony.quartz</groupId>
            <artifactId>com.springsource.org.quartz</artifactId>
            <version>1.6.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.extensions.surf</groupId>
            <artifactId>spring-webscripts</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.log4j</groupId>
            <artifactId>com.springsource.org.apache.log4j</artifactId>
            <version>1.2.16</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.0.1b</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>com.springsource.javax.mail</artifactId>
            <version>1.4.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

EDIT:

after adding application-context.xml, application-context-core.xml and a fake-context folder to resource folder in the maven project this error occurs:

testCreateinitialSpaces(AlfrescoTest)  Time elapsed: 0.56 sec  <<< ERROR!
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'ServiceRegistry' is defined
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:527)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1083)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:274)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
    at org.alfresco.util.BaseAlfrescoTestCase.setUp(BaseAlfrescoTestCase.java:105)

Apparently the ServiceRegistry Bean is not available?!

EDIT: I copied the complete Alfresco folder from <WAR>/WEB-INF/classes/alfresco to src/test/resources. Actually no XML file is missing anymore, but the test fails with CannotLoadBeanClassException:

org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.alfresco.repo.cache.InternalEhCacheManagerFactoryBean] for bean with name 'internalEHCacheManager' defined in class path resource [alfresco/cache-context.xml]; nested exception is java.lang.ClassNotFoundException: org.alfresco.repo.cache.InternalEhCacheManagerFactoryBean at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at org.springframework.util.ClassUtils.forName(ClassUtils.java:257) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:408) at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1271) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1242) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:576) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1319) at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:885) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:562) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:93) at org.alfresco.util.BaseApplicationContextHelper.getApplicationContext(BaseApplicationContextHelper.java:67) at org.alfresco.util.ApplicationContextHelper.getApplicationContext(ApplicationContextHelper.java:46) at org.alfresco.util.BaseAlfrescoTestCase.setUpContext(BaseAlfrescoTestCase.java:84) at org.alfresco.util.BaseAlfrescoTestCase.setUp(BaseAlfrescoTestCase.java:102)

1
My first guess is that you've not included all the bits of Alfresco that you need. Are you able to tell us what bits of Alfresco you depended on in your pom, and at what version? - Gagravarr
thanks for your reply. sorry all dependencies are too long for a comment... please see the edit on my post - caldicot
You seem to have a mixture of Alfresco versions in there - some 4.0.d and some 3.4.e. You probably want to fix that first! - Gagravarr
Ok, thanks for the hint. I've updated the 3.4.e sources. Please find the new dependencies in my original post. Unfortunately the error during the test remains... I do not understand, why I have to add "-SNAPSHOT" to the alfresco-data-model and alfresco-web-client dependencies. If I do not add SNAPSHOT the dependencies cannot be resolved by maven. The alfresco-core dependency obviously does not need any addition. - caldicot
Why are you using 3.4.e? It's ancient! The maven support is currently still somewhat WIP, so you'll have more chance with a more recent one (eg something from 4.1 enterprise or 4.2 community) - Gagravarr

1 Answers

0
votes

java.io.FileNotFoundException: class path resource [alfresco/application-context.xml] cannot be opened because it does not exist at

make sure you have alfresco/application-context.xml in the classpath. Where do you put your application-context.xml? try to put it in: src/main/resources/alfresco/application-context.xml, maven will copy it to the classpath