I have a SpringBootApplicationWhich I wish to test.
Below are the details about my files
application.properties
PRODUCT_DATABASE_PASSWORD=
PRODUCT_DATABASE_USERNAME=sa
PRODUCT_DATABASE_CONNECTION_URL=jdbc:h2:file:./target/db/testdb
PRODUCT_DATABASE_DRIVER=org.h2.Driver
RED_SHIFT_DATABASE_PASSWORD=
RED_SHIFT_DATABASE_USERNAME=sa
RED_SHIFT_DATABASE_CONNECTION_URL=jdbc:h2:file:./target/db/testdb
RED_SHIFT_DATABASE_DRIVER=org.h2.Driver
spring.datasource.platform=h2
ConfigurationClass
@SpringBootConfiguration
@SpringBootApplication
@Import({ProductDataAccessConfig.class, RedShiftDataAccessConfig.class})
public class TestConfig {
}
Main Test Class
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {TestConfig.class,ConfigFileApplicationContextInitializer.class}, webEnvironment = SpringBootTest.WebEnvironment.NONE)
public class MainTest {
@Autowired(required = true)
@Qualifier("dataSourceRedShift")
private DataSource dataSource;
@Test
public void testHourlyBlock() throws Exception {
insertDataIntoDb(); //data sucessfully inserted
SpringApplication.run(Application.class, new String[]{}); //No data found
}
}
Data Access In Application.class;
try (Connection conn = dataSourceRedShift.getConnection();
Statement stmt = conn.createStatement() {
//access inserted data
}
Please Help! PS for the spring boot application the test beans are being picked so bean instantiation definitely not a problem. I think I am missing some properties.
I do not use hibernate in my application and data goes off even within the same application context (child context). i.e. I run a spring boot application which reads that data inserted earlier
-
In the test, by default the changes will rollback, do you disable the transaction rollback?Liping Huang– Liping Huang2016年09月22日 00:40:03 +00:00Commented Sep 22, 2016 at 0:40
-
I am not using any transaction manager. Is it configured by default? I did try connection.commit after each query didn't help!user1615664– user16156642016年09月22日 00:46:59 +00:00Commented Sep 22, 2016 at 0:46
-
You can refer to thie docsLiping Huang– Liping Huang2016年09月22日 00:53:38 +00:00Commented Sep 22, 2016 at 0:53
-
I do not use hibernate in my application and data goes off even within the same application context (child context). i.e. I run a spring boot application which reads that data inserted earlier. Should I still implement transaction manager?user1615664– user16156642016年09月22日 00:58:38 +00:00Commented Sep 22, 2016 at 0:58
-
So you need add all those info in your question.Liping Huang– Liping Huang2016年09月22日 01:01:36 +00:00Commented Sep 22, 2016 at 1:01
1 Answer 1
Problem solved. removing spring.datasource.platform=h2 from the application.properties. Made my h2 data persists. But I still wish to know how is h2 starting automatically?