From a572ac900d0df847e7f0b74119a45f4d8f58fdd6 Mon Sep 17 00:00:00 2001 From: wangbing <1919101440@qq.com> Date: Thu, 19 Dec 2019 23:28:16 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: dc201f24cb70e4fe7043e0907772323cb36823a1 --- .../manger/callable/SpringBootCallable.java | 7 +- .../SpringBoot/java/frame/utils/MD5Util.java | 43 ++++- .../java/module/mgr/ApiManager.java | 25 --- .../java/module/mgr/ApiManagerImpl.java | 31 ---- .../modules/SpringBoot/test/UtilTest.java | 6 + .../SpringBoot/test/system/ResourceTest.java | 129 +++++++++++++ .../SpringBoot/test/system/TokensTest.java | 172 ++++++++++++++++++ 7 files changed, 347 insertions(+), 66 deletions(-) delete mode 100644 src/main/resources/modules/SpringBoot/java/module/mgr/ApiManager.java delete mode 100644 src/main/resources/modules/SpringBoot/java/module/mgr/ApiManagerImpl.java create mode 100644 src/main/resources/modules/SpringBoot/test/system/ResourceTest.java create mode 100644 src/main/resources/modules/SpringBoot/test/system/TokensTest.java diff --git a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java index 2454909d..bc716a7b 100644 --- a/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java +++ b/src/main/java/xyz/wbsite/dbtool/javafx/manger/callable/SpringBootCallable.java @@ -336,11 +336,6 @@ public class SpringBootCallable implements Callable { ctx.put("author", md.getProjectAuthor()); ctx.put("date", new Date()); - if (md.getModuleName().equals("api")) { - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiManager" + ".java"), option + "/java/module/mgr/ApiManager.java", ctx); - freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), "ApiManagerImpl" + ".java"), option + "/java/module/mgr/ApiManagerImpl.java", ctx); - } - for (Table table : md.getTables()) { ctx.put("table", table); freeMarkerManager.outputTemp(Tool.createFile(root.getAbsolutePath(), Tool.lineToClassName(table.getTableName()) + "Manager" + ".java"), option + "/java/module/mgr/manager.ftl", ctx); @@ -947,6 +942,8 @@ public class SpringBootCallable implements Callable { freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "DictItemTest.java"), option + "/test/system/DictItemTest.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "DictTest.java"), option + "/test/system/DictTest.java", ctx); freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "FileTest.java"), option + "/test/system/FileTest.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "ResourceTest.java"), option + "/test/system/ResourceTest.java", ctx); + freeMarkerManager.outputTemp(Tool.createFile(system.getAbsolutePath(), "TokensTest.java"), option + "/test/system/TokensTest.java", ctx); } for (Module md : project.getModules()) { diff --git a/src/main/resources/modules/SpringBoot/java/frame/utils/MD5Util.java b/src/main/resources/modules/SpringBoot/java/frame/utils/MD5Util.java index 1c18be2c..07669a9f 100644 --- a/src/main/resources/modules/SpringBoot/java/frame/utils/MD5Util.java +++ b/src/main/resources/modules/SpringBoot/java/frame/utils/MD5Util.java @@ -1,9 +1,7 @@ package ${basePackage}.frame.utils; -import com.fasterxml.jackson.core.TreeNode; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Iterator; /** * MD5Util - MD5工具类 @@ -15,10 +13,35 @@ import java.util.Iterator; public class MD5Util { /** - * 加密 + * 生成加密密码 * - * @param value - * @return + * @param value 待加密字符串 + * @param salts 加密盐 + * @return 加密字符串 + */ + public static String generatePwd(String value, String... salts) { + String pwd = encode(value); + for (String s : salts) { + pwd = encode(s + value + s); + } + return pwd; + } + + /** + * 生成加密密码 + * + * @param value 待加密字符串 + * @return 加密字符串 + */ + public static String generatePwd(String value) { + return generatePwd(value, "MD5"); + } + + /** + * 加密字符串 + * + * @param value 待加密字符串 + * @return 信息摘要Hex字符串 */ public static String encode(String value) { try { @@ -31,6 +54,12 @@ public class MD5Util { } } + /** + * 加密字符串 + * + * @param bytes 待加密字节数组 + * @return 信息摘要Hex字符串 + */ public static String encode(byte[] bytes) { try { MessageDigest md = MessageDigest.getInstance("md5"); @@ -42,6 +71,10 @@ public class MD5Util { } } + /** + * @param bytes 信息摘要字节数组 + * @return Hex字符串 + */ private static String toHexString(byte bytes[]) { StringBuilder hs = new StringBuilder(); String stmp = ""; diff --git a/src/main/resources/modules/SpringBoot/java/module/mgr/ApiManager.java b/src/main/resources/modules/SpringBoot/java/module/mgr/ApiManager.java deleted file mode 100644 index 56b38423..00000000 --- a/src/main/resources/modules/SpringBoot/java/module/mgr/ApiManager.java +++ /dev/null @@ -1,25 +0,0 @@ -package ${basePackage}.module.${moduleName}.mgr; - -import ${basePackage}.module.${moduleName}.req.*; -import ${basePackage}.module.${moduleName}.rsp.*; -import ${basePackage}.frame.base.Token; - -/** - * Api接口 - * - * @author wangbing - * @version 0.0.1 - * @since 2018-10-23 - */ -public interface ApiManager { - - /** - * Api#example - * - * @param request 请求对象 - * @param token 令牌 - * @return 响应 - */ - ApiExampleResponse example(ApiExampleRequest request, Token token); - -} diff --git a/src/main/resources/modules/SpringBoot/java/module/mgr/ApiManagerImpl.java b/src/main/resources/modules/SpringBoot/java/module/mgr/ApiManagerImpl.java deleted file mode 100644 index 130ab58e..00000000 --- a/src/main/resources/modules/SpringBoot/java/module/mgr/ApiManagerImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -package ${basePackage}.module.${moduleName}.mgr; - -import ${basePackage}.module.${moduleName}.req.*; -import ${basePackage}.module.${moduleName}.rsp.*; -import ${basePackage}.frame.base.Token; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Api接口 - * - * @author wangbing - * @version 0.0.1 - * @since 2018-10-23 - */ -@Transactional -@Service -public class ApiManagerImpl implements ApiManager { - - /** - * Api#example - * - * @param request 请求对象 - * @param token 令牌 - * @return 响应 - */ - @Override - public ApiExampleResponse example(ApiExampleRequest request, Token token) { - return new ApiExampleResponse(); - } -} diff --git a/src/main/resources/modules/SpringBoot/test/UtilTest.java b/src/main/resources/modules/SpringBoot/test/UtilTest.java index 3b7c8df0..5ff9aabf 100644 --- a/src/main/resources/modules/SpringBoot/test/UtilTest.java +++ b/src/main/resources/modules/SpringBoot/test/UtilTest.java @@ -19,6 +19,12 @@ import org.springframework.transaction.annotation.Transactional; @Transactional public class UtilTest { + @Test + public void testGeneratePwd() { + System.out.print("[123456]加密="); + System.out.println(MD5Util.generatePwd("123456")); + } + @Test public void testIDgenerator() { for (int i = 0; i < 10; i++) { diff --git a/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java b/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java new file mode 100644 index 00000000..a07103b4 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java @@ -0,0 +1,129 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.Assert.assertTrue; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.module.system.mgr.ResourceManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; +import ${basePackage}.frame.base.Token; + + +/** +* ResourceTest - - 资源测试用例 +* +* @author author +* @version 0.0.1 +* @since 2019-12-19 +*/ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class ResourceTest { + + @Autowired + private Token token; + + @Autowired + private ResourceManager resourceManager; + + @Test + public void testCreate() { + ResourceCreateRequest request = new ResourceCreateRequest(); + request.setValue("资源内容"); + request.setComment("资源描述"); + request.setResourceType("code"); + request.setValid(true); + + ResourceCreateResponse response = resourceManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + ResourceCreateRequest createRequest = new ResourceCreateRequest(); + createRequest.setValue("资源内容"); + createRequest.setComment("资源描述"); + createRequest.setResourceType("code"); + createRequest.setValid(true); + + ResourceCreateResponse createResponse = resourceManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + ResourceDeleteRequest request = new ResourceDeleteRequest(); + request.setId(createResponse.getId()); + + ResourceDeleteResponse response = resourceManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + ResourceCreateRequest createRequest = new ResourceCreateRequest(); + createRequest.setValue("资源内容"); + createRequest.setComment("资源描述"); + createRequest.setResourceType("code"); + createRequest.setValid(true); + + ResourceCreateResponse createResponse = resourceManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + ResourceUpdateRequest request = new ResourceUpdateRequest(); + request.setId(createResponse.getId()); + request.setValue("资源内容"); + request.setComment("资源描述"); + request.setResourceType("code"); + request.setValid(true); + + ResourceUpdateResponse response = resourceManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + ResourceFindRequest request = new ResourceFindRequest(); + request.setValue("资源内容"); + request.setComment("资源描述"); + request.setResourceType("code"); + request.setValid(true); + + ResourceFindResponse response = resourceManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + ResourceCreateRequest createRequest = new ResourceCreateRequest(); + createRequest.setValue("资源内容"); + createRequest.setComment("资源描述"); + createRequest.setResourceType("code"); + createRequest.setValid(true); + + ResourceCreateResponse createResponse = resourceManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + ResourceGetRequest request = new ResourceGetRequest(); + request.setId(createResponse.getId()); + + ResourceGetResponse response = resourceManager.get(request,token); + + assertTrue(!response.hasError() && response.getResource() != null); + } +} diff --git a/src/main/resources/modules/SpringBoot/test/system/TokensTest.java b/src/main/resources/modules/SpringBoot/test/system/TokensTest.java new file mode 100644 index 00000000..7b4ac77d --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/TokensTest.java @@ -0,0 +1,172 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import static org.junit.Assert.assertTrue; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.module.system.mgr.TokensManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; +import ${basePackage}.frame.base.Token; +import java.util.Date; + + +/** +* TokensTest - - 通行证测试用例 +* +* @author author +* @version 0.0.1 +* @since 2019-12-19 +*/ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class TokensTest { + + @Autowired + private Token token; + + @Autowired + private TokensManager tokensManager; + + @Test + public void testCreate() { + TokensCreateRequest request = new TokensCreateRequest(); + request.setUserId(1L); + request.setUserName("用户名称"); + request.setLoginTime(new Date()); + request.setValidTime(new Date()); + request.setValid(true); + request.setDeptId(1L); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + request.setTerminalType("code"); + request.setTerminalIp("终端地址"); + request.setTerminalInfo("终端信息"); + + TokensCreateResponse response = tokensManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + TokensCreateRequest createRequest = new TokensCreateRequest(); + createRequest.setUserId(1L); + createRequest.setUserName("用户名称"); + createRequest.setLoginTime(new Date()); + createRequest.setValidTime(new Date()); + createRequest.setValid(true); + createRequest.setDeptId(1L); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + createRequest.setTerminalType("code"); + createRequest.setTerminalIp("终端地址"); + createRequest.setTerminalInfo("终端信息"); + + TokensCreateResponse createResponse = tokensManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + TokensDeleteRequest request = new TokensDeleteRequest(); + request.setId(createResponse.getId()); + + TokensDeleteResponse response = tokensManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + TokensCreateRequest createRequest = new TokensCreateRequest(); + createRequest.setUserId(1L); + createRequest.setUserName("用户名称"); + createRequest.setLoginTime(new Date()); + createRequest.setValidTime(new Date()); + createRequest.setValid(true); + createRequest.setDeptId(1L); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + createRequest.setTerminalType("code"); + createRequest.setTerminalIp("终端地址"); + createRequest.setTerminalInfo("终端信息"); + + TokensCreateResponse createResponse = tokensManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + TokensUpdateRequest request = new TokensUpdateRequest(); + request.setId(createResponse.getId()); + request.setUserId(1L); + request.setUserName("用户名称"); + request.setLoginTime(new Date()); + request.setValidTime(new Date()); + request.setValid(true); + request.setDeptId(1L); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + request.setTerminalType("code"); + request.setTerminalIp("终端地址"); + request.setTerminalInfo("终端信息"); + + TokensUpdateResponse response = tokensManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + TokensFindRequest request = new TokensFindRequest(); + request.setUserId(1L); + request.setUserName("用户名称"); + request.setLoginTime(new Date()); + request.setValidTime(new Date()); + request.setValid(true); + request.setDeptId(1L); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + request.setTerminalType("code"); + request.setTerminalIp("终端地址"); + request.setTerminalInfo("终端信息"); + + TokensFindResponse response = tokensManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + TokensCreateRequest createRequest = new TokensCreateRequest(); + createRequest.setUserId(1L); + createRequest.setUserName("用户名称"); + createRequest.setLoginTime(new Date()); + createRequest.setValidTime(new Date()); + createRequest.setValid(true); + createRequest.setDeptId(1L); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + createRequest.setTerminalType("code"); + createRequest.setTerminalIp("终端地址"); + createRequest.setTerminalInfo("终端信息"); + + TokensCreateResponse createResponse = tokensManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + TokensGetRequest request = new TokensGetRequest(); + request.setId(createResponse.getId()); + + TokensGetResponse response = tokensManager.get(request,token); + + assertTrue(!response.hasError() && response.getTokens() != null); + } +}