diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml b/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml index 18cff34c..6b4682cc 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/pom.xml @@ -83,6 +83,18 @@ test + + org.testcontainers + testcontainers + test + + + com.fasterxml.jackson.core + jackson-annotations + + + + diff --git a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/QueryChainTest.java b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/QueryChainTest.java index 2e3f6e46..631d3112 100644 --- a/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/QueryChainTest.java +++ b/mybatis-flex-test/mybatis-flex-spring-boot-test/src/test/java/com/mybatisflex/test/mapper/QueryChainTest.java @@ -22,10 +22,18 @@ import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.test.model.Gender; import com.mybatisflex.test.model.User; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.testcontainers.containers.BindMode; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.utility.DockerImageName; + +import java.util.Collections; import static com.mybatisflex.test.model.table.RoleTableDef.ROLE; import static com.mybatisflex.test.model.table.UserRoleTableDef.USER_ROLE; @@ -38,9 +46,28 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER; @SpringBootTest class QueryChainTest { + static final String TEST_DDL = QueryChainTest.class.getClassLoader().getResource("flex_test.sql").getPath(); + static GenericContainer mysql = new GenericContainer<>(DockerImageName.parse("mysql:8.2.0")) + .waitingFor(Wait.forLogMessage(".*ready for connections.*\\n", 1)) + // bind DDL to container /docker-entrypoint-initdb.d and it will execute automatically + .withFileSystemBind(TEST_DDL, "/docker-entrypoint-initdb.d/flex_test.sql", BindMode.READ_ONLY) + .withEnv("MYSQL_DATABASE", "flex_test") + .withEnv("MYSQL_ROOT_PASSWORD", "123456"); + @Autowired UserMapper userMapper; + @BeforeAll + public static void start() { + mysql.setPortBindings(Collections.singletonList("3306:3306")); + mysql.start(); + } + + @AfterAll + public static void stop() { + mysql.stop(); + } + @Test void testFields() { QueryBuilder builder = user -> diff --git a/pom.xml b/pom.xml index f1f9cf4b..d86684fd 100644 --- a/pom.xml +++ b/pom.xml @@ -71,6 +71,7 @@ 2.5.3 4.13.2 + 1.19.3 1.5.0 @@ -188,6 +189,14 @@ true + + org.testcontainers + testcontainers-bom + ${testcontainers.version} + pom + import + +