mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
Testcontainers with QueryChainTest
This commit is contained in:
parent
236c136497
commit
b71c6587d8
@ -83,6 +83,18 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -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<User> builder = user ->
|
||||
|
||||
9
pom.xml
9
pom.xml
@ -71,6 +71,7 @@
|
||||
<solon.version>2.5.3</solon.version>
|
||||
|
||||
<junit.version>4.13.2</junit.version>
|
||||
<testcontainers.version>1.19.3</testcontainers.version>
|
||||
<maven-flatten.version>1.5.0</maven-flatten.version>
|
||||
</properties>
|
||||
|
||||
@ -188,6 +189,14 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers-bom</artifactId>
|
||||
<version>${testcontainers.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user