diff --git a/mifosng-provider/build.gradle b/mifosng-provider/build.gradle index 4ae27257d..38520c3e8 100644 --- a/mifosng-provider/build.gradle +++ b/mifosng-provider/build.gradle @@ -228,6 +228,9 @@ tomcatRunWar { configFile = file('src/test/resources/META-INF/context.xml') } +/* http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle */ +sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDir +sourceSets.test.output.resourcesDir = sourceSets.test.output.classesDir sourceSets { integrationTest { diff --git a/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml b/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml index c50d4294f..292572b3d 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/appContext.xml @@ -63,6 +63,11 @@ + + diff --git a/mifosng-provider/src/main/resources/META-INF/spring/infrastructure.xml b/mifosng-provider/src/main/resources/META-INF/spring/infrastructure.xml index 6f4efe943..95f28318d 100644 --- a/mifosng-provider/src/main/resources/META-INF/spring/infrastructure.xml +++ b/mifosng-provider/src/main/resources/META-INF/spring/infrastructure.xml @@ -40,6 +40,4 @@ - \ No newline at end of file diff --git a/mifosng-provider/src/main/resources/META-INF/spring/jndi.xml b/mifosng-provider/src/main/resources/META-INF/spring/jndi.xml new file mode 100644 index 000000000..43411f1e1 --- /dev/null +++ b/mifosng-provider/src/main/resources/META-INF/spring/jndi.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/mifosng-provider/src/main/webapp/WEB-INF/web.xml b/mifosng-provider/src/main/webapp/WEB-INF/web.xml index 7aa76807e..e1400fde7 100644 --- a/mifosng-provider/src/main/webapp/WEB-INF/web.xml +++ b/mifosng-provider/src/main/webapp/WEB-INF/web.xml @@ -18,7 +18,7 @@ contextConfigLocation - classpath*:META-INF/spring/appContext.xml + classpath*:META-INF/spring/jndi.xml classpath*:META-INF/spring/appContext.xml @@ -36,7 +36,7 @@ - jersey-serlvet + jersey-servlet com.sun.jersey.spi.spring.container.servlet.SpringServlet com.sun.jersey.api.json.POJOMappingFeature @@ -54,7 +54,7 @@ - jersey-serlvet + jersey-servlet /api/v1/* \ No newline at end of file diff --git a/mifosng-provider/src/test/java/org/mifosplatform/infrastructure/configuration/spring/SpringConfigurationTest.java b/mifosng-provider/src/test/java/org/mifosplatform/infrastructure/configuration/spring/SpringConfigurationTest.java new file mode 100644 index 000000000..533445646 --- /dev/null +++ b/mifosng-provider/src/test/java/org/mifosplatform/infrastructure/configuration/spring/SpringConfigurationTest.java @@ -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() {} +} diff --git a/mifosng-provider/src/test/java/org/mifosplatform/infrastructure/configuration/spring/TestsWithoutDatabaseAndNoJobsConfiguration.java b/mifosng-provider/src/test/java/org/mifosplatform/infrastructure/configuration/spring/TestsWithoutDatabaseAndNoJobsConfiguration.java new file mode 100644 index 000000000..4e361ad8c --- /dev/null +++ b/mifosng-provider/src/test/java/org/mifosplatform/infrastructure/configuration/spring/TestsWithoutDatabaseAndNoJobsConfiguration.java @@ -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; + } +} \ No newline at end of file