| | |
| | | package com.iplatform.base; |
| | | |
| | | import com.fasterxml.jackson.databind.JsonNode; |
| | | import com.fasterxml.jackson.databind.node.ObjectNode; |
| | | import com.iplatform.base.pojo.form.FormDataItem; |
| | | import com.iplatform.base.util.MenuUtils; |
| | | import com.iplatform.base.util.NotificationUtils; |
| | | import com.iplatform.model.po.S_user_core; |
| | | import com.walker.infrastructure.utils.GenericTypeUtils; |
| | | import com.walker.infrastructure.utils.JsonUtils; |
| | | import com.walker.infrastructure.utils.PhoneNumberUtils; |
| | | import org.junit.Test; |
| | | import org.springframework.core.ResolvableType; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | |
| | | public class TestMenu { |
| | | |
| | | private List<String> typeList1 = new ArrayList<String>(); |
| | | |
| | | // @Test |
| | | public void testPhoneNumber(){ |
| | | String input = "1001"; |
| | | boolean value = PhoneNumberUtils.isCellPhoneNumber(input); |
| | | System.out.println(value + ", " + input); |
| | | } |
| | | |
| | | // @Test |
| | | public void testFasterxml() throws Exception{ |
| | | // String json = "[\\\"23:53\\\",\\\"23:59\\\"]"; |
| | | String json_2 = "[\"23:53\",\"23:59\"]"; |
| | | List<String> listJson = JsonUtils.jsonStringToObject(json_2, List.class); |
| | | System.out.println("listJson = " + listJson); |
| | | // System.out.println("json 01 = " + json.replaceAll("\"", "")); |
| | | // System.out.println("json 02 = " + json_2.replaceAll("\"", "")); |
| | | |
| | | List<String> list = new ArrayList<>(4); |
| | | list.add("10:20"); |
| | | list.add("11:32"); |
| | | |
| | | FormDataItem dataItem = new FormDataItem(); |
| | | dataItem.setName("测试01"); |
| | | dataItem.setTitle("时间段"); |
| | | |
| | | String listJsonString = JsonUtils.objectToJsonString(list); |
| | | System.out.println("listJsonString = " + listJsonString); |
| | | dataItem.setValue(listJsonString); |
| | | |
| | | String formDataItemJson = JsonUtils.objectToJsonString(dataItem); |
| | | System.out.println("formDataItemJson = " + formDataItemJson); |
| | | |
| | | FormDataItem dataItem1From = JsonUtils.jsonStringToObject(formDataItemJson, FormDataItem.class); |
| | | System.out.println("formDataItem.value = " + dataItem1From.getValue()); |
| | | |
| | | List<String> listFrom = JsonUtils.jsonStringToObject(listJsonString, List.class); |
| | | // ObjectNode objectNode = new ObjectNode(); |
| | | System.out.println("listFrom = " + listFrom); |
| | | |
| | | // 判断字符串是否json |
| | | // String noneJsonStr = JsonUtils.objectToJsonString() |
| | | } |
| | | |
| | | // @Test |
| | | public void testPushMessageType(){ |
| | | // String input = "tcp && web_socket && wx && system"; |
| | | // String input = "tcp || web_socket || wx || system"; |
| | | String input = "tcp "; |
| | | Object[] data = NotificationUtils.acquireMessagePushRules(input); |
| | | System.out.println(data[0]); |
| | | String[] indexList = (String[])data[1]; |
| | | for(String s : indexList){ |
| | | System.out.println("index = " + s); |
| | | } |
| | | } |
| | | |
| | | // @Test |
| | | public void testGenericType() throws Exception{ |
| | | // List<String> typeList1 = new ArrayList<String>(); |
| | | Class type1 = GenericTypeUtils.getSuperClassGenericType(typeList1.getClass()); |
| | | System.out.println(type1); |
| | | // Type[] types = typeList1.getClass().getGenericInterfaces(); |
| | | // TypeVariable[] types = typeList1.getClass().getTypeParameters(); |
| | | // for(Type type : types){ |
| | | // System.out.println(type); |
| | | //package com.iplatform.base; |
| | | // |
| | | //import com.fasterxml.jackson.databind.JsonNode; |
| | | //import com.fasterxml.jackson.databind.node.ObjectNode; |
| | | //import com.iplatform.base.pojo.form.FormDataItem; |
| | | //import com.iplatform.base.util.MenuUtils; |
| | | //import com.iplatform.base.util.NotificationUtils; |
| | | //import com.iplatform.model.po.S_user_core; |
| | | //import com.walker.infrastructure.utils.GenericTypeUtils; |
| | | //import com.walker.infrastructure.utils.JsonUtils; |
| | | //import com.walker.infrastructure.utils.PhoneNumberUtils; |
| | | //import org.springframework.core.ResolvableType; |
| | | // |
| | | //import java.util.ArrayList; |
| | | //import java.util.Iterator; |
| | | //import java.util.List; |
| | | // |
| | | //public class TestMenu { |
| | | // |
| | | // private List<String> typeList1 = new ArrayList<String>(); |
| | | // |
| | | //// @Test |
| | | // public void testPhoneNumber(){ |
| | | // String input = "1001"; |
| | | // boolean value = PhoneNumberUtils.isCellPhoneNumber(input); |
| | | // System.out.println(value + ", " + input); |
| | | // } |
| | | // |
| | | //// @Test |
| | | // public void testFasterxml() throws Exception{ |
| | | //// String json = "[\\\"23:53\\\",\\\"23:59\\\"]"; |
| | | // String json_2 = "[\"23:53\",\"23:59\"]"; |
| | | // List<String> listJson = JsonUtils.jsonStringToObject(json_2, List.class); |
| | | // System.out.println("listJson = " + listJson); |
| | | //// System.out.println("json 01 = " + json.replaceAll("\"", "")); |
| | | //// System.out.println("json 02 = " + json_2.replaceAll("\"", "")); |
| | | // |
| | | // List<String> list = new ArrayList<>(4); |
| | | // list.add("10:20"); |
| | | // list.add("11:32"); |
| | | // |
| | | // FormDataItem dataItem = new FormDataItem(); |
| | | // dataItem.setName("测试01"); |
| | | // dataItem.setTitle("时间段"); |
| | | // |
| | | // String listJsonString = JsonUtils.objectToJsonString(list); |
| | | // System.out.println("listJsonString = " + listJsonString); |
| | | // dataItem.setValue(listJsonString); |
| | | // |
| | | // String formDataItemJson = JsonUtils.objectToJsonString(dataItem); |
| | | // System.out.println("formDataItemJson = " + formDataItemJson); |
| | | // |
| | | // FormDataItem dataItem1From = JsonUtils.jsonStringToObject(formDataItemJson, FormDataItem.class); |
| | | // System.out.println("formDataItem.value = " + dataItem1From.getValue()); |
| | | // |
| | | // List<String> listFrom = JsonUtils.jsonStringToObject(listJsonString, List.class); |
| | | //// ObjectNode objectNode = new ObjectNode(); |
| | | // System.out.println("listFrom = " + listFrom); |
| | | // |
| | | // // 判断字符串是否json |
| | | //// String noneJsonStr = JsonUtils.objectToJsonString() |
| | | // } |
| | | // |
| | | //// @Test |
| | | // public void testPushMessageType(){ |
| | | //// String input = "tcp && web_socket && wx && system"; |
| | | //// String input = "tcp || web_socket || wx || system"; |
| | | // String input = "tcp "; |
| | | // Object[] data = NotificationUtils.acquireMessagePushRules(input); |
| | | // System.out.println(data[0]); |
| | | // String[] indexList = (String[])data[1]; |
| | | // for(String s : indexList){ |
| | | // System.out.println("index = " + s); |
| | | // } |
| | | System.out.println(typeList1.getClass().getTypeName()); |
| | | |
| | | // 获取对象包含的泛型类型,不能直接通过class定义获得(此时并不知道),只能在运行环境中获得。2022-11-16 |
| | | // ResolvableType t = ResolvableType.forClass(typeList1.getClass()); |
| | | ResolvableType t = ResolvableType.forField(getClass().getDeclaredField("typeList1")); |
| | | System.out.println(t.getGeneric(0).resolve()); |
| | | } |
| | | |
| | | // @Test |
| | | public void testUserPrincipal2Json() throws Exception{ |
| | | S_user_core user = new S_user_core(); |
| | | user.setId(1L); |
| | | user.setUser_name("shikeying"); |
| | | user.setCreate_time(0L); |
| | | user.setNick_name("时工"); |
| | | user.setPassword("$2a$10$9lSwwUFMULR6/KhPsUbTj.0PTZfTnq0fB3OtS6PWoKAibpa8hL1cy"); |
| | | user.setUser_type(2); |
| | | user.setDel_flag(0); |
| | | user.setStatus(0); |
| | | user.setSex("0"); |
| | | user.setOrg_id(0L); |
| | | user.setDept_id(0L); |
| | | user.setAvatar("avatar.jpg"); |
| | | DefaultUserPrincipal userPrincipal = new DefaultUserPrincipal(user); |
| | | |
| | | List<String> roleIdList = new ArrayList<>(4); |
| | | roleIdList.add("role1"); |
| | | roleIdList.add("role2"); |
| | | // userPrincipal.setRoleIdList(roleIdList); |
| | | |
| | | String jsonString = JsonUtils.objectToJsonString(userPrincipal); |
| | | System.out.println("json = " + jsonString); |
| | | |
| | | // DefaultUserPrincipal testUser = JsonUtils.jsonStringToObject(jsonString, DefaultUserPrincipal.class); |
| | | // System.out.println("user = " + testUser.getUserName()); |
| | | ObjectNode objectNode = JsonUtils.jsonStringToObjectNode(jsonString); |
| | | String id = objectNode.get("id").asText(); |
| | | System.out.println("id = " + id); |
| | | |
| | | JsonNode userInfoNode = objectNode.get("userInfo"); |
| | | String userName = userInfoNode.get("user_name").asText(); |
| | | System.out.println("user_name = " + userName); |
| | | |
| | | S_user_core user_core = new S_user_core(); |
| | | user_core.setId(userInfoNode.get("id").asLong()); |
| | | user_core.setUser_name(userInfoNode.get("user_name").asText()); |
| | | user_core.setPassword(userInfoNode.get("password").asText()); |
| | | user_core.setDept_id(userInfoNode.get("dept_id").asLong()); |
| | | user_core.setNick_name(userInfoNode.get("nick_name").asText()); |
| | | user_core.setUser_type(userInfoNode.get("user_type").asInt()); |
| | | user_core.setCreate_time(userInfoNode.get("create_time").asLong()); |
| | | user_core.setOrg_id(userInfoNode.get("org_id").asLong()); |
| | | user_core.setStatus(userInfoNode.get("status").asInt()); |
| | | user_core.setDel_flag(userInfoNode.get("del_flag").asInt()); |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("sex"))){ |
| | | user_core.setSex(userInfoNode.get("sex").asText()); |
| | | } else { |
| | | user_core.setSex("2"); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("phonenumber"))){ |
| | | user_core.setPhonenumber(userInfoNode.get("phonenumber").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("avatar"))){ |
| | | user_core.setAvatar(userInfoNode.get("avatar").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("email"))){ |
| | | user_core.setEmail(userInfoNode.get("email").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("remark"))){ |
| | | user_core.setRemark(userInfoNode.get("remark").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("create_by"))){ |
| | | user_core.setCreate_by(userInfoNode.get("create_by").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("login_date"))){ |
| | | user_core.setLogin_date(userInfoNode.get("login_date").asLong()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("login_ip"))){ |
| | | user_core.setLogin_ip(userInfoNode.get("login_ip").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("update_by"))){ |
| | | user_core.setUpdate_by(userInfoNode.get("update_by").asText()); |
| | | } |
| | | if(!JsonUtils.isEmptyObject(userInfoNode.get("update_time"))){ |
| | | user_core.setUpdate_time(userInfoNode.get("update_time").asLong()); |
| | | } |
| | | |
| | | JsonNode roleIdListJson = objectNode.get("roleIdList"); |
| | | List<String> roleList = new ArrayList<>(4); |
| | | if(roleIdListJson.isArray()){ |
| | | for(Iterator<JsonNode> it = roleIdListJson.iterator(); it.hasNext();){ |
| | | roleList.add(it.next().asText()); |
| | | } |
| | | } |
| | | System.out.println(roleList); |
| | | DefaultUserPrincipal testPrincipal1 = new DefaultUserPrincipal(user_core); |
| | | System.out.println(testPrincipal1); |
| | | } |
| | | |
| | | // @Test |
| | | public void testAcquireUrlFromPerms(){ |
| | | String perms = "system:user:query"; |
| | | // String perms = "system:role:list"; |
| | | String url = MenuUtils.acquireUrlFromPerms(perms); |
| | | System.out.println("perms = " + perms + ", url = " + url); |
| | | } |
| | | } |
| | | // } |
| | | // |
| | | //// @Test |
| | | // public void testGenericType() throws Exception{ |
| | | //// List<String> typeList1 = new ArrayList<String>(); |
| | | // Class type1 = GenericTypeUtils.getSuperClassGenericType(typeList1.getClass()); |
| | | // System.out.println(type1); |
| | | //// Type[] types = typeList1.getClass().getGenericInterfaces(); |
| | | //// TypeVariable[] types = typeList1.getClass().getTypeParameters(); |
| | | //// for(Type type : types){ |
| | | //// System.out.println(type); |
| | | //// } |
| | | // System.out.println(typeList1.getClass().getTypeName()); |
| | | // |
| | | // // 获取对象包含的泛型类型,不能直接通过class定义获得(此时并不知道),只能在运行环境中获得。2022-11-16 |
| | | //// ResolvableType t = ResolvableType.forClass(typeList1.getClass()); |
| | | // ResolvableType t = ResolvableType.forField(getClass().getDeclaredField("typeList1")); |
| | | // System.out.println(t.getGeneric(0).resolve()); |
| | | // } |
| | | // |
| | | //// @Test |
| | | // public void testUserPrincipal2Json() throws Exception{ |
| | | // S_user_core user = new S_user_core(); |
| | | // user.setId(1L); |
| | | // user.setUser_name("shikeying"); |
| | | // user.setCreate_time(0L); |
| | | // user.setNick_name("时工"); |
| | | // user.setPassword("$2a$10$9lSwwUFMULR6/KhPsUbTj.0PTZfTnq0fB3OtS6PWoKAibpa8hL1cy"); |
| | | // user.setUser_type(2); |
| | | // user.setDel_flag(0); |
| | | // user.setStatus(0); |
| | | // user.setSex("0"); |
| | | // user.setOrg_id(0L); |
| | | // user.setDept_id(0L); |
| | | // user.setAvatar("avatar.jpg"); |
| | | // DefaultUserPrincipal userPrincipal = new DefaultUserPrincipal(user); |
| | | // |
| | | // List<String> roleIdList = new ArrayList<>(4); |
| | | // roleIdList.add("role1"); |
| | | // roleIdList.add("role2"); |
| | | //// userPrincipal.setRoleIdList(roleIdList); |
| | | // |
| | | // String jsonString = JsonUtils.objectToJsonString(userPrincipal); |
| | | // System.out.println("json = " + jsonString); |
| | | // |
| | | //// DefaultUserPrincipal testUser = JsonUtils.jsonStringToObject(jsonString, DefaultUserPrincipal.class); |
| | | //// System.out.println("user = " + testUser.getUserName()); |
| | | // ObjectNode objectNode = JsonUtils.jsonStringToObjectNode(jsonString); |
| | | // String id = objectNode.get("id").asText(); |
| | | // System.out.println("id = " + id); |
| | | // |
| | | // JsonNode userInfoNode = objectNode.get("userInfo"); |
| | | // String userName = userInfoNode.get("user_name").asText(); |
| | | // System.out.println("user_name = " + userName); |
| | | // |
| | | // S_user_core user_core = new S_user_core(); |
| | | // user_core.setId(userInfoNode.get("id").asLong()); |
| | | // user_core.setUser_name(userInfoNode.get("user_name").asText()); |
| | | // user_core.setPassword(userInfoNode.get("password").asText()); |
| | | // user_core.setDept_id(userInfoNode.get("dept_id").asLong()); |
| | | // user_core.setNick_name(userInfoNode.get("nick_name").asText()); |
| | | // user_core.setUser_type(userInfoNode.get("user_type").asInt()); |
| | | // user_core.setCreate_time(userInfoNode.get("create_time").asLong()); |
| | | // user_core.setOrg_id(userInfoNode.get("org_id").asLong()); |
| | | // user_core.setStatus(userInfoNode.get("status").asInt()); |
| | | // user_core.setDel_flag(userInfoNode.get("del_flag").asInt()); |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("sex"))){ |
| | | // user_core.setSex(userInfoNode.get("sex").asText()); |
| | | // } else { |
| | | // user_core.setSex("2"); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("phonenumber"))){ |
| | | // user_core.setPhonenumber(userInfoNode.get("phonenumber").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("avatar"))){ |
| | | // user_core.setAvatar(userInfoNode.get("avatar").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("email"))){ |
| | | // user_core.setEmail(userInfoNode.get("email").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("remark"))){ |
| | | // user_core.setRemark(userInfoNode.get("remark").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("create_by"))){ |
| | | // user_core.setCreate_by(userInfoNode.get("create_by").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("login_date"))){ |
| | | // user_core.setLogin_date(userInfoNode.get("login_date").asLong()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("login_ip"))){ |
| | | // user_core.setLogin_ip(userInfoNode.get("login_ip").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("update_by"))){ |
| | | // user_core.setUpdate_by(userInfoNode.get("update_by").asText()); |
| | | // } |
| | | // if(!JsonUtils.isEmptyObject(userInfoNode.get("update_time"))){ |
| | | // user_core.setUpdate_time(userInfoNode.get("update_time").asLong()); |
| | | // } |
| | | // |
| | | // JsonNode roleIdListJson = objectNode.get("roleIdList"); |
| | | // List<String> roleList = new ArrayList<>(4); |
| | | // if(roleIdListJson.isArray()){ |
| | | // for(Iterator<JsonNode> it = roleIdListJson.iterator(); it.hasNext();){ |
| | | // roleList.add(it.next().asText()); |
| | | // } |
| | | // } |
| | | // System.out.println(roleList); |
| | | // DefaultUserPrincipal testPrincipal1 = new DefaultUserPrincipal(user_core); |
| | | // System.out.println(testPrincipal1); |
| | | // } |
| | | // |
| | | //// @Test |
| | | // public void testAcquireUrlFromPerms(){ |
| | | // String perms = "system:user:query"; |
| | | //// String perms = "system:role:list"; |
| | | // String url = MenuUtils.acquireUrlFromPerms(perms); |
| | | // System.out.println("perms = " + perms + ", url = " + url); |
| | | // } |
| | | //} |