diff --git a/src/test/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePluginTest.java b/src/test/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePluginTest.java new file mode 100644 index 0000000..d7f2934 --- /dev/null +++ b/src/test/java/com/itfsw/mybatis/generator/plugins/LogicalDeletePluginTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2017. + * + * 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.itfsw.mybatis.generator.plugins; + +import com.itfsw.mybatis.generator.plugins.tools.DBHelper; +import com.itfsw.mybatis.generator.plugins.tools.MyBatisGeneratorTool; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mybatis.generator.exception.InvalidConfigurationException; +import org.mybatis.generator.exception.XMLParserException; + +import java.io.IOException; +import java.sql.SQLException; + +/** + * --------------------------------------------------------------------------- + * + * --------------------------------------------------------------------------- + * @author: hewei + * @time:2017/7/7 16:59 + * --------------------------------------------------------------------------- + */ +public class LogicalDeletePluginTest { + /** + * 初始化数据库 + */ + @BeforeClass + public static void init() throws SQLException, IOException, ClassNotFoundException { + DBHelper.createDB("scripts/LogicalDeletePlugin/init.sql"); + } + + /** + * 测试配置异常 + */ + @Test + public void testWarnings() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException { + MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LogicalDeletePlugin/mybatis-generator-with-unsupport-type.xml"); + tool.generate(); + + Assert.assertEquals(tool.getWarnings().get(0), "itfsw(逻辑删除插件):tb逻辑删除列(ts_2)的类型不在支持范围(请使用数字列,字符串列,布尔列)!"); + } +} diff --git a/src/test/resources/scripts/LogicalDeletePlugin/init.sql b/src/test/resources/scripts/LogicalDeletePlugin/init.sql new file mode 100644 index 0000000..91bf58a --- /dev/null +++ b/src/test/resources/scripts/LogicalDeletePlugin/init.sql @@ -0,0 +1,37 @@ +/* +Navicat MySQL Data Transfer + +Source Server : localhost +Source Server Version : 50617 +Source Host : localhost:3306 +Source Database : mybatis-generator-plugin + +Target Server Type : MYSQL +Target Server Version : 50617 +File Encoding : 65001 + +Date: 2017-07-10 17:09:38 +*/ + +SET FOREIGN_KEY_CHECKS=0; + +-- ---------------------------- +-- Table structure for tb +-- ---------------------------- +DROP TABLE IF EXISTS `tb`; +CREATE TABLE `tb` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1', + `del_flag` smallint(1) NOT NULL DEFAULT '0', + `ts_1` tinyint(1) DEFAULT NULL, + `ts_2` binary(255) DEFAULT NULL, + `ts_3` float DEFAULT NULL, + `ts_4` varchar(10) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8; + +-- ---------------------------- +-- Records of tb +-- ---------------------------- +INSERT INTO `tb` VALUES ('1', '0', null, 0x300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, null, null); +INSERT INTO `tb` VALUES ('2', '0', null, 0x300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, null, null); +INSERT INTO `tb` VALUES ('3', '1', null, 0x300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, null, null); diff --git a/src/test/resources/scripts/LogicalDeletePlugin/mybatis-generator-with-unsupport-type.xml b/src/test/resources/scripts/LogicalDeletePlugin/mybatis-generator-with-unsupport-type.xml new file mode 100644 index 0000000..783669d --- /dev/null +++ b/src/test/resources/scripts/LogicalDeletePlugin/mybatis-generator-with-unsupport-type.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
\ No newline at end of file