diff --git a/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java b/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java index e6c7e094..8ee6ec0f 100644 --- a/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java +++ b/src/main/resources/modules/SpringBoot/java/action/ajax/system/ResourceAjax.java @@ -19,13 +19,13 @@ import ${basePackage}.module.system.req.ResourceCreateRequest; import ${basePackage}.module.system.req.ResourceDeleteRequest; import ${basePackage}.module.system.req.ResourceFindRequest; import ${basePackage}.module.system.req.ResourceGetRequest; -import ${basePackage}.module.system.req.ResourceLoadRequest; +import ${basePackage}.module.system.req.ResourceTreeRequest; import ${basePackage}.module.system.req.ResourceUpdateRequest; import ${basePackage}.module.system.rsp.ResourceCreateResponse; import ${basePackage}.module.system.rsp.ResourceDeleteResponse; import ${basePackage}.module.system.rsp.ResourceFindResponse; import ${basePackage}.module.system.rsp.ResourceGetResponse; -import ${basePackage}.module.system.rsp.ResourceLoadResponse; +import ${basePackage}.module.system.rsp.ResourceTreeResponse; import ${basePackage}.module.system.rsp.ResourceUpdateResponse; import java.io.IOException; @@ -56,8 +56,8 @@ public class ResourceAjax { return resourceManager.get(request, LocalData.getToken()); } - public ResourceLoadResponse load(ResourceLoadRequest request) { - return resourceManager.load(request, LocalData.getToken()); + public ResourceTreeResponse tree(ResourceTreeRequest request) { + return resourceManager.tree(request, LocalData.getToken()); } public Object template() { diff --git a/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java deleted file mode 100644 index fe815116..00000000 --- a/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceCheck.java +++ /dev/null @@ -1,33 +0,0 @@ -package ${basePackage}.module.system.ent; - -public class ResourceCheck { - - private long resourceId; - private String resourceValue; - private boolean check; - - - public long getResourceId() { - return resourceId; - } - - public void setResourceId(long resourceId) { - this.resourceId = resourceId; - } - - public String getResourceValue() { - return resourceValue; - } - - public void setResourceValue(String resourceValue) { - this.resourceValue = resourceValue; - } - - public boolean isCheck() { - return check; - } - - public void setCheck(boolean check) { - this.check = check; - } -} diff --git a/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java index fc93b938..1cb224a8 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/ent/ResourceTree.java @@ -1,26 +1,27 @@ package ${basePackage}.module.system.ent; +import java.util.ArrayList; import java.util.List; -public class ResourceTree { +public class ResourceTree extends Resource { - private String resourceModule; + private Long pId; - private List resourceChecks; + private List children = new ArrayList<>(); - public String getResourceModule() { - return resourceModule; + public Long getpId() { + return pId; } - public void setResourceModule(String resourceModule) { - this.resourceModule = resourceModule; + public void setpId(Long pId) { + this.pId = pId; } - public List getResourceChecks() { - return resourceChecks; + public List getChildren() { + return children; } - public void setResourceChecks(List resourceChecks) { - this.resourceChecks = resourceChecks; + public void setChildren(List children) { + this.children = children; } } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java index 81556097..436dbd08 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManager.java @@ -5,13 +5,13 @@ import ${basePackage}.module.system.req.ResourceCreateRequest; import ${basePackage}.module.system.req.ResourceDeleteRequest; import ${basePackage}.module.system.req.ResourceFindRequest; import ${basePackage}.module.system.req.ResourceGetRequest; -import ${basePackage}.module.system.req.ResourceLoadRequest; +import ${basePackage}.module.system.req.ResourceTreeRequest; import ${basePackage}.module.system.req.ResourceUpdateRequest; import ${basePackage}.module.system.rsp.ResourceCreateResponse; import ${basePackage}.module.system.rsp.ResourceDeleteResponse; import ${basePackage}.module.system.rsp.ResourceFindResponse; import ${basePackage}.module.system.rsp.ResourceGetResponse; -import ${basePackage}.module.system.rsp.ResourceLoadResponse; +import ${basePackage}.module.system.rsp.ResourceTreeResponse; import ${basePackage}.module.system.rsp.ResourceUpdateResponse; /** @@ -68,5 +68,12 @@ public interface ResourceManager { */ ResourceGetResponse get(ResourceGetRequest request, Token token); - ResourceLoadResponse load(ResourceLoadRequest request, Token token); + /** + * 获得资源树 + * + * @param request 请求对象 + * @param token 令牌 + * @return + */ + ResourceTreeResponse tree(ResourceTreeRequest request, Token token); } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java index f5da25b3..84ab095f 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/mgr/ResourceManagerImpl.java @@ -14,24 +14,24 @@ import ${basePackage}.frame.utils.MapperUtil; import ${basePackage}.frame.utils.Message; import ${basePackage}.frame.utils.ValidationUtil; import ${basePackage}.module.system.ent.Resource; -import ${basePackage}.module.system.ent.ResourceCheck; -import ${basePackage}.module.system.ent.ResourceTree; import ${basePackage}.module.system.mpr.ResourceMapper; import ${basePackage}.module.system.req.ResourceCreateRequest; import ${basePackage}.module.system.req.ResourceDeleteRequest; import ${basePackage}.module.system.req.ResourceFindRequest; import ${basePackage}.module.system.req.ResourceGetRequest; -import ${basePackage}.module.system.req.ResourceLoadRequest; +import ${basePackage}.module.system.req.ResourceTreeRequest; import ${basePackage}.module.system.req.ResourceUpdateRequest; import ${basePackage}.module.system.rsp.ResourceCreateResponse; import ${basePackage}.module.system.rsp.ResourceDeleteResponse; import ${basePackage}.module.system.rsp.ResourceFindResponse; import ${basePackage}.module.system.rsp.ResourceGetResponse; -import ${basePackage}.module.system.rsp.ResourceLoadResponse; +import ${basePackage}.module.system.rsp.ResourceTreeResponse; import ${basePackage}.module.system.rsp.ResourceUpdateResponse; -import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; /** * RESOURCE - 资源 @@ -184,7 +184,7 @@ public class ResourceManagerImpl implements ResourceManager { } @Override - public ResourceTreeResponse load(ResourceTreeRequest request, Token token) { + public ResourceTreeResponse tree(ResourceTreeRequest request, Token token) { ResourceTreeResponse response = new ResourceTreeResponse(); ValidationUtil.validate(request, response); @@ -204,7 +204,8 @@ public class ResourceManagerImpl implements ResourceManager { return response; } - Map map = new HashMap<>(); + Map treeMap = new HashMap<>(); + Map allMap = new HashMap<>(); List result = resourceFindResponse.getResult(); // 获取最顶级资源 @@ -213,23 +214,27 @@ public class ResourceManagerImpl implements ResourceManager { Iterator iterator = result.iterator(); while (iterator.hasNext()) { Resource next = iterator.next(); + ResourceTree tree = new ResourceTree(); + tree.setId(next.getId()); + tree.setCode(next.getCode()); + tree.setComment(next.getComment()); + if (next.getCode() != null && next.getCode().split("_").length == level) { - ResourceTree tree = MapperUtil.map(next, ResourceTree.class); - map.put(tree.getCode(), tree); + allMap.put(tree.getCode(), tree); iterator.remove(); - {//尝试获取上级资源 - String code = next.getCode(); - ResourceTree Ptree = null; - while (code.contains("_")) { - code = code.substring(0, code.lastIndexOf("_")); - Ptree = map.get(code); - if (Ptree != null) break; - } - if (Ptree != null){ - Ptree.getChildren().add(tree); - } else { - map.put(tree.getCode(), tree); - } + //尝试获取上级资源 + String code = next.getCode(); + ResourceTree Ptree = null; + while (code.contains("_")) { + code = code.substring(0, code.lastIndexOf("_")); + Ptree = allMap.get(code); + if (Ptree != null) break; + } + if (Ptree != null) { + tree.setpId(Ptree.getpId()); + Ptree.getChildren().add(tree); + } else { + treeMap.put(tree.getCode(), tree); } } } diff --git a/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceTreeRequest.java b/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceTreeRequest.java index a6f04b88..b8f42f96 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceTreeRequest.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/req/ResourceTreeRequest.java @@ -1,6 +1,6 @@ -package xyz.wbsite.module.system.req; +package ${basePackage}.module.system.req; -import xyz.wbsite.frame.base.BaseRequest; +import ${basePackage}.frame.base.BaseRequest; /** * ResourceTreeRequest - 资源获取 diff --git a/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceTreeResponse.java b/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceTreeResponse.java index 496d14eb..ae09909d 100644 --- a/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceTreeResponse.java +++ b/src/main/resources/modules/SpringBoot/java/module/system/rsp/ResourceTreeResponse.java @@ -1,7 +1,7 @@ -package xyz.wbsite.module.system.rsp; +package ${basePackage}.module.system.rsp; -import xyz.wbsite.frame.base.BaseFindResponse; -import xyz.wbsite.module.system.ent.ResourceTree; +import ${basePackage}.frame.base.BaseFindResponse; +import ${basePackage}.module.system.ent.ResourceTree; /** * ResourceTreeResponse - 资源 diff --git a/src/main/resources/modules/SpringBoot/resources/dbtool/wadmin.xml b/src/main/resources/modules/SpringBoot/resources/dbtool/wadmin.xml index 3a5d0820..2df94e6a 100644 --- a/src/main/resources/modules/SpringBoot/resources/dbtool/wadmin.xml +++ b/src/main/resources/modules/SpringBoot/resources/dbtool/wadmin.xml @@ -1,7 +1,7 @@ wadmin -xyz.wbsite +${basePackage} wangbing false false diff --git a/src/main/resources/modules/SpringBoot/test/application.ftl b/src/main/resources/modules/SpringBoot/test/application.ftl index b3ba5502..2e194ce3 100644 --- a/src/main/resources/modules/SpringBoot/test/application.ftl +++ b/src/main/resources/modules/SpringBoot/test/application.ftl @@ -128,4 +128,7 @@ web.login.page=/login.htm # 拦截验证 web.url.auth.included=/,/**/*.htm # 直接放行 -web.url.auth.excluded=/login.htm \ No newline at end of file +web.url.auth.excluded=/login.htm +# 超级管理员 +web.url.auth.admin=admin +web.url.auth.pwd=17fac3376f76d65943d1d26d1f7cb1e5 \ No newline at end of file diff --git a/src/main/resources/modules/SpringBoot/test/system/DeptTest.java b/src/main/resources/modules/SpringBoot/test/system/DeptTest.java new file mode 100644 index 00000000..5f102886 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/DeptTest.java @@ -0,0 +1,142 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.frame.base.Token; +import ${basePackage}.module.system.mgr.DeptManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import static org.junit.Assert.assertTrue; + + +/** + * DeptTest - - 部门测试用例 + * + * @author wangbing + * @version 0.0.1 + * @since 2019-12-27 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class DeptTest { + + @Autowired + private Token token; + + @Autowired + private DeptManager deptManager; + + @Test + public void testCreate() { + DeptCreateRequest request = new DeptCreateRequest(); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + request.setDeptAlias("部门别名"); + request.setSupCode("父部门代码"); + request.setSupName("父部门名称"); + request.setValid(true); + + DeptCreateResponse response = deptManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + DeptCreateRequest createRequest = new DeptCreateRequest(); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + createRequest.setDeptAlias("部门别名"); + createRequest.setSupCode("父部门代码"); + createRequest.setSupName("父部门名称"); + createRequest.setValid(true); + + DeptCreateResponse createResponse = deptManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + DeptDeleteRequest request = new DeptDeleteRequest(); + request.setId(createResponse.getId()); + + DeptDeleteResponse response = deptManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + DeptCreateRequest createRequest = new DeptCreateRequest(); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + createRequest.setDeptAlias("部门别名"); + createRequest.setSupCode("父部门代码"); + createRequest.setSupName("父部门名称"); + createRequest.setValid(true); + + DeptCreateResponse createResponse = deptManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + DeptUpdateRequest request = new DeptUpdateRequest(); + request.setId(createResponse.getId()); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + request.setDeptAlias("部门别名"); + request.setSupCode("父部门代码"); + request.setSupName("父部门名称"); + request.setValid(true); + + DeptUpdateResponse response = deptManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + DeptFindRequest request = new DeptFindRequest(); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + request.setDeptAlias("部门别名"); + request.setSupCode("父部门代码"); + request.setSupName("父部门名称"); + request.setValid(true); + + DeptFindResponse response = deptManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + DeptCreateRequest createRequest = new DeptCreateRequest(); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + createRequest.setDeptAlias("部门别名"); + createRequest.setSupCode("父部门代码"); + createRequest.setSupName("父部门名称"); + createRequest.setValid(true); + + DeptCreateResponse createResponse = deptManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + DeptGetRequest request = new DeptGetRequest(); + request.setId(createResponse.getId()); + + DeptGetResponse response = deptManager.get(request,token); + + assertTrue(!response.hasError() && response.getDept() != null); + } +} diff --git a/src/main/resources/modules/SpringBoot/test/system/DictItemTest.java b/src/main/resources/modules/SpringBoot/test/system/DictItemTest.java index c0798065..09665bb8 100644 --- a/src/main/resources/modules/SpringBoot/test/system/DictItemTest.java +++ b/src/main/resources/modules/SpringBoot/test/system/DictItemTest.java @@ -1,5 +1,11 @@ package ${basePackage}.system; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; import ${basePackage}.frame.base.Token; import ${basePackage}.module.system.mgr.DictItemManager; import ${basePackage}.module.system.req.DictItemCreateRequest; @@ -12,12 +18,6 @@ import ${basePackage}.module.system.rsp.DictItemDeleteResponse; import ${basePackage}.module.system.rsp.DictItemFindResponse; import ${basePackage}.module.system.rsp.DictItemGetResponse; import ${basePackage}.module.system.rsp.DictItemUpdateResponse; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; import static org.junit.Assert.assertTrue; diff --git a/src/main/resources/modules/SpringBoot/test/system/DictTest.java b/src/main/resources/modules/SpringBoot/test/system/DictTest.java index 730ad6c8..efb02cd4 100644 --- a/src/main/resources/modules/SpringBoot/test/system/DictTest.java +++ b/src/main/resources/modules/SpringBoot/test/system/DictTest.java @@ -1,5 +1,11 @@ package ${basePackage}.system; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; import ${basePackage}.frame.base.Token; import ${basePackage}.module.system.mgr.DictItemManager; import ${basePackage}.module.system.mgr.DictManager; @@ -17,12 +23,6 @@ import ${basePackage}.module.system.rsp.DictGetResponse; import ${basePackage}.module.system.rsp.DictItemCreateResponse; import ${basePackage}.module.system.rsp.DictLoadResponse; import ${basePackage}.module.system.rsp.DictUpdateResponse; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; import static org.junit.Assert.assertTrue; diff --git a/src/main/resources/modules/SpringBoot/test/system/FileTest.java b/src/main/resources/modules/SpringBoot/test/system/FileTest.java index 6a7f2a4e..2b1065ee 100644 --- a/src/main/resources/modules/SpringBoot/test/system/FileTest.java +++ b/src/main/resources/modules/SpringBoot/test/system/FileTest.java @@ -1,5 +1,11 @@ package ${basePackage}.system; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; import ${basePackage}.frame.base.Token; import ${basePackage}.module.system.mgr.FileManager; import ${basePackage}.module.system.req.FileCreateRequest; @@ -10,12 +16,6 @@ import ${basePackage}.module.system.rsp.FileCreateResponse; import ${basePackage}.module.system.rsp.FileDeleteResponse; import ${basePackage}.module.system.rsp.FileFindResponse; import ${basePackage}.module.system.rsp.FileGetResponse; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Transactional; import static org.junit.Assert.assertTrue; diff --git a/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java b/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java index 3974f124..1ae957ff 100644 --- a/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java +++ b/src/main/resources/modules/SpringBoot/test/system/ResourceTest.java @@ -2,15 +2,15 @@ package ${basePackage}.system; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; 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}.frame.base.Token; import ${basePackage}.module.system.req.*; import ${basePackage}.module.system.rsp.*; -import ${basePackage}.frame.base.Token; + +import static org.junit.Assert.assertTrue; /** @@ -29,7 +29,7 @@ public class ResourceTest { private Token token; @Autowired - private ResourceManager resourceManager; + private ${basePackage}.module.system.mgr.ResourceManager resourceManager; @Test public void testCreate() { @@ -126,4 +126,14 @@ public class ResourceTest { assertTrue(!response.hasError() && response.getResource() != null); } + + @Test + public void testTree() { + //创建数据 + ${basePackage}.module.system.req.ResourceTreeRequest request = new ${basePackage}.module.system.req.ResourceTreeRequest(); + + ${basePackage}.module.system.rsp.ResourceTreeResponse response = resourceManager.tree(request, token); + + assertTrue(!response.hasError()); + } } diff --git a/src/main/resources/modules/SpringBoot/test/system/RoleResourceTest.java b/src/main/resources/modules/SpringBoot/test/system/RoleResourceTest.java new file mode 100644 index 00000000..0b552af7 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/RoleResourceTest.java @@ -0,0 +1,118 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.frame.base.Token; +import ${basePackage}.module.system.mgr.RoleResourceManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import static org.junit.Assert.assertTrue; + + +/** + * RoleResourceTest - - 角色资源关系测试用例 + * + * @author wangbing + * @version 0.0.1 + * @since 2019-12-27 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class RoleResourceTest { + + @Autowired + private Token token; + + @Autowired + private RoleResourceManager roleResourceManager; + + @Test + public void testCreate() { + RoleResourceCreateRequest request = new RoleResourceCreateRequest(); + request.setRoleId(1L); + request.setResourceId(1L); + + RoleResourceCreateResponse response = roleResourceManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + RoleResourceCreateRequest createRequest = new RoleResourceCreateRequest(); + createRequest.setRoleId(1L); + createRequest.setResourceId(1L); + + RoleResourceCreateResponse createResponse = roleResourceManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + RoleResourceDeleteRequest request = new RoleResourceDeleteRequest(); + request.setId(createResponse.getId()); + + RoleResourceDeleteResponse response = roleResourceManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + RoleResourceCreateRequest createRequest = new RoleResourceCreateRequest(); + createRequest.setRoleId(1L); + createRequest.setResourceId(1L); + + RoleResourceCreateResponse createResponse = roleResourceManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + RoleResourceUpdateRequest request = new RoleResourceUpdateRequest(); + request.setId(createResponse.getId()); + request.setRoleId(1L); + request.setResourceId(1L); + + RoleResourceUpdateResponse response = roleResourceManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + RoleResourceFindRequest request = new RoleResourceFindRequest(); + request.setRoleId(1L); + request.setResourceId(1L); + + RoleResourceFindResponse response = roleResourceManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + RoleResourceCreateRequest createRequest = new RoleResourceCreateRequest(); + createRequest.setRoleId(1L); + createRequest.setResourceId(1L); + + RoleResourceCreateResponse createResponse = roleResourceManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + RoleResourceGetRequest request = new RoleResourceGetRequest(); + request.setId(createResponse.getId()); + + RoleResourceGetResponse response = roleResourceManager.get(request,token); + + assertTrue(!response.hasError() && response.getRoleResource() != null); + } +} diff --git a/src/main/resources/modules/SpringBoot/test/system/RoleTest.java b/src/main/resources/modules/SpringBoot/test/system/RoleTest.java new file mode 100644 index 00000000..a8dbb5b9 --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/RoleTest.java @@ -0,0 +1,124 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.frame.base.Token; +import ${basePackage}.module.system.mgr.RoleManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import static org.junit.Assert.assertTrue; + + +/** + * RoleTest - - 角色测试用例 + * + * @author wangbing + * @version 0.0.1 + * @since 2019-12-27 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class RoleTest { + + @Autowired + private Token token; + + @Autowired + private RoleManager roleManager; + + @Test + public void testCreate() { + RoleCreateRequest request = new RoleCreateRequest(); + request.setCode("角色代码"); + request.setName("角色名称"); + request.setComment("角色描述"); + + RoleCreateResponse response = roleManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + RoleCreateRequest createRequest = new RoleCreateRequest(); + createRequest.setCode("角色代码"); + createRequest.setName("角色名称"); + createRequest.setComment("角色描述"); + + RoleCreateResponse createResponse = roleManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + RoleDeleteRequest request = new RoleDeleteRequest(); + request.setId(createResponse.getId()); + + RoleDeleteResponse response = roleManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + RoleCreateRequest createRequest = new RoleCreateRequest(); + createRequest.setCode("角色代码"); + createRequest.setName("角色名称"); + createRequest.setComment("角色描述"); + + RoleCreateResponse createResponse = roleManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + RoleUpdateRequest request = new RoleUpdateRequest(); + request.setId(createResponse.getId()); + request.setCode("角色代码"); + request.setName("角色名称"); + request.setComment("角色描述"); + + RoleUpdateResponse response = roleManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + RoleFindRequest request = new RoleFindRequest(); + request.setCode("角色代码"); + request.setName("角色名称"); + request.setComment("角色描述"); + + RoleFindResponse response = roleManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + RoleCreateRequest createRequest = new RoleCreateRequest(); + createRequest.setCode("角色代码"); + createRequest.setName("角色名称"); + createRequest.setComment("角色描述"); + + RoleCreateResponse createResponse = roleManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + RoleGetRequest request = new RoleGetRequest(); + request.setId(createResponse.getId()); + + RoleGetResponse response = roleManager.get(request,token); + + assertTrue(!response.hasError() && response.getRole() != null); + } +} diff --git a/src/main/resources/modules/SpringBoot/test/system/TokensTest.java b/src/main/resources/modules/SpringBoot/test/system/TokensTest.java index fb18d276..a717a572 100644 --- a/src/main/resources/modules/SpringBoot/test/system/TokensTest.java +++ b/src/main/resources/modules/SpringBoot/test/system/TokensTest.java @@ -2,17 +2,19 @@ package ${basePackage}.system; import org.junit.Test; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; 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}.frame.base.Token; 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; +import static org.junit.Assert.assertTrue; + /** * TokensTest - - 通行证测试用例 diff --git a/src/main/resources/modules/SpringBoot/test/system/UserRoleTest.java b/src/main/resources/modules/SpringBoot/test/system/UserRoleTest.java new file mode 100644 index 00000000..0e80955a --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/UserRoleTest.java @@ -0,0 +1,118 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.frame.base.Token; +import ${basePackage}.module.system.mgr.UserRoleManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import static org.junit.Assert.assertTrue; + + +/** + * UserRoleTest - - 用户角色授权测试用例 + * + * @author wangbing + * @version 0.0.1 + * @since 2019-12-27 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class UserRoleTest { + + @Autowired + private Token token; + + @Autowired + private UserRoleManager userRoleManager; + + @Test + public void testCreate() { + UserRoleCreateRequest request = new UserRoleCreateRequest(); + request.setUserId(1L); + request.setRoleId(1L); + + UserRoleCreateResponse response = userRoleManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + UserRoleCreateRequest createRequest = new UserRoleCreateRequest(); + createRequest.setUserId(1L); + createRequest.setRoleId(1L); + + UserRoleCreateResponse createResponse = userRoleManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + UserRoleDeleteRequest request = new UserRoleDeleteRequest(); + request.setId(createResponse.getId()); + + UserRoleDeleteResponse response = userRoleManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + UserRoleCreateRequest createRequest = new UserRoleCreateRequest(); + createRequest.setUserId(1L); + createRequest.setRoleId(1L); + + UserRoleCreateResponse createResponse = userRoleManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + UserRoleUpdateRequest request = new UserRoleUpdateRequest(); + request.setId(createResponse.getId()); + request.setUserId(1L); + request.setRoleId(1L); + + UserRoleUpdateResponse response = userRoleManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + UserRoleFindRequest request = new UserRoleFindRequest(); + request.setUserId(1L); + request.setRoleId(1L); + + UserRoleFindResponse response = userRoleManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + UserRoleCreateRequest createRequest = new UserRoleCreateRequest(); + createRequest.setUserId(1L); + createRequest.setRoleId(1L); + + UserRoleCreateResponse createResponse = userRoleManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + UserRoleGetRequest request = new UserRoleGetRequest(); + request.setId(createResponse.getId()); + + UserRoleGetResponse response = userRoleManager.get(request,token); + + assertTrue(!response.hasError() && response.getUserRole() != null); + } +} diff --git a/src/main/resources/modules/SpringBoot/test/system/UserTest.java b/src/main/resources/modules/SpringBoot/test/system/UserTest.java new file mode 100644 index 00000000..a85cca3d --- /dev/null +++ b/src/main/resources/modules/SpringBoot/test/system/UserTest.java @@ -0,0 +1,153 @@ +package ${basePackage}.system; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; +import ${basePackage}.frame.base.Token; +import ${basePackage}.module.system.mgr.UserManager; +import ${basePackage}.module.system.req.*; +import ${basePackage}.module.system.rsp.*; + +import static org.junit.Assert.assertTrue; + + +/** + * UserTest - - 用户测试用例 + * + * @author wangbing + * @version 0.0.1 + * @since 2019-12-27 + */ +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +public class UserTest { + + @Autowired + private Token token; + + @Autowired + private UserManager userManager; + + @Test + public void testCreate() { + UserCreateRequest request = new UserCreateRequest(); + request.setUserName("用户账户"); + request.setUserCode("用户代码"); + request.setUserAlias("用户别名"); + request.setUserPwd("用户密码"); + request.setUserStatus("code"); + request.setDeptId(1L); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + + UserCreateResponse response = userManager.create(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testDelete() { + + //创建数据 + UserCreateRequest createRequest = new UserCreateRequest(); + createRequest.setUserName("用户账户"); + createRequest.setUserCode("用户代码"); + createRequest.setUserAlias("用户别名"); + createRequest.setUserPwd("用户密码"); + createRequest.setUserStatus("code"); + createRequest.setDeptId(1L); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + + UserCreateResponse createResponse = userManager.create(createRequest,token); + + assertTrue(!createResponse.hasError() && createResponse.getId() > 0); + //删除数据 + UserDeleteRequest request = new UserDeleteRequest(); + request.setId(createResponse.getId()); + + UserDeleteResponse response = userManager.delete(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testUpdate() { + //创建数据 + UserCreateRequest createRequest = new UserCreateRequest(); + createRequest.setUserName("用户账户"); + createRequest.setUserCode("用户代码"); + createRequest.setUserAlias("用户别名"); + createRequest.setUserPwd("用户密码"); + createRequest.setUserStatus("code"); + createRequest.setDeptId(1L); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + + UserCreateResponse createResponse = userManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //更新数据 + UserUpdateRequest request = new UserUpdateRequest(); + request.setId(createResponse.getId()); + request.setUserName("用户账户"); + request.setUserCode("用户代码"); + request.setUserAlias("用户别名"); + request.setUserPwd("用户密码"); + request.setUserStatus("code"); + request.setDeptId(1L); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + + UserUpdateResponse response = userManager.update(request,token); + + assertTrue(!response.hasError() && response.getResult() == 1L); + } + + @Test + public void testFind() { + UserFindRequest request = new UserFindRequest(); + request.setUserName("用户账户"); + request.setUserCode("用户代码"); + request.setUserAlias("用户别名"); + request.setUserStatus("code"); + request.setDeptId(1L); + request.setDeptCode("部门代码"); + request.setDeptName("部门名称"); + + UserFindResponse response = userManager.find(request,token); + + assertTrue(!response.hasError()); + } + + @Test + public void testGet() { + //创建数据 + UserCreateRequest createRequest = new UserCreateRequest(); + createRequest.setUserName("用户账户"); + createRequest.setUserCode("用户代码"); + createRequest.setUserAlias("用户别名"); + createRequest.setUserPwd("用户密码"); + createRequest.setUserStatus("code"); + createRequest.setDeptId(1L); + createRequest.setDeptCode("部门代码"); + createRequest.setDeptName("部门名称"); + + UserCreateResponse createResponse = userManager.create(createRequest, token); + + assertTrue(!createResponse.hasError()); + + //获得数据 + UserGetRequest request = new UserGetRequest(); + request.setId(createResponse.getId()); + + UserGetResponse response = userManager.get(request,token); + + assertTrue(!response.hasError() && response.getUser() != null); + } +}