diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryMultipleSqlFilesIntTest.java similarity index 79% rename from persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryIntegrationTest.java rename to persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryMultipleSqlFilesIntTest.java index 8ec1520495..f1f6e85d8c 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/boot/test/UserRepositoryMultipleSqlFilesIntTest.java @@ -4,6 +4,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.boot.domain.User; @@ -18,7 +19,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @DataJpaTest -public class UserRepositoryIntegrationTest { +@ActiveProfiles("multiplesqlfiles") +public class UserRepositoryMultipleSqlFilesIntTest { @Autowired private UserRepository userRepository; @@ -26,7 +28,7 @@ public class UserRepositoryIntegrationTest { public void givenTwoImportFilesWhenFindAllShouldReturnSixUsers() { Collection users = userRepository.findAll(); - assertThat(users.size()).isEqualTo(3); + assertThat(users.size()).isEqualTo(6); } } diff --git a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java index 597628c5d4..e9824fce44 100644 --- a/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence/src/test/java/com/baeldung/springbootdatasourceconfig/application/tests/UserRepositoryIntegrationTest.java @@ -25,6 +25,7 @@ public class UserRepositoryIntegrationTest { userRepository.save(new User("Bob", "bob@domain.com")); List users = (List) userRepository.findAll(); + // 2 additional users are saved in the CommandLineRunner bean assertThat(users.size()).isEqualTo(3); } } diff --git a/persistence-modules/spring-boot-persistence/src/test/resources/application-multiplesqlfiles.properties b/persistence-modules/spring-boot-persistence/src/test/resources/application-multiplesqlfiles.properties new file mode 100644 index 0000000000..06efc25f38 --- /dev/null +++ b/persistence-modules/spring-boot-persistence/src/test/resources/application-multiplesqlfiles.properties @@ -0,0 +1 @@ +spring.jpa.properties.hibernate.hbm2ddl.import_files=import_active_users.sql,import_inactive_users.sql \ No newline at end of file