I have a simple Springboot application which runs perfectly. My issue is that I made some tests which are running well on my computer but not on Jenkins.
The reason is that I have 2 datasources protected by a firewall. A little "mvn clean install" on my computer works because its IP is trusted whereas Jenkins' one is not and cannot be.
My tests don't need the datasources (everything is mocked) but when the application context is loaded, it fails because of a database connection timeout (->firewall)
How can I skip the database part when tests are executed ? I tried with Profiles without success...
Thanks in advance for your responses ;-)
Here are main classes of my application
MyApp.java
@SpringBootApplication
@ComponentScan
@EnableAutoConfiguration(exclude={JpaRepositoriesAutoConfiguration.class,
DataSourceAutoConfiguration.class})
@PropertySources({
@PropertySource(MyApp.CLASSPATH_APPLICATION_PROPERTIES)
})
public class MyApp extends SpringBootServletInitializer {
public static final String CLASSPATH_APPLICATION_PROPERTIES = "http://classpath:/application-${spring.profiles.active}.properties";
....
}
FirstDataSourceConfig.java (there is a second class for the other datasource)
@Configuration
@Profile("prod")
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "dbFirstEntityManager",
transactionManagerRef = "dbFirstTransactionManager",
basePackages = {"my.package.for.dao"})
public class FirstDataSourceConfig {
// Definition of LocalContainerEntityManagerFactoryBean, DataSource and Transaction manager
}
AbstractTest.java
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {MyApp.class})
@ActiveProfiles("dev")
public class AbstractTest {
protected Logger LOGGER = Logger.getLogger(this.getClass());
}
AbstractControllerTest.java
@WebAppConfiguration
public class AbstractControllerTest extends AbstractTest {
protected MockMvc mvc;
@Autowired
protected WebApplicationContext webApplicationContext;
protected void setUp() {
mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
....
}
Aucun commentaire:
Enregistrer un commentaire