org.mybatis.generator.api.GeneratedJavaFile Java Examples

The following examples show how to use org.mybatis.generator.api.GeneratedJavaFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntrospectedTableMyBatis3Impl.java    From mapper-generator-javafx with Apache License 2.0 6 votes vote down vote up
@Override
public List<GeneratedJavaFile> getGeneratedJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<>();

    for (AbstractJavaGenerator javaGenerator : javaGenerators) {
        List<CompilationUnit> compilationUnits = javaGenerator.getCompilationUnits();
        for (CompilationUnit compilationUnit : compilationUnits) {
            GeneratedJavaFile gjf = new GeneratedJavaFile(compilationUnit,
                            javaGenerator.getProject(),
                            context.getProperty(PropertyRegistry.CONTEXT_JAVA_FILE_ENCODING),
                            context.getJavaFormatter());
            answer.add(gjf);
        }
    }

    return answer;
}
 
Example #2
Source File: MapperAnnotationPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试默认配置
 */
@Test
public void testDefault() throws Exception{
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/MapperAnnotationPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof Interface && compilationUnit.getType().getShortName().endsWith("Mapper")) {
            Interface interfaze = (Interface) compilationUnit;

            Assert.assertEquals(interfaze.getAnnotations().size(), 1);
            Assert.assertEquals(interfaze.getAnnotations().get(0), "@Mapper");
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper")));
        }
    }
}
 
Example #3
Source File: MapperAnnotationPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试配置Repository
 * @throws Exception
 */
@Test
public void testWithRepository() throws Exception{
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/MapperAnnotationPlugin/mybatis-generator-with-repository.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof Interface && compilationUnit.getType().getShortName().endsWith("Mapper")) {
            Interface interfaze = (Interface) compilationUnit;

            Assert.assertEquals(interfaze.getAnnotations().size(), 2);
            Assert.assertEquals(interfaze.getAnnotations().get(0), "@Mapper");
            Assert.assertEquals(interfaze.getAnnotations().get(1), "@Repository");
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper")));
            Assert.assertTrue(interfaze.getImportedTypes().contains(new FullyQualifiedJavaType("org.springframework.stereotype.Repository")));
        }
    }
}
 
Example #4
Source File: BugFixedTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试domainObjectRenamingRule和
 */
@Test
public void bug0004() throws Exception {
    DBHelper.createDB("scripts/BugFixedTest/bug-0004.sql");
    // 规则 ^T 替换成空,也就是去掉前缀
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/bug-0004.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        String name = file.getCompilationUnit().getType().getShortName();
        if (!name.matches("B.*")) {
            Assert.assertTrue(false);
        }
        if (name.endsWith("Example")) {
            Assert.assertEquals(file.getCompilationUnit().getType().getPackageName(), "com.itfsw.dao.example");
        }
    }
}
 
Example #5
Source File: LombokPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试具体生成(只有keys的特殊情况,尽量使用Builder)
 */
@Test
public void testGenerateWithOnlyKeys() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LombokPlugin/mybatis-generator-with-only-keys.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof TopLevelClass) {
            TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
            String name = topLevelClass.getType().getShortName();
            if (name.equals("TbOnlyKeysKey")){
                Assert.assertTrue(topLevelClass.getAnnotations().contains("@Builder"));
            }
        }
    }
}
 
Example #6
Source File: CommentPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 测试配置了模板参数转换
 */
@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);
        }
    }
}
 
Example #7
Source File: DynamicSqlPluginTest.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateAdditionalFileEvenWhenTableHasNoColumns() throws Exception {
	// Given
	given(table.getAllColumns()).willReturn(new ArrayList<IntrospectedColumn>());

	// When
	List<GeneratedJavaFile> files = plugin.contextGenerateAdditionalJavaFiles(table);

	// Then
	then(files).hasSize(1);
}
 
Example #8
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin
                .contextGenerateAdditionalJavaFiles();
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example #9
Source File: PluginAggregator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
	List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
	for (Plugin plugin : plugins) {
		List<GeneratedJavaFile> temp = plugin.contextGenerateAdditionalJavaFiles(introspectedTable);
		if (temp != null) {
			answer.addAll(temp);
		}
	}
	return answer;
}
 
Example #10
Source File: PluginAggregator.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
	List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
	for (Plugin plugin : plugins) {
		List<GeneratedJavaFile> temp = plugin.contextGenerateAdditionalJavaFiles();
		if (temp != null) {
			answer.addAll(temp);
		}
	}
	return answer;
}
 
Example #11
Source File: Context.java    From mybatis-generator-plus with Apache License 2.0 5 votes vote down vote up
public void generateFiles(ProgressCallback callback, List<GeneratedJavaFile> generatedJavaFiles, List<GeneratedXmlFile> generatedXmlFiles, List<String> warnings) throws InterruptedException {

		pluginAggregator = new PluginAggregator();
		for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
			Plugin plugin = ObjectFactory.createPlugin(this, pluginConfiguration);
			if (plugin.validate(warnings)) {
				pluginAggregator.addPlugin(plugin);
			}
			else {
				warnings.add(getString("Warning.24", //$NON-NLS-1$
						pluginConfiguration.getConfigurationType(), id));
			}
		}

		if (introspectedTables != null) {
			for (IntrospectedTable introspectedTable : introspectedTables) {
				callback.checkCancel();

				introspectedTable.initialize();
				introspectedTable.calculateGenerators(warnings, callback);
				generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles());
				generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles());

				generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles(introspectedTable));
				generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles(introspectedTable));
			}
		}

		generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles());
		generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles());


		//每个表自定义包路径
		setJavaFilesCustomTargetPackage(generatedJavaFiles);
		setXmlFilesCustomTargetPackage(generatedJavaFiles);
	}
 
Example #12
Source File: CreateGenericInterfacePlugin.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
	List<GeneratedJavaFile> models = new ArrayList<>();

	GeneratedJavaFile genericInterfaceFile =
			new GeneratedJavaFile(genericInterface, context.getJavaClientGeneratorConfiguration().getTargetProject(), new DefaultJavaFormatter());

	models.add(genericInterfaceFile);

	return models;
}
 
Example #13
Source File: DynamicSqlPlugin.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
	List<GeneratedJavaFile> models = new ArrayList<>();

	CompilationUnit unit = DynamicSqlSupportClassGenerator
			.of(introspectedTable, context.getCommentGenerator(), tableClassSuffix, addAliasedColumns, addTableAlias, tableAliasFieldName, properties)
			.generate();

	GeneratedJavaFile dynamicSqlModel =
			new GeneratedJavaFile(unit, context.getJavaClientGeneratorConfiguration().getTargetProject(), new DefaultJavaFormatter());

	models.add(dynamicSqlModel);

	return models;
}
 
Example #14
Source File: CreateGenericInterfacePluginTest.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateAdditionalFile() throws Exception {
	// Given

	// When
	List<GeneratedJavaFile> files = plugin.contextGenerateAdditionalJavaFiles();

	// Then
	then(files).hasSize(1);
}
 
Example #15
Source File: DynamicSqlPluginTest.java    From mybatis-generator-plugins with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateAdditionalFile() throws Exception {
	// Given

	// When
	List<GeneratedJavaFile> files = plugin.contextGenerateAdditionalJavaFiles(table);

	// Then
	then(files).hasSize(1);
}
 
Example #16
Source File: BugFixedTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试批量batchUpsert存在主键的情况
 * https://github.com/itfsw/mybatis-generator-plugin/issues/77
 * @throws Exception
 */
@Test
public void issues81() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/BugFixedTest/issues-81.xml");
    MyBatisGenerator myBatisGenerator = tool.generate(() -> DBHelper.createDB("scripts/BugFixedTest/issues-81.sql"));

    // 是否在使用系统默认模板
    int count = 0;
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        if (file.getFormattedContent().indexOf(MergeConstants.NEW_ELEMENT_TAG) != -1) {
            count++;
        }
    }
    Assert.assertTrue(count == 0);
}
 
Example #17
Source File: TemplateFilePlugin.java    From Mapper with MIT License 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
    List<GeneratedJavaFile> list = new ArrayList<GeneratedJavaFile>();
    TableClass tableClass = TableColumnBuilder.build(introspectedTable);
    if ("TRUE".equalsIgnoreCase(singleMode)) {
        list.add(new GenerateByTemplateFile(tableClass, (TemplateFormatter) templateFormatter, properties, targetProject, targetPackage, fileName, templateContent));
    } else {
        cacheTables.add(tableClass);
    }
    return list;
}
 
Example #18
Source File: TemplateFilePlugin.java    From Mapper with MIT License 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
    List<GeneratedJavaFile> list = new ArrayList<GeneratedJavaFile>();
    if (cacheTables != null && cacheTables.size() > 0) {
        list.add(new GenerateByListTemplateFile(cacheTables, (ListTemplateFormatter) templateFormatter, properties, targetProject, targetPackage, fileName, templateContent));
    }
    return list;
}
 
Example #19
Source File: ControllerPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
		IntrospectedTable introspectedTable) {
	// 判断是否生成Controller文件
       String javaControllerName = 
			introspectedTable.getTableConfiguration().getProperty("generatedControllerName");
	if(javaControllerName == null || "".equals(javaControllerName.trim())){
		return null;
	}
	// Business 文件名
	String javaBusinessName = 
			introspectedTable.getTableConfiguration().getProperty("generatedBusinessName");
	return ControllerPluginUtil.getControllerJavaFile(context, introspectedTable, 
			controllerPackage, javaControllerName, businessPackage, javaBusinessName, exceptionClass);
}
 
Example #20
Source File: ControllerPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
		IntrospectedTable introspectedTable) {
	// 判断是否生成Controller文件
       String javaControllerName = 
			introspectedTable.getTableConfiguration().getProperty("generatedControllerName");
	if(javaControllerName == null || "".equals(javaControllerName.trim())){
		return null;
	}
	// Business 文件名
	String javaBusinessName = 
			introspectedTable.getTableConfiguration().getProperty("generatedBusinessName");
	return ControllerPluginUtil.getControllerJavaFile(context, introspectedTable, 
			controllerPackage, javaControllerName, businessPackage, javaBusinessName, exceptionClass);
}
 
Example #21
Source File: BusinessPlugin.java    From maven-archetype with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
		IntrospectedTable introspectedTable) {
	// 判断是否需要生成business文件
	String javaBusinessName = 
			introspectedTable.getTableConfiguration().getProperty("generatedBusinessName");
	// 不生成Business文件
	if(javaBusinessName == null || "".equals(javaBusinessName.trim())){
		return null;
	}
	
	return BusinessPluginUtil.getBusinessJavaFile(context, introspectedTable, 
			businessPackage, javaBusinessName);
}
 
Example #22
Source File: TableRenamePluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试具体生成
 */
@Test
public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException {
    // 规则1 ^T 替换成 Test, 同时tb2 使用了tableOverride 替换成 TestOverride
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TableRenamePlugin/mybatis-generator-rule1.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
        String name = file.getCompilationUnit().getType().getShortName();
        if (name.matches(".*1.*")){
            Assert.assertTrue(name.matches("Testb1.*"));
        } else {
            Assert.assertTrue(name.matches("TestOverride.*"));
        }
    }
}
 
Example #23
Source File: PluginAggregator.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles() {
    List<GeneratedJavaFile> answer = new ArrayList<>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin.contextGenerateAdditionalJavaFiles();
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}
 
Example #24
Source File: Context.java    From mapper-generator-javafx with Apache License 2.0 5 votes vote down vote up
public void generateFiles(ProgressCallback callback,
        List<GeneratedJavaFile> generatedJavaFiles,
        List<GeneratedXmlFile> generatedXmlFiles, List<String> warnings)
        throws InterruptedException {

    pluginAggregator = new PluginAggregator();
    for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
        Plugin plugin = ObjectFactory.createPlugin(this, pluginConfiguration);
        if (plugin.validate(warnings)) {
            pluginAggregator.addPlugin(plugin);
        } else {
            warnings.add(getString("Warning.24",
                    pluginConfiguration.getConfigurationType(), id));
        }
    }

    if (introspectedTables != null) {
        for (IntrospectedTable introspectedTable : introspectedTables) {
            callback.checkCancel();

            introspectedTable.initialize();
            introspectedTable.calculateGenerators(warnings, callback);
            generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles());
            generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles());

            generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles(introspectedTable));
            generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles(introspectedTable));
        }
    }

    generatedJavaFiles.addAll(pluginAggregator.contextGenerateAdditionalJavaFiles());
    generatedXmlFiles.addAll(pluginAggregator.contextGenerateAdditionalXmlFiles());
}
 
Example #25
Source File: LombokPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试具体生成
 */
@Test
public void testGenerateDefault() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/LombokPlugin/mybatis-generator-default.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<String> comm = Arrays.asList("@Data");
    List<String> child = new ArrayList<>(Arrays.asList("@EqualsAndHashCode(callSuper = true)", "@ToString(callSuper = true)"));
    child.addAll(comm);

    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()) {
        CompilationUnit compilationUnit = file.getCompilationUnit();
        if (compilationUnit instanceof TopLevelClass) {
            TopLevelClass topLevelClass = (TopLevelClass) compilationUnit;
            String name = topLevelClass.getType().getShortName();
            if ("TbKeyBlobKey".equals(name)) {
                Assert.assertEquals(comm.size(), topLevelClass.getAnnotations().size());
                Assert.assertTrue(comm.containsAll(topLevelClass.getAnnotations()));
            } else if ("TbKeyBlobWithBLOBs".equals(name)) {
                Assert.assertEquals(child.size(), topLevelClass.getAnnotations().size());
                Assert.assertTrue(child.containsAll(topLevelClass.getAnnotations()));
            }

            // tb 没有继承
            if ("Tb".equals(name)) {
                Assert.assertEquals(comm.size(), topLevelClass.getAnnotations().size());
                Assert.assertTrue(comm.containsAll(topLevelClass.getAnnotations()));
            }
        }
    }
}
 
Example #26
Source File: TablePrefixPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试具体生成
 */
@Test
public void testGenerate() throws IOException, XMLParserException, InvalidConfigurationException, InterruptedException, SQLException {
    // 全局规则增加 DB, tb2 单独规则增加Tt
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/TablePrefixPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();
    for (GeneratedJavaFile file : myBatisGenerator.getGeneratedJavaFiles()){
        String name = file.getCompilationUnit().getType().getShortName();
        if (name.matches(".*1.*")){
            Assert.assertTrue(name.matches("DB.*"));
        } else {
            Assert.assertTrue(name.matches("Tt.*"));
        }
    }
}
 
Example #27
Source File: CommentPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * 测试配置了模板参数转换
 */
@Test
public void testGenerateWithTemplate() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/CommentPlugin/mybatis-generator.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().get(0), "TestAddJavaFileComment:Tb:" + new SimpleDateFormat("yyyy-MM").format(new Date()));
            // addFieldComment 同时测试 if 判断和 mbg
            Field id = topLevelClass.getFields().get(0);
            Assert.assertEquals(id.getJavaDocLines().get(0), "注释1");
            Assert.assertEquals(id.getJavaDocLines().get(1), MergeConstants.NEW_ELEMENT_TAG);
            // addGeneralMethodComment
            Method cons = topLevelClass.getMethods().get(0);
            Assert.assertEquals(cons.getJavaDocLines().get(0), "addGeneralMethodComment:Tb:tb");
            // addSetterComment
            Method setter = topLevelClass.getMethods().get(5);
            Assert.assertEquals(setter.getJavaDocLines().get(0), "addSetterComment:field1:field1");
        }
    }

    // xml注释
    ObjectUtil xml = new ObjectUtil(myBatisGenerator.getGeneratedXmlFiles().get(0));
    Document doc = (Document) xml.get("document");
    List<Element> els = ((XmlElement) (doc.getRootElement().getElements().get(0))).getElements();
    String comment = ((TextElement) els.get(0)).getContent();
    Assert.assertEquals(comment, "addComment:BaseResultMap");
}
 
Example #28
Source File: ExampleTargetPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testNormalPath() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator-without-plugin.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<GeneratedJavaFile> list = myBatisGenerator.getGeneratedJavaFiles();
    for (GeneratedJavaFile file : list){
        if (file.getFileName().equals("TbExample.java")){
            Assert.assertEquals(file.getTargetPackage(), tool.getTargetPackage());
        }
    }
}
 
Example #29
Source File: ExampleTargetPluginTest.java    From mybatis-generator-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testConfigPath() throws Exception {
    MyBatisGeneratorTool tool = MyBatisGeneratorTool.create("scripts/ExampleTargetPlugin/mybatis-generator.xml");
    MyBatisGenerator myBatisGenerator = tool.generate();

    List<GeneratedJavaFile> list = myBatisGenerator.getGeneratedJavaFiles();
    for (GeneratedJavaFile file : list){
        if (file.getFileName().equals("TbExample.java")){
            Assert.assertEquals(file.getTargetPackage(), "com.itfsw.mybatis.generator.plugins.dao.example");
        }
    }
}
 
Example #30
Source File: PluginAggregator.java    From mybatis-generator-core-fix with Apache License 2.0 5 votes vote down vote up
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(
        IntrospectedTable introspectedTable) {
    List<GeneratedJavaFile> answer = new ArrayList<GeneratedJavaFile>();
    for (Plugin plugin : plugins) {
        List<GeneratedJavaFile> temp = plugin
                .contextGenerateAdditionalJavaFiles(introspectedTable);
        if (temp != null) {
            answer.addAll(temp);
        }
    }
    return answer;
}