Ok, I come from Rails am having a bit of a hard time trying to get this working.
Right know this is what I understand from the Spring framework (and please correct me if I'm wrong):
I am using Tomcat. So what it does, basically, is go after web.xml, and check any configuration files from there in order to initialize and get beans auto wired, etc.
In my example, I have on web.xml the context config location as application-config.xml
It turns out that application-config.xml has other config files that will take care of the following:
Hibernate:
<util:properties id="hibernatePropertiesConfigurer" location="classpath:hibernate.properties"/>
JSon Converter:
<import resource="classpath:json-converter.xml"/>
Managers (@Component
) Scanner:
<import resource="classpath:scanner-config.xml"/>
Among others. In other words, these work just fine, web server gets up, managers (@Components
) are @Autowired
, @Controllers
can call them, persist objects in the database, etc.
Now, I want to test, i.e. run JUnit tests. I did find a lot of examples on how to mock these layers (managers, controllers) but I want to try the real thing:
- Test will instantiate
@Controller
- Test will post to
@Controller
object @Controller
will have a real@Autowired
(not mocked version) of@Component
or@Bean
@Component
will persist an@Entity
- And, most important of all, database should see the changes. (I am using MySQL)
- Test will, then, use an
@Autowired
instance of@Component
, and query the database to confirm the persistence occurred.
Is this possible, at all, with Spring, JUnit testing?