Created
February 11, 2016 12:17
-
-
Save davengeo/dc3f835ed14a8cc4ebcd to your computer and use it in GitHub Desktop.
useful IT test to list the beans
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
@RunWith(SpringJUnit4ClassRunner.class) | |
@SpringApplicationConfiguration(classes = { | |
Application.class, | |
TrivialIT.PostConfiguration.class | |
}) | |
@WebAppConfiguration | |
@IntegrationTest("server.port=0") | |
@ActiveProfiles({"default", "test"}) | |
@ConfigurationProperties("application.yml") | |
public class TrivialIT { | |
Logger LOG = LoggerFactory.getLogger(TrivialIT.class); | |
@Autowired | |
ApplicationContext context; | |
@Test | |
public void should_load_all_the_beans() throws Exception { | |
LOG.info("\n\n"); | |
LOG.info("Beans report ****************************************"); | |
for (String beanName : context.getBeanDefinitionNames()) { | |
LOG.info("Bean: {} -> {}", beanName, context.getBean(beanName).getClass().getName()); | |
}; | |
LOG.info("\n\n"); | |
LOG.info("Profiles report ************************************"); | |
for (String profile : context.getEnvironment().getActiveProfiles()) { | |
LOG.info("Profile: {}", profile); | |
} | |
LOG.info("\n\n"); | |
} | |
@Configuration | |
@Import({ | |
JmsAutoConfiguration.class, | |
ActiveMQAutoConfiguration.class | |
}) | |
public static class PostConfiguration { | |
@Bean | |
RestTemplate restTemplate() { | |
return new RestTemplate(); | |
} | |
@Bean(name = "connectionFactory") | |
UserCredentialsConnectionFactoryAdapter userCredentialsConnectionFactoryAdapter(ActiveMQConnectionFactory jmsConnectionFactory) throws NamingException { | |
UserCredentialsConnectionFactoryAdapter factoryAdapter = new UserCredentialsConnectionFactoryAdapter(); | |
factoryAdapter.setTargetConnectionFactory(jmsConnectionFactory); | |
return factoryAdapter; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment