Так создается источник данных.
Код: Выделить всё
@Configuration
@Import(RewardsConfig.class)
public class TestInfrastructureConfig {
/**
* Creates an in-memory "rewards" database populated
* with test data for fast testing
*/
@Bean
public DataSource dataSource() {
return (new EmbeddedDatabaseBuilder()) //
.addScript("classpath:rewards/testdb/schema.sql") //
.addScript("classpath:rewards/testdb/data.sql") //
.build();
}
}
Код: Выделить всё
class RewardNetworkTests {
private RewardNetwork rewardNetwork;
@BeforeEach
void setUp() throws Exception {
ApplicationContext cxt = SpringApplication.run(TestInfrastructureConfig.class);
this.rewardNetwork = cxt.getBean(RewardNetwork.class);
}
@Test
void testRewardForDining() {
fail("Not yet implemented");
}
}
Код: Выделить всё
Caused by: java.io.FileNotFoundException: class path resource [rewards/testdb/schema.sql] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:199) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.core.io.support.EncodedResource.getReader(EncodedResource.java:146) ~[spring-core-5.3.23.jar:5.3.23]
at org.springframework.jdbc.datasource.init.ScriptUtils.readScript(ScriptUtils.java:328) ~[spring-jdbc-5.3.23.jar:5.3.23]
at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:236) ~[spring-jdbc-5.3.23.jar:5.3.23]
... 122 common frames omitted
Подробнее здесь: https://stackoverflow.com/questions/793 ... nother-lab
Мобильная версия