From 82d6d4b8354487a050a61574ebf9a3f1c74d2123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Wed, 5 Jul 2023 16:29:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20junit=20=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatis-flex-native-test/pom.xml | 18 +++-- .../com/mybatisflex/test/AccountTester.java | 79 +++++++++++++++++++ 2 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java diff --git a/mybatis-flex-test/mybatis-flex-native-test/pom.xml b/mybatis-flex-test/mybatis-flex-native-test/pom.xml index 4dc4b4ed..53af5b95 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/pom.xml +++ b/mybatis-flex-test/mybatis-flex-native-test/pom.xml @@ -102,11 +102,13 @@ test - - junit - junit - test - + + + + + + + org.assertj assertj-core @@ -119,6 +121,12 @@ 1.2.18 compile + + junit + junit + + + diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java new file mode 100644 index 00000000..86a04d54 --- /dev/null +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/AccountTester.java @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mybatisflex.test; + +import com.mybatisflex.core.MybatisFlexBootstrap; +import com.mybatisflex.core.audit.AuditManager; +import com.mybatisflex.core.audit.ConsoleMessageCollector; +import com.mybatisflex.core.audit.MessageCollector; +import com.mybatisflex.core.query.If; +import com.mybatisflex.core.query.QueryWrapper; +import org.junit.BeforeClass; +import org.junit.Test; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; + +import javax.sql.DataSource; +import java.util.List; + + +public class AccountTester { + + static AccountMapper accountMapper; + + @BeforeClass + public static void init() { + DataSource dataSource = new EmbeddedDatabaseBuilder() + .setType(EmbeddedDatabaseType.H2) + .addScript("schema.sql") + .addScript("data.sql") + .build(); + + MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance() + .setDataSource(dataSource) + .addMapper(AccountMapper.class) + .start(); + + //开启审计功能 + AuditManager.setAuditEnable(true); + + //设置 SQL 审计收集器 + MessageCollector collector = new ConsoleMessageCollector(); + AuditManager.setMessageCollector(collector); + + + accountMapper = bootstrap.getMapper(AccountMapper.class); + } + + + @Test + public void testLambda() { + QueryWrapper queryWrapper = QueryWrapper.create(); + queryWrapper.where(Account::getId).ge(100) + .and(Account::getUserName).like("michael") + .or(Account::getUserName).like(null, If::notNull); + System.out.println(queryWrapper.toSQL()); + } + + + @Test + public void testSelectAsToDTO() { + List accountDTOS = accountMapper.selectListByQueryAs(QueryWrapper.create(), AccountDTO.class); + System.out.println(accountDTOS); + } + + +}