Created
March 1, 2012 23:27
-
-
Save bmchild/1953988 to your computer and use it in GitHub Desktop.
An example of using @configuration for testing spring repositories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bmchild.repository; | |
/*imports | |
*. | |
*. | |
*. | |
*/ | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration(loader=AnnotationConfigContextLoader.class) | |
public class MyRepositoryIntegrationTest { | |
@Configuration | |
@ImportResource("classpath:/test-context.xml") | |
static class ContextConfiguration { | |
/* | |
* MyOtherRepository has a custom impl | |
*/ | |
@Bean | |
public MyOtherCustomRepository myOtherCustomRepository() { | |
MyOtherCustomRepository repo = new MyOtherRepositoryImpl(); | |
return repo; | |
} | |
@Bean | |
public JpaRepositoryFactoryBean<MyRepository,MyEntity,Long> getMyRepositoryBean() { | |
JpaRepositoryFactoryBean<MyRepository,MyEntity,Long> rfb = new JpaRepositoryFactoryBean<MyRepository,MyEntity,Long>(); | |
rfb.setRepositoryInterface(MyRepository.class); | |
rfb.setTransactionManager("transactionManagerBeanName"); | |
return rfb; | |
} | |
@Bean | |
public JpaRepositoryFactoryBean<MyOtherRepository,MyOtherEntity,Long> getMyOtherRepositoryBean() { | |
JpaRepositoryFactoryBean<MyOtherRepository,MyOtherEntity,Long> rfb = | |
new JpaRepositoryFactoryBean<MyOtherRepository,MyOtherEntity,Long>(); | |
rfb.setRepositoryInterface(ManPowerProfileRepository.class); | |
rfb.setTransactionManager("transactionManagerBeanName"); | |
rfb.setCustomImplementation(myOtherCustomRepository()); | |
return rfb; | |
} | |
} | |
@Autowired | |
private MyRepository myRepository; | |
@Autowired | |
private MyOtherRepository myOtherRepository; | |
/*tests | |
*. | |
*. | |
*. | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment