shikeying
2024-01-11 3b67e947e36133e2a40eb2737b15ea375e157ea0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
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<String, String> map = JsonUtils.jsonStringToObject(json, Map.class);
        System.out.println(map);
    }
 
//    @Test
    public void testJsonList() throws Exception{
        List<Address> 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<Address> 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<String> aroundList = geoHashHelper.around(myLat, myLng);
        System.out.println(aroundList);
 
        //
        int geoSearchSize = 4;
        System.out.println("geoHash_substring = " + aroundList.get(0).substring(0, geoSearchSize));
        List<Address> 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<String, JsonNode> entry = null;
        for(Iterator<Map.Entry<String, JsonNode>> 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<String, Object> 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<String> 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<arrayNode.size(); i++){
            System.out.println(arrayNode.get(i).toString());
        }
    }
 
//    @Test
    public void testArgumentManager() throws Exception{
        XmlArgumentsManager argumentManager = new XmlArgumentsManager();
        argumentManager.setClasspathFileName("app_variables.xml");
        argumentManager.setSource("test");
        argumentManager.afterPropertiesSet();
        System.out.println(argumentManager.getVariableList("SYSTEM.SUPERPASS"));
 
        System.out.println("+++ 分组信息: " + argumentManager.getGroupList());
 
        WorkingTimeTester tester = new WorkingTimeTester("var");
        Variable var = argumentManager.getVariable("APP.LOGIN_MULTI_TERM");
        System.out.println("--分页数:" + var.getBooleanValue());
        tester.stop();
 
        Object[] args1 = new Object[]{"1", "11", 88};
        Object[] args2 = new Object[]{"2", "21", "修改过企业名称"};
        List<Object[]> argList = new ArrayList<Object[]>();
        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<Object[]> insertList = new ArrayList<Object[]>();
        insertList.add(new Object[]{group2, v});
        argumentManager.insert(insertList);
    }
 
}