增加CommentPlugin的测试用例
This commit is contained in:
@@ -51,7 +51,7 @@ public class CommentPluginTest {
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
DBHelper.createDB("scripts/ComentPlugin/init.sql");
|
||||
DBHelper.createDB("scripts/CommentPlugin/init.sql");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public class CommentPluginTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGenerateWithoutTemplate() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator-without-template.xml");
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator-without-template.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
// 是否在使用系统默认模板
|
||||
int count = 0;
|
||||
@@ -76,7 +76,7 @@ public class CommentPluginTest {
|
||||
*/
|
||||
@Test
|
||||
public void testGenerateWithTemplate() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ComentPlugin/mybatis-generator.xml");
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
|
||||
// java中的注释
|
||||
@@ -105,4 +105,31 @@ public class CommentPluginTest {
|
||||
String comment = ((TextElement) els.get(0)).getContent();
|
||||
Assert.assertEquals(comment, "addComment:BaseResultMap");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试配置了模板参数转换
|
||||
*/
|
||||
@Test
|
||||
public void testGenerateWithOutComment() throws Exception {
|
||||
MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator-without-comment.xml");
|
||||
MyBatisGenerator myBatisGenerator = tool.generate();
|
||||
|
||||
// java中的注释
|
||||
for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
|
||||
if (file.getFileName().equals("Tb.java")) {
|
||||
TopLevelClass topLevelClass = (TopLevelClass) file.getCompilationUnit();
|
||||
// addJavaFileComment
|
||||
Assert.assertEquals(topLevelClass.getFileCommentLines().size(), 0);
|
||||
// addFieldComment
|
||||
Field id = topLevelClass.getFields().get(0);
|
||||
Assert.assertEquals(id.getJavaDocLines().size(), 0);
|
||||
// addGeneralMethodComment
|
||||
Method cons = topLevelClass.getMethods().get(0);
|
||||
Assert.assertEquals(cons.getJavaDocLines().size(), 0);
|
||||
// addSetterComment
|
||||
Method setter = topLevelClass.getMethods().get(5);
|
||||
Assert.assertEquals(setter.getJavaDocLines().size(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2019.
|
||||
~
|
||||
~ 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.
|
||||
-->
|
||||
|
||||
<!DOCTYPE generatorConfiguration
|
||||
PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
|
||||
<generatorConfiguration>
|
||||
<properties resource="db.properties"/>
|
||||
|
||||
<!--导入属性配置 -->
|
||||
<context id="default" targetRuntime="MyBatis3">
|
||||
<!-- 插件 -->
|
||||
<!-- 注释插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.CommentPlugin"/>
|
||||
|
||||
<commentGenerator>
|
||||
<property name="suppressAllComments" value="true"/>
|
||||
</commentGenerator>
|
||||
<!--jdbc的数据库连接 -->
|
||||
<jdbcConnection driverClass="${driver}" connectionURL="${url}" userId="${username}" password="${password}" />
|
||||
<!-- Model模型生成器,用来生成含有主键key的类,记录类 以及查询Example类
|
||||
targetPackage 指定生成的model生成所在的包名
|
||||
targetProject 指定在该项目下所在的路径 -->
|
||||
<javaModelGenerator targetPackage="" targetProject="">
|
||||
<!-- 是否对model添加 构造函数 -->
|
||||
<property name="constructorBased" value="true"/>
|
||||
<!-- 给Model添加一个父类 -->
|
||||
<!--<property name="rootClass" value="com.itfsw.base"/>-->
|
||||
</javaModelGenerator>
|
||||
<!--Mapper映射文件生成所在的目录 为每一个数据库的表生成对应的SqlMap文件 -->
|
||||
<sqlMapGenerator targetPackage="" targetProject="" />
|
||||
<!-- 客户端代码,生成易于使用的针对Model对象和XML配置文件 的代码
|
||||
type="ANNOTATEDMAPPER",生成Java Model 和基于注解的Mapper对象
|
||||
type="MIXEDMAPPER",生成基于注解的Java Model 和相应的Mapper对象
|
||||
type="XMLMAPPER",生成SQLMap XML文件和独立的Mapper接口 -->
|
||||
<javaClientGenerator targetPackage="" targetProject="" type="XMLMAPPER"/>
|
||||
|
||||
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 要自动生成的表 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
|
||||
<table tableName="tb">
|
||||
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
|
||||
</table>
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<!-- 插件 -->
|
||||
<!-- 注释插件 -->
|
||||
<plugin type="com.itfsw.mybatis.generator.plugins.CommentPlugin">
|
||||
<property name="template" value="src/test/resources/scripts/ComentPlugin/test-comment.ftl"/>
|
||||
<property name="template" value="src/test/resources/scripts/CommentPlugin/test-comment.ftl"/>
|
||||
</plugin>
|
||||
|
||||
<commentGenerator>
|
||||
Reference in New Issue
Block a user