Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test : spring context loaded several times #185

Closed
mindthegab opened this issue Jul 20, 2014 · 6 comments
Closed

Unit test : spring context loaded several times #185

mindthegab opened this issue Jul 20, 2014 · 6 comments

Comments

@mindthegab
Copy link
Contributor

From alexis.t...@gmail.com on May 22, 2014 04:44:16

There a 2 ways to write test in alfresco :

-Extending BaseWebScriptTest when you need to test webscript. In this case, BaseWebscriptTest call TestWebScriptRepoServer.getTestServer(). This method use ApplicationContextHelper to load the context.

  • Using Spring annotation on the class:
    @RunWith(RemoteTestRunner.class)
    @Remote(runnerClass = SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:alfresco/application-context.xml")
    Context is loaded by spring, spring will not call ApplicationContextHelper to load the context.

Result : In a project, when you have both type of tests, context is loaded several times.

To fix, the issue, i wrote a customer loader (see attached file).

@ContextConfiguration(loader = AlfrescoContextLoader.class)
public class MyTestCase {

Attachment: AlfrescoContextLoader.java

Original issue: http://code.google.com/p/maven-alfresco-archetypes/issues/detail?id=185

@mindthegab
Copy link
Contributor Author

From alexis.t...@gmail.com on May 22, 2014 01:50:03

Another point, i think webscript test should also use annotation :
@RunWith(RemoteTestRunner.class)
@Remote(runnerClass = SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AlfrescoContextLoader.class)

The benefits is to @Autowired bean needed to setup the test data, and this will execute test in remote runner mode.

@mindthegab
Copy link
Contributor Author

From colum...@gmail.com on June 10, 2014 05:47:25

Labels: Milestone-Release-sdk-2.0.0

@mindthegab
Copy link
Contributor Author

From colum...@gmail.com on June 10, 2014 05:47:57

Hey Alexis,

would you be interested in committing this patch and testing it?

I can give you commit access relatively easily.

@mindthegab
Copy link
Contributor Author

From alexis.t...@gmail.com on June 14, 2014 12:37:02

Hi gabriele,
For sure, i can commit a patch. But i think there is another issue related to this one : jrebel rad devellopment. When you want to use jrebel with the sdk for unit testing, you first start alfresco with mvn -Pamp-to-war,rad. This will load the alfresco standard context, but without spring alfresco/web-scripts-application-context-test.xml. Webscript test don't work in this case.

In my opinion, i think we should let unit test start the context in RemoteServer. I made some test : you first have to start the RemoteServer main method with a correct classpath, then you launch test class. Test class will connect to RemoteServer, and start, first time, the unit test context. For now, i start the RemoteServer with netbeans, but it should be possible to start this with maven exec plugin or someting else.

Maybe you have another idea, or you already fix that ?

@mindthegab mindthegab modified the milestone: Release-sdk-2.0.0 Jul 20, 2014
@mindthegab mindthegab self-assigned this Jul 20, 2014
@mindthegab mindthegab assigned maoo and unassigned mindthegab Aug 1, 2014
@mindthegab
Copy link
Contributor Author

@maoo Can you review this one on JRebel?

@mindthegab mindthegab modified the milestones: 2.0.0-beta-1, 2.0.0 Aug 22, 2014
@mindthegab
Copy link
Contributor Author

Now the spring context is reloaded only once at the first remote testing invocation. So I think I can close this issue.

On another note, Spring contexts are not reloaded at all right now with the new Spring Loaded approach and we need to work (as part of issue #158) to get that sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants