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

Adding Spring StaticApplicationContext #21

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

omidp
Copy link

@omidp omidp commented Feb 11, 2013

It is a common way that developers programmatically register beans into context specially in testing rather than reading bean definitions from external configuration sources, in this case, you need to use StaticApplicationContext.

I added it to arquillian. please see StaticSpringContext

@omidp
Copy link
Author

omidp commented Feb 11, 2013

The only problem with this approach is sharing the created instance in test class which we can use an annotation to do so e.g

@springcontext
StaticApplicationContext ctx; //created by Arquillian and inject in test class

WDYT ?

@jmnarloch
Copy link
Member

Hi,

Thanks for the pull request! :)
I went quickly through the code and could you please tell what would be the difference between using SpringAnnotationConfiguration and providing to it the packages to scan (their work not only for @configuration, but for all Spring stereotype annotated classes) ?

Also, I think that I don't understand entirely the idea of injecting the
@springcontext
StaticApplicationContext ctx;

into the test class. How could it be used afterwards?

BTW. would you mind creating a JIRA issue for this functionality. https://issues.jboss.org/browse/ARQ/component/12313437

@jmnarloch
Copy link
Member

Also, please take a look at https://github.com/jmnarloch/arquillian-extension-guice/blob/master/int-tests/src/test/java/org/jboss/arquillian/extension/guice/testsuite/CustomInjectorTestCase.java

That's the Guice enricher. I added there custom @GuiceInjector which allows to "grab" the application context directly from the test. Maybe that's the direction we could also aproach with spring extension?

@jmnarloch
Copy link
Member

As goes for other ideas: http://blog.springsource.com/2011/06/21/spring-3-1-m2-testing-with-configuration-classes-and-profiles/

Spring Test has nice capabilities, that were not yet implemented in Arquillian extension. I would especially favor having inner static class annoated with @configuration, that could be used by the extension for configuring the application context. That would be really neat to have.

@omidp
Copy link
Author

omidp commented Feb 18, 2013

I've created a JIRA issue and explained it there.

https://issues.jboss.org/browse/ARQ-1303

@omidp
Copy link
Author

omidp commented Feb 18, 2013

What is SpringAnnotationConfiguration and where is it? I wasn't aware there is such a thing
I haven't used Guice so I have no idea about your second comment

@jmnarloch
Copy link
Member

The @SpringAnnotationConfiguration from arquillian-service-integration-spring-javaconfig is used for configuring the AnnotationConfigApplicationContext by providing the classes to scan or optional packages. The only drawback is that it requires Spring 3.x in order to be used.

@jmnarloch
Copy link
Member

Hi again,

Let's continue the hight level discusion in JIRA and here let's discuss only the details.

I'm wondering how can be injected @springcontext StaticApplicationContext used afterwads?

@omidp
Copy link
Author

omidp commented Feb 21, 2013

Hi,

I found it useful to have spring context in your test for some occasions. it's like your test is ApplicationContextAware. for example :

  • For publishing events
 ctx.publishEvent(event)
  • for checking what beans has been autowired
  • for working with different environment ctx.getEnvironment()
    and maybe other situation that I don't know besides I've checked SpringAnnotationConfiguration, I wasn't aware of it. It's pretty useful and currently meets all my need for testing. maybe there is no need to have staticapplicationcontext.

@jmnarloch
Copy link
Member

But you know that this works, out of the box in Spring? You just @autowire the ApplicationContext. There is no need for special annotation that would inject it.

https://jira.springsource.org/browse/SPR-5101

@jmnarloch
Copy link
Member

There is a test example in integrations tests: https://github.com/arquillian/arquillian-extension-spring/blob/master/arquillian-service-integration-spring-3-int-tests/src/test/java/org/jboss/arquillian/spring/testsuite/test/ApplicationContextTestCase.java

I have nothing against having the StaticApplicationContext as one of the implementations, altughout would mind having the annotations made consistent with the existing ones? I were thinking about one single annotation something like:

@interface SpringStaticConfiguration {

Class<?>[] classes();
String[] packages();
}

You can choice different name if you like.

@omidp
Copy link
Author

omidp commented Feb 23, 2013

that's fine with me. I totally agree. thanks for your help

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

Successfully merging this pull request may close these issues.

2 participants