diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm index 906d12c..bfe2dc0 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue/api/api.js.vm @@ -63,7 +63,7 @@ export function export${simpleClassName}Excel(params) { responseType: 'blob' }) } -## 特殊:主子表专属逻辑 +## 特殊:主子表专属逻辑 TODO @puhui999:下面方法的【空格】不太对 #foreach ($subTable in $subTables) #set ($index = $foreach.count - 1) #set ($subSimpleClassName = $subSimpleClassNames.get($index)) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm index c159579..1c15536 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm @@ -1,137 +1,137 @@ \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java new file mode 100644 index 0000000..588f2b0 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineAbstractTest.java @@ -0,0 +1,127 @@ +package cn.iocoder.yudao.module.infra.service.codegen.inner; + +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.io.IoUtil; +import cn.hutool.core.io.resource.ResourceUtil; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.core.util.ZipUtil; +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; +import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; +import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.InjectMocks; +import org.mockito.Spy; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * {@link CodegenEngine} 的单元测试抽象基类 + * + * @author 芋道源码 + */ +public abstract class CodegenEngineAbstractTest extends BaseMockitoUnitTest { + + @InjectMocks + protected CodegenEngine codegenEngine; + + @Spy + protected CodegenProperties codegenProperties = new CodegenProperties() + .setBasePackage("cn.iocoder.yudao"); + + @BeforeEach + public void setUp() { + codegenEngine.initGlobalBindingMap(); + } + + protected static CodegenTableDO getTable(String name) { + String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); + return JsonUtils.parseObject(content, "table", CodegenTableDO.class); + } + + protected static List getColumnList(String name) { + String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); + List list = JsonUtils.parseArray(content, "columns", CodegenColumnDO.class); + list.forEach(column -> { + if (column.getNullable() == null) { + column.setNullable(false); + } + if (column.getCreateOperation() == null) { + column.setCreateOperation(false); + } + if (column.getUpdateOperation() == null) { + column.setUpdateOperation(false); + } + if (column.getListOperation() == null) { + column.setListOperation(false); + } + if (column.getListOperationResult() == null) { + column.setListOperationResult(false); + } + }); + return list; + } + + @SuppressWarnings("rawtypes") + protected static void assertResult(Map result, String path) { + String assertContent = ResourceUtil.readUtf8Str(path + "/assert.json"); + List asserts = JsonUtils.parseArray(assertContent, HashMap.class); + assertEquals(asserts.size(), result.size()); + // 校验每个文件 + asserts.forEach(assertMap -> { + String contentPath = (String) assertMap.get("contentPath"); + String filePath = (String) assertMap.get("filePath"); + String content = ResourceUtil.readUtf8Str(path + "/" + contentPath); + assertEquals(content, result.get(filePath), filePath + ":不匹配"); + }); + } + + // ==================== 调试专用 ==================== + + /** + * 【调试使用】将生成的代码,写入到文件 + * + * @param result 生成的代码 + * @param path 写入文件的路径 + */ + protected void writeFile(Map result, String path) { + // 生成压缩包 + String[] paths = result.keySet().toArray(new String[0]); + ByteArrayInputStream[] ins = result.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + ZipUtil.zip(outputStream, paths, ins); + // 写入文件 + FileUtil.writeBytes(outputStream.toByteArray(), path); + } + + /** + * 【调试使用】将生成的结果,写入到文件 + * + * @param result 生成的代码 + * @param basePath 写入文件的路径(绝对路径) + */ + protected void writeResult(Map result, String basePath) { + // 写入文件内容 + List> asserts = new ArrayList<>(); + result.forEach((filePath, fileContent) -> { + String lastFilePath = StrUtil.subAfter(filePath, '/', true); + String contentPath = StrUtil.subAfter(lastFilePath, '.', true) + + '/' + StrUtil.subBefore(lastFilePath, '.', true); + asserts.add(MapUtil.builder().put("filePath", filePath) + .put("contentPath", contentPath).build()); + FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); + }); + // 写入 assert.json 文件 + FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath +"/assert.json"); + } + +} diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java index 9513362..aaaf17e 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue2Test.java @@ -1,47 +1,21 @@ package cn.iocoder.yudao.module.infra.service.codegen.inner; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.io.resource.ResourceUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.core.util.ZipUtil; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; -import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.*; - -import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** - * {@link CodegenEngine} 的单元测试 + * {@link CodegenEngine} 的 Vue2 + Element UI 单元测试 * * @author 芋道源码 */ -public class CodegenEngineVue2Test extends BaseMockitoUnitTest { - - @InjectMocks - private CodegenEngine codegenEngine; - - @Spy - private CodegenProperties codegenProperties = new CodegenProperties() - .setBasePackage("cn.iocoder.yudao"); - - @BeforeEach - public void setUp() { - codegenEngine.initGlobalBindingMap(); - } +public class CodegenEngineVue2Test extends CodegenEngineAbstractTest { @Test public void testExecute_vue2_one() { @@ -118,85 +92,4 @@ public class CodegenEngineVue2Test extends BaseMockitoUnitTest { // writeFile(result, "/Users/yunai/test/demo11.zip"); } - private static CodegenTableDO getTable(String name) { - String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); - return JsonUtils.parseObject(content, "table", CodegenTableDO.class); - } - - private static List getColumnList(String name) { - String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); - List list = JsonUtils.parseArray(content, "columns", CodegenColumnDO.class); - list.forEach(column -> { - if (column.getNullable() == null) { - column.setNullable(false); - } - if (column.getCreateOperation() == null) { - column.setCreateOperation(false); - } - if (column.getUpdateOperation() == null) { - column.setUpdateOperation(false); - } - if (column.getListOperation() == null) { - column.setListOperation(false); - } - if (column.getListOperationResult() == null) { - column.setListOperationResult(false); - } - }); - return list; - } - - @SuppressWarnings("rawtypes") - private static void assertResult(Map result, String path) { - String assertContent = ResourceUtil.readUtf8Str(path + "/assert.json"); - List asserts = JsonUtils.parseArray(assertContent, HashMap.class); - assertEquals(asserts.size(), result.size()); - // 校验每个文件 - asserts.forEach(assertMap -> { - String contentPath = (String) assertMap.get("contentPath"); - String filePath = (String) assertMap.get("filePath"); - String content = ResourceUtil.readUtf8Str(path + "/" + contentPath); - assertEquals(content, result.get(filePath), filePath + ":不匹配"); - }); - } - - // ==================== 调试专用 ==================== - - /** - * 【调试使用】将生成的代码,写入到文件 - * - * @param result 生成的代码 - * @param path 写入文件的路径 - */ - private void writeFile(Map result, String path) { - // 生成压缩包 - String[] paths = result.keySet().toArray(new String[0]); - ByteArrayInputStream[] ins = result.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ZipUtil.zip(outputStream, paths, ins); - // 写入文件 - FileUtil.writeBytes(outputStream.toByteArray(), path); - } - - /** - * 【调试使用】将生成的结果,写入到文件 - * - * @param result 生成的代码 - * @param basePath 写入文件的路径(绝对路径) - */ - private void writeResult(Map result, String basePath) { - // 写入文件内容 - List> asserts = new ArrayList<>(); - result.forEach((filePath, fileContent) -> { - String lastFilePath = StrUtil.subAfter(filePath, '/', true); - String contentPath = StrUtil.subAfter(lastFilePath, '.', true) - + '/' + StrUtil.subBefore(lastFilePath, '.', true); - asserts.add(MapUtil.builder().put("filePath", filePath) - .put("contentPath", contentPath).build()); - FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); - }); - // 写入 assert.json 文件 - FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath +"/assert.json"); - } - } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java index 7c5a877..56ad78a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngineVue3Test.java @@ -1,48 +1,21 @@ package cn.iocoder.yudao.module.infra.service.codegen.inner; -import cn.hutool.core.io.FileUtil; -import cn.hutool.core.io.IoUtil; -import cn.hutool.core.io.resource.ResourceUtil; -import cn.hutool.core.map.MapUtil; -import cn.hutool.core.util.StrUtil; -import cn.hutool.core.util.ZipUtil; -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; -import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenColumnDO; import cn.iocoder.yudao.module.infra.dal.dataobject.codegen.CodegenTableDO; -import cn.iocoder.yudao.module.infra.enums.codegen.*; -import cn.iocoder.yudao.module.infra.framework.codegen.config.CodegenProperties; -import org.apache.ibatis.type.JdbcType; -import org.junit.jupiter.api.BeforeEach; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenFrontTypeEnum; +import cn.iocoder.yudao.module.infra.enums.codegen.CodegenTemplateTypeEnum; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; -import org.mockito.Spy; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.*; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** - * {@link CodegenEngine} 的单元测试 + * {@link CodegenEngine} 的 Vue2 + Element Plus 单元测试 * * @author 芋道源码 */ -public class CodegenEngineTest extends BaseMockitoUnitTest { - - @InjectMocks - private CodegenEngine codegenEngine; - - @Spy - private CodegenProperties codegenProperties = new CodegenProperties() - .setBasePackage("cn.iocoder.yudao"); - - @BeforeEach - public void setUp() { - codegenEngine.initGlobalBindingMap(); - } +public class CodegenEngineVue3Test extends CodegenEngineAbstractTest { @Test public void testExecute_vue3_one() { @@ -119,85 +92,4 @@ public class CodegenEngineTest extends BaseMockitoUnitTest { // writeFile(result, "/Users/yunai/test/demo11.zip"); } - private static CodegenTableDO getTable(String name) { - String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); - return JsonUtils.parseObject(content, "table", CodegenTableDO.class); - } - - private static List getColumnList(String name) { - String content = ResourceUtil.readUtf8Str("codegen/table/" + name + ".json"); - List list = JsonUtils.parseArray(content, "columns", CodegenColumnDO.class); - list.forEach(column -> { - if (column.getNullable() == null) { - column.setNullable(false); - } - if (column.getCreateOperation() == null) { - column.setCreateOperation(false); - } - if (column.getUpdateOperation() == null) { - column.setUpdateOperation(false); - } - if (column.getListOperation() == null) { - column.setListOperation(false); - } - if (column.getListOperationResult() == null) { - column.setListOperationResult(false); - } - }); - return list; - } - - @SuppressWarnings("rawtypes") - private static void assertResult(Map result, String path) { - String assertContent = ResourceUtil.readUtf8Str(path + "/assert.json"); - List asserts = JsonUtils.parseArray(assertContent, HashMap.class); - assertEquals(asserts.size(), result.size()); - // 校验每个文件 - asserts.forEach(assertMap -> { - String contentPath = (String) assertMap.get("contentPath"); - String filePath = (String) assertMap.get("filePath"); - String content = ResourceUtil.readUtf8Str(path + "/" + contentPath); - assertEquals(content, result.get(filePath), filePath + ":不匹配"); - }); - } - - // ==================== 调试专用 ==================== - - /** - * 【调试使用】将生成的代码,写入到文件 - * - * @param result 生成的代码 - * @param path 写入文件的路径 - */ - private void writeFile(Map result, String path) { - // 生成压缩包 - String[] paths = result.keySet().toArray(new String[0]); - ByteArrayInputStream[] ins = result.values().stream().map(IoUtil::toUtf8Stream).toArray(ByteArrayInputStream[]::new); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - ZipUtil.zip(outputStream, paths, ins); - // 写入文件 - FileUtil.writeBytes(outputStream.toByteArray(), path); - } - - /** - * 【调试使用】将生成的结果,写入到文件 - * - * @param result 生成的代码 - * @param basePath 写入文件的路径(绝对路径) - */ - private void writeResult(Map result, String basePath) { - // 写入文件内容 - List> asserts = new ArrayList<>(); - result.forEach((filePath, fileContent) -> { - String lastFilePath = StrUtil.subAfter(filePath, '/', true); - String contentPath = StrUtil.subAfter(lastFilePath, '.', true) - + '/' + StrUtil.subBefore(lastFilePath, '.', true); - asserts.add(MapUtil.builder().put("filePath", filePath) - .put("contentPath", contentPath).build()); - FileUtil.writeUtf8String(fileContent, basePath + "/" + contentPath); - }); - // 写入 assert.json 文件 - FileUtil.writeUtf8String(JsonUtils.toJsonPrettyString(asserts), basePath +"/assert.json"); - } - }