test: 移除 TestContainer 依赖。

This commit is contained in:
Suomm 2024-01-27 19:46:05 +08:00
parent 25682c1b1b
commit c55633172a
12 changed files with 27 additions and 77 deletions

View File

@ -83,24 +83,6 @@
<scope>test</scope> <scope>test</scope>
</dependency> </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>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mysql</artifactId>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,33 +0,0 @@
package com.mybatisflex.test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MySQLContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;
import java.util.Collections;
public class TestInfrastructure {
static final String FLEX_TEST_DDL = TestInfrastructure.class.getClassLoader().getResource("flex_test.sql").getPath();
static final String FIELD_MAPPING_TEST_DDL = TestInfrastructure.class.getClassLoader().getResource("field_mapping_test.sql").getPath();
static final String PATIENT_DATA_SPLIT_TEST_DDL = TestInfrastructure.class.getClassLoader().getResource("patient_data_split_test.sql").getPath();
static final String DOCKER_INITDB_PATH = "/docker-entrypoint-initdb.d/";
static GenericContainer<?> mysql = new MySQLContainer<>(DockerImageName.parse("mysql:8.2.0"))
.waitingFor(Wait.forLogMessage(".*ready for connections.*\\n", 1))
.withFileSystemBind(FLEX_TEST_DDL, DOCKER_INITDB_PATH + "flex_test.sql", BindMode.READ_ONLY)
.withFileSystemBind(FIELD_MAPPING_TEST_DDL, DOCKER_INITDB_PATH + "field_mapping_test.sql", BindMode.READ_ONLY)
.withFileSystemBind(PATIENT_DATA_SPLIT_TEST_DDL, DOCKER_INITDB_PATH + "patient_data_split_test.sql", BindMode.READ_ONLY)
.withDatabaseName("flex_test")
.withReuse(true)
.withPassword("123456");
@BeforeAll
public static void start() {
mysql.setPortBindings(Collections.singletonList("3306:3306"));
mysql.start();
}
}

View File

@ -19,7 +19,6 @@ package com.mybatisflex.test.mapper;
import com.mybatisflex.core.logicdelete.LogicDeleteManager; import com.mybatisflex.core.logicdelete.LogicDeleteManager;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.Db;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.model.Account; import com.mybatisflex.test.model.Account;
import com.mybatisflex.test.model.AccountVO; import com.mybatisflex.test.model.AccountVO;
import com.mybatisflex.test.model.AccountVO2; import com.mybatisflex.test.model.AccountVO2;
@ -30,7 +29,9 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date; import java.util.Date;
import static com.mybatisflex.core.query.QueryMethods.*; import static com.mybatisflex.core.query.QueryMethods.column;
import static com.mybatisflex.core.query.QueryMethods.concat;
import static com.mybatisflex.core.query.QueryMethods.distinct;
import static com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT; import static com.mybatisflex.test.model.table.AccountTableDef.ACCOUNT;
import static com.mybatisflex.test.model.table.RoleTableDef.ROLE; import static com.mybatisflex.test.model.table.RoleTableDef.ROLE;
import static com.mybatisflex.test.model.table.UserRoleTableDef.USER_ROLE; import static com.mybatisflex.test.model.table.UserRoleTableDef.USER_ROLE;
@ -42,7 +43,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
*/ */
@SpringBootTest @SpringBootTest
@SuppressWarnings("all") @SuppressWarnings("all")
class AccountMapperTest extends TestInfrastructure { class AccountMapperTest {
@Autowired @Autowired
private AccountMapper accountMapper; private AccountMapper accountMapper;
@ -136,13 +137,13 @@ class AccountMapperTest extends TestInfrastructure {
Account account = new Account(); Account account = new Account();
account.setAge(10); account.setAge(10);
Assertions.assertThrows(Exception.class, () -> Assertions.assertThrows(Exception.class, () ->
LogicDeleteManager.execWithoutLogicDelete(()->accountMapper.updateByQuery(account, QueryWrapper.create()))); LogicDeleteManager.execWithoutLogicDelete(() -> accountMapper.updateByQuery(account, QueryWrapper.create())));
} }
@Test @Test
void testDeleteAll() { void testDeleteAll() {
Assertions.assertThrows(Exception.class, () -> Assertions.assertThrows(Exception.class, () ->
LogicDeleteManager.execWithoutLogicDelete(()-> accountMapper.deleteByQuery(QueryWrapper.create()))); LogicDeleteManager.execWithoutLogicDelete(() -> accountMapper.deleteByQuery(QueryWrapper.create())));
} }
@Test @Test

View File

@ -18,7 +18,6 @@ package com.mybatisflex.test.mapper;
import com.mybatisflex.core.mybatis.Mappers; import com.mybatisflex.core.mybatis.Mappers;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.model.Good; import com.mybatisflex.test.model.Good;
import com.mybatisflex.test.model.User; import com.mybatisflex.test.model.User;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -35,7 +34,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
* @since 2023-07-23 * @since 2023-07-23
*/ */
@SpringBootTest @SpringBootTest
class ActiveRecordTest extends TestInfrastructure { class ActiveRecordTest {
@Test @Test
void testMapper() { void testMapper() {
@ -125,11 +124,14 @@ class ActiveRecordTest extends TestInfrastructure {
@Test @Test
void testRelation() { void testRelation() {
User user1 = User.create().select(USER.ALL_COLUMNS, ROLE.ALL_COLUMNS) User user1 = User.create()
.as("u")
.select(USER.DEFAULT_COLUMNS, ROLE.DEFAULT_COLUMNS)
.leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID)) .leftJoin(USER_ROLE).as("ur").on(USER_ROLE.USER_ID.eq(USER.USER_ID))
.leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID)) .leftJoin(ROLE).as("r").on(USER_ROLE.ROLE_ID.eq(ROLE.ROLE_ID))
.where(USER.USER_ID.eq(2)) .where(USER.USER_ID.eq(2))
.list().get(0); .list()
.get(0);
User user2 = User.create() User user2 = User.create()
.where(USER.USER_ID.eq(2)) .where(USER.USER_ID.eq(2))

View File

@ -17,7 +17,6 @@
package com.mybatisflex.test.mapper; package com.mybatisflex.test.mapper;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.model.Account; import com.mybatisflex.test.model.Account;
import com.mybatisflex.test.model.Article; import com.mybatisflex.test.model.Article;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -27,7 +26,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.util.List; import java.util.List;
@SpringBootTest @SpringBootTest
public class CombinedMapperTest extends TestInfrastructure { public class CombinedMapperTest {
@Autowired @Autowired
private AccountMapper accountMapper; private AccountMapper accountMapper;

View File

@ -16,7 +16,6 @@
package com.mybatisflex.test.mapper; package com.mybatisflex.test.mapper;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.model.Account; import com.mybatisflex.test.model.Account;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -33,7 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
* @since 2023/4/24 19:37 * @since 2023/4/24 19:37
*/ */
@SpringBootTest @SpringBootTest
class MyAccountMapperTest extends TestInfrastructure { class MyAccountMapperTest {
@Autowired @Autowired
private MyAccountMapper mapper; private MyAccountMapper mapper;

View File

@ -17,7 +17,6 @@
package com.mybatisflex.test.mapper; package com.mybatisflex.test.mapper;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.entity.Outer; import com.mybatisflex.test.entity.Outer;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -32,7 +31,7 @@ import static com.mybatisflex.test.entity.table.OuterTableDef.OUTER;
* @since 2023-07-01 * @since 2023-07-01
*/ */
@SpringBootTest @SpringBootTest
class OuterMapperTest extends TestInfrastructure { class OuterMapperTest {
@Autowired @Autowired
private OuterMapper outerMapper; private OuterMapper outerMapper;

View File

@ -1,6 +1,5 @@
package com.mybatisflex.test.mapper; package com.mybatisflex.test.mapper;
import com.mybatisflex.test.TestInfrastructure;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -14,7 +13,7 @@ import javax.annotation.Resource;
*/ */
@SpringBootTest @SpringBootTest
@SuppressWarnings("all") @SuppressWarnings("all")
public class PatientMapperTest extends TestInfrastructure { public class PatientMapperTest {
@Resource @Resource
private PatientMapper patientMapper; private PatientMapper patientMapper;

View File

@ -20,7 +20,6 @@ import com.mybatisflex.core.field.QueryBuilder;
import com.mybatisflex.core.query.QueryChain; import com.mybatisflex.core.query.QueryChain;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.update.UpdateChain; import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.model.Gender; import com.mybatisflex.test.model.Gender;
import com.mybatisflex.test.model.User; import com.mybatisflex.test.model.User;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -37,7 +36,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
* @since 2023-08-08 * @since 2023-08-08
*/ */
@SpringBootTest @SpringBootTest
class QueryChainTest extends TestInfrastructure { class QueryChainTest {
@Autowired @Autowired
UserMapper userMapper; UserMapper userMapper;

View File

@ -18,8 +18,13 @@ package com.mybatisflex.test.mapper;
import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.TestInfrastructure; import com.mybatisflex.test.model.OrderInfo;
import com.mybatisflex.test.model.*; import com.mybatisflex.test.model.User;
import com.mybatisflex.test.model.UserInfo;
import com.mybatisflex.test.model.UserVO;
import com.mybatisflex.test.model.UserVO1;
import com.mybatisflex.test.model.UserVO2;
import com.mybatisflex.test.model.UserVO3;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -43,7 +48,7 @@ import static com.mybatisflex.test.model.table.UserTableDef.USER;
*/ */
@SpringBootTest @SpringBootTest
@SuppressWarnings("all") @SuppressWarnings("all")
class UserMapperTest extends TestInfrastructure { class UserMapperTest {
@Autowired @Autowired
private UserMapper userMapper; private UserMapper userMapper;

View File

@ -17,7 +17,6 @@
package com.mybatisflex.test.service; package com.mybatisflex.test.service;
import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.test.TestInfrastructure;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -29,7 +28,7 @@ import static com.mybatisflex.test.model.table.ArticleTableDef.ARTICLE;
* @since 2023-07-22 * @since 2023-07-22
*/ */
@SpringBootTest @SpringBootTest
class ArticleServiceTest extends TestInfrastructure { class ArticleServiceTest {
@Autowired @Autowired
ArticleService articleService; ArticleService articleService;

View File

@ -2,7 +2,6 @@ package com.mybatisflex.test.service;
import com.mybatisflex.test.mapper.FieldMappingInnerMapper; import com.mybatisflex.test.mapper.FieldMappingInnerMapper;
import com.mybatisflex.test.mapper.FieldMappingMapper; import com.mybatisflex.test.mapper.FieldMappingMapper;
import com.mybatisflex.test.TestInfrastructure;
import com.mybatisflex.test.model.FieldMapping; import com.mybatisflex.test.model.FieldMapping;
import com.mybatisflex.test.model.FieldMappingInner; import com.mybatisflex.test.model.FieldMappingInner;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -12,7 +11,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import java.util.Date; import java.util.Date;
@SpringBootTest @SpringBootTest
class FieldMappingTest extends TestInfrastructure { class FieldMappingTest {
@Autowired @Autowired
FieldMappingMapper fieldMappingMapper; FieldMappingMapper fieldMappingMapper;
@Autowired @Autowired