package com.walker.infrastructure; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import com.walker.infrastructure.arguments.Variable; import com.walker.infrastructure.arguments.VariableType; import com.walker.infrastructure.arguments.support.DefaultGroup; import com.walker.infrastructure.arguments.support.DefaultVariable; import com.walker.infrastructure.arguments.support.XmlArgumentsManager; import com.walker.infrastructure.tree.TreeNode; import com.walker.infrastructure.utils.CollectionUtils; import com.walker.infrastructure.utils.JsonUtils; import com.walker.infrastructure.utils.NetworkUtils; import com.walker.infrastructure.utils.PasswordUtils; import com.walker.infrastructure.utils.StringUtils; import com.walker.infrastructure.utils.WorkingTimeTester; import com.walker.location.DistanceUtils; import com.walker.location.GeoHashHelper; import org.junit.Test; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; //@RunWith(SpringRunner.class) public class TestMain { // @Test public void testLocalIp(){ System.out.println("IP Address: " + NetworkUtils.getLocalHostIp()); } // @Test public void testPasswordFilter(){ // String password = "sdfsdf-9-0;.,~~*&^%$#@!()/\\[]{}"; String password = "sdfsdf-9-0&^%$#@!()"; System.out.println(PasswordUtils.filterText(password)); } // @Test public void testPasswordLevel(){ // String password = "shikeying"; String password = "55677123"; System.out.println(password + "----------->"); System.out.println("一级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_01_LOW)); System.out.println("二级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_02_MEDIUM)); System.out.println("三级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_03_HIGH)); System.out.println("四级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_04_VERY_HIGH)); password = "shikeying123"; System.out.println(password + "----------->"); System.out.println("一级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_01_LOW)); System.out.println("二级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_02_MEDIUM)); System.out.println("三级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_03_HIGH)); System.out.println("四级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_04_VERY_HIGH)); password = "Shikeying123"; System.out.println(password + "----------->"); System.out.println("一级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_01_LOW)); System.out.println("二级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_02_MEDIUM)); System.out.println("三级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_03_HIGH)); System.out.println("四级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_04_VERY_HIGH)); password = "Shikeying@123"; System.out.println(password + "----------->"); System.out.println("一级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_01_LOW)); System.out.println("二级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_02_MEDIUM)); System.out.println("三级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_03_HIGH)); System.out.println("四级安全,结果=" + PasswordUtils.validateComplex(password, PasswordUtils.LEVEL_04_VERY_HIGH)); } // @Test public void testStringToMap() throws Exception{ String json = "{\"92\":\"92号\"}"; json = json.replace("\\", ""); System.out.println(json); Map map = JsonUtils.jsonStringToObject(json, Map.class); System.out.println(map); } // @Test public void testJsonList() throws Exception{ List
list = new ArrayList<>(); list.add(new Address("对象1", 0, 0, null)); list.add(new Address("对象2", 0, 0, null)); list.add(new Address("对象3", 0, 0, null)); String json = JsonUtils.objectToJsonString(list); System.out.println(json); list = JsonUtils.jsonStringToList(json, Address.class); System.out.println(list); } // @Test // public void testMailPush(){ // MailPush mailPush = new DefaultMailPush(); // mailPush.setMailServerHost("smtp.126.com"); // mailPush.setMailServerPort("25"); // mailPush.setFromAddress("hnzzzhsl@126.com"); // mailPush.setFromPassword("UWBUXNLFJEANRCXX"); // mailPush.startup(); // // Notification notification = PushUtils.acquireEmailNotificationOne("测试邮件标题" // , "您的验证码是:0098", "123333@126.com", "pxzsky@163.com", "0"); // try { // PushResult pushResult = mailPush.push(notification); // System.out.println(pushResult); // } catch (PushException e) { // throw new RuntimeException(e); // } // } // @Test public void testGeoDemo(){ GeoHashHelper geoHashHelper = new GeoHashHelper(); List
data = MockUtils.acquireTestAddressList(geoHashHelper); System.out.println(data); // 计算我当前位置geoHash, 113.630199,34.874996 double myLat = 34.874996; double myLng = 113.630199; String myPositionGeoHash = geoHashHelper.encode(myLat,myLng); List aroundList = geoHashHelper.around(myLat, myLng); System.out.println(aroundList); // int geoSearchSize = 4; System.out.println("geoHash_substring = " + aroundList.get(0).substring(0, geoSearchSize)); List
resultList = MockUtils.searchAround(data, aroundList, geoSearchSize); Collections.sort(resultList, new PositionComparator()); for(Address address : resultList){ System.out.println(address.toString() + ", 距离当前位置:" + DistanceUtils.getDistance(address.getLng(), address.getLat(), myLng, myLat)); } } // @Test public void testGeoHash(){ GeoHashHelper geoHashHelper = new GeoHashHelper(); long start = System.currentTimeMillis(); System.out.println(geoHashHelper.around(44.9999, 116.3967)); System.out.println(geoHashHelper.around(45.0001, 116.3967)); // System.out.println(DistanceUtils.getDistance(44.9999, 116.3967, 45.0001, 116.3967)); System.out.println(DistanceUtils.getDistance(116.3967, 44.9999, 116.3967, 45.0001)); System.out.println("waste time: " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); System.out.println(geoHashHelper.encode(44.9999, 116.3967)); System.out.println(geoHashHelper.encode(45.0001, 116.3967)); System.out.println("waste time: " + (System.currentTimeMillis() - start)); } // @Test public void testCamelName2Underline(){ // String input = "DemoUserCore"; // String input = "DemoUser_core"; // String input = "DemoUser_"; String input = "SConfigExt"; System.out.println(StringUtils.transferCamelName2Underline(input)); } // @Test public void testJava2ObjectNode(){ TreeNode treeNode = new TreeNode(1, "root", null, 0); ObjectNode objectNode = JsonUtils.javaObjectToObjectNode(treeNode); System.out.println(objectNode); String key = null; JsonNode jsonNode = null; Map.Entry entry = null; for(Iterator> it = objectNode.fields(); it.hasNext();){ entry = it.next(); System.out.println("key = " + entry.getKey() + ", value = " + entry.getValue()); jsonNode = entry.getValue(); if(jsonNode == null){ System.out.println("......... null"); } else if(jsonNode.isLong()){ System.out.println("......... " + entry.getKey() + " is Long = " + jsonNode.longValue()); } else if(jsonNode.isTextual()){ String v = jsonNode.asText(); System.out.println("......... " + entry.getKey() + " is String = " + v); } System.out.println("=============================="); // System.out.println("getLabel() = " + jsonNode.get("label").asText()); System.out.println(jsonNode); } Map map = new HashMap<>(2); map.put("id", 10); map.put("name", "shikeying"); System.out.println(map); System.out.println("去掉双引号:" + "shikeying\"".replace(StringUtils.STRING_DOUBLE_MARK, "")); } // @Test public void testShuffle(){ List data = new ArrayList<>(64); data.add("数据:1"); data.add("数据:2"); data.add("数据:3"); data.add("数据:4"); data.add("数据:5"); data.add("数据:6"); data.add("数据:7"); data.add("数据:8"); data.add("数据:9"); CollectionUtils.shuffleLittle(data, 10); System.out.println(data); System.out.println("============================="); CollectionUtils.shuffleLittle(data, 30); System.out.println(data); System.out.println("============================="); CollectionUtils.shuffleLittle(data, 50); System.out.println(data); System.out.println("============================="); CollectionUtils.shuffleLittle(data, 80); System.out.println(data); System.out.println("============================="); } // @Test public void testHttpLink(){ // String link = "https://www.baidu.com/service/adsfsdf?q=sdfsfdsf"; String link = "tcp://www.baidu.com/service/adsfsdf?q=sdfsfdsf"; System.out.println(StringUtils.isHttpLink(link)); } // @Test public void testJsonArrayNode() throws Exception{ String jsonArray = "[1,2,3,4,5]"; ArrayNode arrayNode = JsonUtils.toJsonArray(jsonArray); for(int i=0; i argList = new ArrayList(); argList.add(args1); argList.add(args2); argumentManager.persist(argList); // argumentManager.persist("1", "11", 56); Variable v2 = argumentManager.getVariable("21"); System.out.println("修改后缓存: " + v2.getStringValue()); // 添加一个节点 DefaultGroup group2 = new DefaultGroup(); group2.setId("testGroup2"); group2.setName("系统提醒"); group2.setOrder(8); DefaultVariable v = new DefaultVariable(); v.setId("smtp.mail.address"); v.setDescription("邮件发送地址"); v.setType(VariableType.String); v.setValue("smtp.163.com"); v.setDefaultValue("smtp.mymail.net"); List insertList = new ArrayList(); insertList.add(new Object[]{group2, v}); argumentManager.insert(insertList); } }