Currently I'm trying to create a test environment in Junit. As an example I used the DemoComponentTest.class to create my own Test class:
import com.tradeshift.test.remote.Remote;
import com.tradeshift.test.remote.RemoteTestRunner;
import org.alfresco.service.ServiceRegistry;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:alfresco/application-context.xml"})
public class DocumentManagementTest {
@Autowired ServiceRegistry serviceRegistry;
@Test
public void testWiring() {
Assert.assertNotNull(serviceRegistry);
}
}
When my app is running and I run the test it gives me the following exceptions:
junit.framework.AssertionFailedError: java.lang.IllegalStateException: Failed to load ApplicationContext at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103)
........
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'patch.updateAdminUserWhenDefault' defined in URL [jar:file:/D:/alfresco-samples/sampleapp/target/amp-war/WEB-INF/lib/alfresco-repository-5.2.g.jar!/alfresco/patch/patch-services-context.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'webscript.org.alfresco.slingshot.datalists.list.get' defined in file [D:\alfresco-samples\sampleapp\target\amp-war\WEB-INF\classes\alfresco\module\alfresco-share-services\module-context.xml]: Could not resolve parent bean definition 'declarativeSpreadsheetWebScript'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'declarativeSpreadsheetWebScript' is defined
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1514)
at
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'declarativeSpreadsheetWebScript' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:575)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1111)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:892)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:1166)
... 60 more
.....................
at com.tradeshift.test.remote.internal.InternalRemoteRunner.runChild(InternalRemoteRunner.java:162)
at com.tradeshift.test.remote.internal.InternalRemoteRunner.runChild(InternalRemoteRunner.java:41)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
In pom.xml:
<parent>
<groupId>org.alfresco.maven</groupId>
<artifactId>alfresco-sdk-parent</artifactId>
<version>2.2.0</version>
</parent>
When I run the app I use:
-Pamp-to-war
Extract:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'patch.updateAdminUserWhenDefault' defined in URL [jar:file:/D:/alfresco-samples/sampleapp/target/amp-war/WEB-INF/lib/alfresco-repository-5.2.g.jar!/alfresco/patch/patch-services-context.xml]: Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'webscript.org.alfresco.slingshot.datalists.list.get' defined in file [D:\alfresco-samples\sampleapp\target\amp-war\WEB-INF\classes\alfresco\module\alfresco-share-services\module-context.xml]: Could not resolve parent bean definition 'declarativeSpreadsheetWebScript'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'declarativeSpreadsheetWebScript' is defined
FYI https://community.alfresco.com/thread/214051-remote-unit-testing#comment-716388
Have you also tried using Alfresco Maven SDK v3.0.1 ?
Regards,
Jan
Yes, by extending the AbstractAlfrescoIT it works fine but It's possible to run unit tests without having the app running.
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.