-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89530e6
commit 452142c
Showing
7 changed files
with
4,602 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
iam-login-service/src/test/java/it/infn/mw/iam/test/db_upgrade/UpgradeDbTestSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package it.infn.mw.iam.test.db_upgrade; | ||
|
||
import static it.infn.mw.iam.test.api.account.search.service.DefaultPagedAccountsServiceTests.TOTAL_TEST_ACCOUNTS; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.io.IOException; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import it.infn.mw.iam.persistence.repository.IamAccountRepository; | ||
|
||
public abstract class UpgradeDbTestSupport { | ||
|
||
public static final String INITDB_DIR = "/docker-entrypoint-initdb.d"; | ||
public static final String DB_DUMPS_DIR = "db-dumps"; | ||
|
||
public static String joinPathStrings(String first, String second) { | ||
return String.format("%s/%s", first, second); | ||
} | ||
|
||
@Autowired | ||
IamAccountRepository accountRepo; | ||
|
||
@Test | ||
public void dbUpgradeSucceeds() throws IOException { | ||
assertThat(accountRepo.count(), is(TOTAL_TEST_ACCOUNTS)); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
iam-login-service/src/test/java/it/infn/mw/iam/test/db_upgrade/Upgradev1_7_0DbTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package it.infn.mw.iam.test.db_upgrade; | ||
|
||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import it.infn.mw.iam.test.util.db.MySQL57TestContainer; | ||
|
||
@Testcontainers | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@Transactional | ||
@ActiveProfiles({"mysql-test", "flyway-repair"}) | ||
@DirtiesContext | ||
public class Upgradev1_7_0DbTests extends UpgradeDbTestSupport { | ||
|
||
public static final String DB_DUMP = "iam-v1.7.0-mysql5.7.sql"; | ||
|
||
@Container | ||
static MySQL57TestContainer db = | ||
new MySQL57TestContainer().withClasspathResourceMapping( | ||
joinPathStrings(DB_DUMPS_DIR, DB_DUMP), joinPathStrings(INITDB_DIR, DB_DUMP), | ||
BindMode.READ_ONLY); | ||
|
||
|
||
@DynamicPropertySource | ||
static void registerMysqlConnectionString(DynamicPropertyRegistry registry) { | ||
registry.add("spring.datasource.url", db::getJdbcUrl); | ||
} | ||
|
||
|
||
} |
37 changes: 37 additions & 0 deletions
37
iam-login-service/src/test/java/it/infn/mw/iam/test/db_upgrade/Upgradev1_7_2DbTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package it.infn.mw.iam.test.db_upgrade; | ||
|
||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
|
||
import it.infn.mw.iam.test.util.db.MySQL57TestContainer; | ||
|
||
@Testcontainers | ||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
@Transactional | ||
@ActiveProfiles({"mysql-test", "flyway-repair"}) | ||
@DirtiesContext | ||
public class Upgradev1_7_2DbTests extends UpgradeDbTestSupport { | ||
|
||
public static final String DB_DUMP = "iam-v1.7.2-mysql5.7.sql"; | ||
|
||
@Container | ||
static MySQL57TestContainer db = | ||
new MySQL57TestContainer().withClasspathResourceMapping( | ||
joinPathStrings(DB_DUMPS_DIR, DB_DUMP), joinPathStrings(INITDB_DIR, DB_DUMP), | ||
BindMode.READ_ONLY); | ||
|
||
@DynamicPropertySource | ||
static void registerMysqlConnectionString(DynamicPropertyRegistry registry) { | ||
registry.add("spring.datasource.url", db::getJdbcUrl); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
iam-login-service/src/test/java/it/infn/mw/iam/test/util/db/MySQL57TestContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package it.infn.mw.iam.test.util.db; | ||
|
||
import org.testcontainers.containers.MySQLContainer; | ||
|
||
public class MySQL57TestContainer extends MySQLContainer<MySQL57TestContainer> { | ||
|
||
public static final String DEFAULT_IMAGE = "mysql:5.7"; | ||
public static final String DEFAULT_DATABASE_NAME = "iam"; | ||
public static final String DEFAULT_USERNAME = "iam"; | ||
public static final String DEFAULT_PASSWORD = "pwd"; | ||
|
||
public MySQL57TestContainer() { | ||
super(DEFAULT_IMAGE); | ||
withDatabaseName(DEFAULT_DATABASE_NAME); | ||
withPassword(DEFAULT_PASSWORD); | ||
withUsername(DEFAULT_USERNAME); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Flyway Log | ||
logging.level.org.flywaydb=DEBUG |
Oops, something went wrong.