05-02-2018 10:33 AM
I have a simple working JUnit test:
@RunWith(SpringJUnit4ClassRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:alfresco/application-context.xml")
public class MySimpleTest {
@Test
public void contextLoad() {
}
}
But I need to add dependency to Records Management (I want to create custom action by creating bean extending from RMDispositionActionExecuterAbstractBase as child of rmProxyAction😞
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-rm-community-repo</artifactId>
<version>2.6.c</version>
<classifier>classes</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco-rm-community-repo</artifactId>
<version>2.6.c</version>
<classifier>config</classifier>
<scope>provided</scope>
</dependency>
It's working (as deployed AMP to Alfresco Content Services 5.2.2).
But my test not working after adding this dependencies. I'm getting error:
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:103)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:122)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:284)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Can't find bean 'simpleMappingExceptionResolver' to be extended.' is defined
at org.alfresco.util.BeanExtender.postProcessBeanFactory(BeanExtender.java:80)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:699)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:689)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:461)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:102)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:246)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:69)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:95)
... 26 more
How can I add Records Management dependencies and use JUnit tests?
05-16-2018 04:08 AM
Hi!
Extending RM isn't something I'm very familiar with (because I work directly on it), however a couple of things stand out to me. Firstly the exception message is bizarre - usually the NoSuchBeanDefinition will name a particular bean, but your error message looks like it's trying to add a bean called "Can't find bean 'simpleMappingExceptionResolver' to be extended." I've no idea how this could happen.
Secondly did you consider writing tests in the same style as our integration tests? (i.e. our tests in test/java rather than unit-test/java) We extend an abstract class BaseRMTestCase, which includes setting up the application context. More recently we have moved away from application context tests to focus on end-to-end REST API tests, but I know that doesn't always cover all cases.
If you have a minimal project that reproduces this issue then perhaps you could put it on GitHub and we could try it out? I'm not sure what the @Remote annotation is for - are you trying to run the tests against a server in a separate jvm rather than setting up the application context as part of the test?
08-04-2020 01:20 AM
Hi, I am facing same type issue in APS unit test, can you help?
https://hub.alfresco.com/t5/alfresco-process-services/javadelegate-unit-test/m-p/300548#M6686
Explore our Alfresco products with the links below. Use labels to filter content by product module.