New SpringConfigurationTest; the first @RunWith(SpringJUnit4ClassRunner)
@ContextConfiguration in Mifos X. More of it to come - stay tuned. Signed-off-by: Michael Vorburger <mike@vorburger.ch>
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
package org.mifosplatform.infrastructure.configuration.spring;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* This integration test ensure that the "production" Spring XML configuration
|
||||
* files (appContext.xml & Co.) are valid. It does not need any database for
|
||||
* that.
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = TestsWithoutDatabaseAndNoJobsConfiguration.class)
|
||||
public class SpringConfigurationTest {
|
||||
|
||||
/**
|
||||
* This tests if "Aal izz well" (i.e. if we can start-up with the [almost]
|
||||
* "production" Spring XML configuration) by doing nothing - it doesn't have
|
||||
* to, as the SpringJUnit4ClassRunner with this @ContextConfiguration will
|
||||
* automatically fail if e.g. there is any invalid Spring XML, an invalid
|
||||
* bean definition somewhere or anything like that.
|
||||
*
|
||||
* @see https://www.google.ch/search?q=Aal+izz+well
|
||||
*/
|
||||
@Test
|
||||
public void testSpringXMLConfiguration() {}
|
||||
}
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
package org.mifosplatform.infrastructure.configuration.spring;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.service.TenantDatabaseUpgradeService;
|
||||
import org.mifosplatform.infrastructure.jobs.service.JobRegisterService;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
/**
|
||||
* Spring @Configuration which does not require a running database. It also does
|
||||
* not load any job configuration (as they are in the DB), thus nor starts any
|
||||
* background jobs. For some integration tests, this may be perfectly sufficient
|
||||
* (and faster to run such tests).
|
||||
*/
|
||||
@Configuration
|
||||
// We do NOT want the testContext.xml here, but the real one!
|
||||
@ImportResource("classpath*:META-INF/spring/appContext.xml")
|
||||
public class TestsWithoutDatabaseAndNoJobsConfiguration {
|
||||
|
||||
/**
|
||||
* Override TenantDatabaseUpgradeService binding, because the real one has a @PostConstruct
|
||||
* upgradeAllTenants() which accesses the database on start-up.
|
||||
*/
|
||||
@Bean
|
||||
public TenantDatabaseUpgradeService tenantDatabaseUpgradeService() {
|
||||
return new TenantDatabaseUpgradeService(null) {
|
||||
|
||||
@Override
|
||||
public void upgradeAllTenants() {
|
||||
// NOOP
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Override JobRegisterService binding, because the real
|
||||
* JobRegisterServiceImpl has a @PostConstruct loadAllJobs() which accesses
|
||||
* the database on start-up.
|
||||
*/
|
||||
@Bean
|
||||
public JobRegisterService jobRegisterServiceImpl() {
|
||||
JobRegisterService mockJobRegisterService = Mockito.mock(JobRegisterService.class);
|
||||
return mockJobRegisterService;
|
||||
}
|
||||
|
||||
/**
|
||||
* DataSource with Mockito RETURNS_MOCKS black magic.
|
||||
*/
|
||||
@Bean
|
||||
public DataSource tenantDataSourceJndi() {
|
||||
DataSource mockDataSource = Mockito.mock(DataSource.class, Mockito.RETURNS_MOCKS);
|
||||
return mockDataSource;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user