From 5b497dcd3a51493f20e56523166f3dee39c664fd Mon Sep 17 00:00:00 2001 From: tiangao1102 Date: Mon, 16 May 2016 23:19:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=96=87=E4=BB=B6=20=E5=8A=A0=E5=AF=86?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E6=B5=8B=E8=AF=95=20CryptosTest=20?= =?UTF-8?q?=E7=AD=BE=E5=90=8D=E5=B7=A5=E5=85=B7=E7=B1=BB=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=20DigestsTest=20Http=E5=B7=A5=E5=85=B7=E7=B1=BB=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=20HttpUtilTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加测试输入流签名的文件 test_md5.txt --- .../java/com/jfinal/utils/CryptosTest.java | 49 ++++++++++++++ .../java/com/jfinal/utils/DigestsTest.java | 56 ++++++++++++++++ .../com/jfinal/utils/http/HttpUtilTest.java | 64 +++++++++++++++++++ src/test/resources/test_md5.txt | 1 + 4 files changed, 170 insertions(+) create mode 100644 src/test/java/com/jfinal/utils/CryptosTest.java create mode 100644 src/test/java/com/jfinal/utils/DigestsTest.java create mode 100644 src/test/java/com/jfinal/utils/http/HttpUtilTest.java create mode 100644 src/test/resources/test_md5.txt diff --git a/src/test/java/com/jfinal/utils/CryptosTest.java b/src/test/java/com/jfinal/utils/CryptosTest.java new file mode 100644 index 0000000..e0c76b1 --- /dev/null +++ b/src/test/java/com/jfinal/utils/CryptosTest.java @@ -0,0 +1,49 @@ +package com.jfinal.utils; + +import static org.junit.Assert.*; + +/** + * Created by tiangao on 2016/5/16. + */ +public class CryptosTest { + + @org.junit.Test + public void testHmacSha1() throws Exception { + //TODO Cryptos.hmacSha1(); + } + + @org.junit.Test + public void testIsMacValid() throws Exception { + + } + + @org.junit.Test + public void testAesEncrypt() throws Exception { + String plainText = "hello world!"; + byte[] keyBytes = Cryptos.generateAesKey(); + + System.out.println("key: " + bytes2HexStr(keyBytes)); + byte[] cryptBytes = Cryptos.aesEncrypt(plainText.getBytes(), keyBytes); + + System.out.println("CryptText: " + bytes2HexStr(cryptBytes)); + assertEquals(new String(Cryptos.aesDecrypt(cryptBytes, keyBytes)), plainText); + + //TODO AES的绝对准确性有待确认 + } + + String bytes2HexStr(byte[] bytes) { + StringBuilder builder = new StringBuilder(); + if (bytes == null || bytes.length <= 0) { + return null; + } + for (int i = 0; i < bytes.length; i++) { + int v = bytes[i] & 0xFF; + String hv = Integer.toHexString(v); + if (hv.length() < 2) { + builder.append(0); + } + builder.append(hv); + } + return builder.toString(); + } +} \ No newline at end of file diff --git a/src/test/java/com/jfinal/utils/DigestsTest.java b/src/test/java/com/jfinal/utils/DigestsTest.java new file mode 100644 index 0000000..39faa47 --- /dev/null +++ b/src/test/java/com/jfinal/utils/DigestsTest.java @@ -0,0 +1,56 @@ +package com.jfinal.utils; + +import org.junit.Test; + +import java.io.*; + +import static org.junit.Assert.*; + +/** + * Created by tiangao on 2016/5/16. + */ +public class DigestsTest { + + final String text = "hello world!"; + + @Test + public void testSha1() throws Exception { + //TODO SHA1编码识别问题有待研究 + String sha1Code = "430ce34d020724ed75a196dfc2ad67c77772d169"; + assertEquals(Digests.sha1(text.getBytes()), sha1Code.getBytes()); + } + + @Test + public void testMd5() throws Exception { + String md5Code = "fc3ff98e8c6a0d3087d515c0473f8677"; + //String 参数测试 + assertEquals(Digests.md5(text), md5Code); + + //bytes 参数测试 + assertEquals(Digests.md5(text.getBytes()), md5Code); + + + //InputStream 参数测试 + String filePath = getClass().getClassLoader().getResource("test_md5.txt").getPath(); +// BufferedReader reader = new BufferedReader(new FileReader(filePath)); +// System.out.print(reader.readLine()); + //TODO 不知道是不是换行符或者空格的问题 + assertEquals(Digests.md5(new FileInputStream(filePath)), md5Code); + + } + + @Test + public void testCrc32() throws Exception { + + } + + @Test + public void testCrc32AsLong() throws Exception { + + } + + @Test + public void testMurmur32() throws Exception { + + } +} \ No newline at end of file diff --git a/src/test/java/com/jfinal/utils/http/HttpUtilTest.java b/src/test/java/com/jfinal/utils/http/HttpUtilTest.java new file mode 100644 index 0000000..dcfa351 --- /dev/null +++ b/src/test/java/com/jfinal/utils/http/HttpUtilTest.java @@ -0,0 +1,64 @@ +package com.jfinal.utils.http; + +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +import static org.junit.Assert.*; + +/** + * Created by tiangao on 2016/5/16. + */ +public class HttpUtilTest { + + /** + * HttpUtil get请求测试 + * @throws Exception + */ + @Test + public void testGet() throws Exception { + //get 直接访问 + assertEquals(HttpUtil.get("http://dashen2048.applinzi.com/test.php"), "1234qwer."); + + //get 带参数Map的访问 + Map paramsMap = new HashMap<>(); + paramsMap.put("name", "wow"); + assertEquals(HttpUtil.get("http://dashen2048.applinzi.com/test.php", paramsMap), "1234qwer. name:wow"); + paramsMap.put("pwd", "wow123"); + assertEquals(HttpUtil.get("http://dashen2048.applinzi.com/test.php", paramsMap), "1234qwer. name:wow"); + + //get 空参数Map + paramsMap.clear(); + assertEquals(HttpUtil.get("http://dashen2048.applinzi.com/test.php", paramsMap), "1234qwer."); + } + + @Test + public void testPost() throws Exception { + //post 直接访问 + assertEquals(HttpUtil.post("http://dashen2048.applinzi.com/test.php"), "1234qwer."); + + //post 带参数访问 + Map paramsMap = new HashMap<>(); + paramsMap.put("type", "wow"); + assertEquals(HttpUtil.post("http://dashen2048.applinzi.com/test.php", paramsMap), "1234qwer. type:wow"); + paramsMap.put("res", "wow123"); + assertEquals(HttpUtil.post("http://dashen2048.applinzi.com/test.php", paramsMap), "1234qwer. type:wow,res:wow123"); + } + + @Test + public void testPostSSL() throws Exception { + //TODO Https方式待研究 + } + + @Test + public void testDownload() throws Exception { + //TODO + } + + @Test + public void testUpload() throws Exception { + //TODO + } +} \ No newline at end of file diff --git a/src/test/resources/test_md5.txt b/src/test/resources/test_md5.txt new file mode 100644 index 0000000..bc7774a --- /dev/null +++ b/src/test/resources/test_md5.txt @@ -0,0 +1 @@ +hello world! \ No newline at end of file -- Gitee From 849e5a26bcb44565f9332f8224814927ed0d475d Mon Sep 17 00:00:00 2001 From: shitg Date: Tue, 17 May 2016 09:35:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?CollectionTest=20=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/jfinal/utils/Collections3Test.java | 116 ++++++++++++++++++ src/test/resources/collectionCase.json | 6 + 2 files changed, 122 insertions(+) create mode 100644 src/test/java/com/jfinal/utils/Collections3Test.java create mode 100644 src/test/resources/collectionCase.json diff --git a/src/test/java/com/jfinal/utils/Collections3Test.java b/src/test/java/com/jfinal/utils/Collections3Test.java new file mode 100644 index 0000000..af2ce53 --- /dev/null +++ b/src/test/java/com/jfinal/utils/Collections3Test.java @@ -0,0 +1,116 @@ +package com.jfinal.utils; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.*; + +/** + * Created by shitiangao on 16/5/16. + */ +public class Collections3Test { + + private Collection intCollectionA; + private Collection intCollectionB; + + private Collection strCollectionA; + private Collection strCollectionB; + + /** + * 初始化两组测试数据 + */ + @Before + public void initCollections() { + intCollectionA = Arrays.asList(1,2,3,4,5,6); + intCollectionB = Arrays.asList(4,5,6,7,8,90); + + strCollectionA = Arrays.asList("a", "b", "c", "d", "e"); + strCollectionB = Arrays.asList("a", "c", "d", "g", "h"); + } + + /** + * ce + * @throws Exception + */ + @Test + public void testGetFirst() throws Exception { + assertEquals((int) Collections3.getFirst(intCollectionA), 1); + assertEquals((int) Collections3.getFirst(intCollectionB), 4); + + assertEquals(Collections3.getFirst(strCollectionA), "a"); + assertEquals(Collections3.getFirst(strCollectionB), "a"); + + } + + @Test + public void testGetLast() throws Exception { + + assertEquals((int) Collections3.getLast(intCollectionA), 6); + assertEquals((int) Collections3.getLast(intCollectionB), 90); + + assertEquals(Collections3.getLast(strCollectionA), "e"); + assertEquals(Collections3.getLast(strCollectionB), "h"); + } + + @Test + public void testUnion() throws Exception { + Collection intResult = Arrays.asList(1, 2, 3, 4, 5, 6, 4, 5, 6, 7, 8, 90); + assertEquals(Collections3.union(intCollectionA, intCollectionB), intResult); + + Collection strResult = Arrays.asList("a", "b", "c", "d", "e", "a", "c", "d", "g", "h"); + assertEquals(Collections3.union(strCollectionA, strCollectionB), strResult); + } + + @Test + public void testSubtract() throws Exception { + + } + + @Test + public void testIntersection() throws Exception { + + } + + @Test + public void testAsList() throws Exception { + + } + + @Test + public void testAsList1() throws Exception { + + } + + @Test + public void testAsList2() throws Exception { + + } + + @Test + public void testExtractToMap() throws Exception { + + } + + @Test + public void testExtractToList() throws Exception { + + } + + @Test + public void testExtractToString() throws Exception { + + } + + @Test + public void testConvertToString() throws Exception { + + } + + @Test + public void testConvertToString1() throws Exception { + + } +} \ No newline at end of file diff --git a/src/test/resources/collectionCase.json b/src/test/resources/collectionCase.json new file mode 100644 index 0000000..9310ace --- /dev/null +++ b/src/test/resources/collectionCase.json @@ -0,0 +1,6 @@ +{ + "TestCases":[ + {"colA":[1,2,3,4,5], "colB":[2,9,4,5], "A_first":1, "B_first":2, "A_last":5, "B_last":5, + "unionRes":[1,2,3,4,5,2,9,4,5], "subtractRes": [1,2,3]} + ] +} \ No newline at end of file -- Gitee From dc5571c0ca6e7e7e8d0f3ec3cb7d7e03b34e4a55 Mon Sep 17 00:00:00 2001 From: shitg Date: Wed, 18 May 2016 17:23:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?pom=20=E4=B8=AD=E4=B8=BA=20easymock=20?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E6=B7=BB=E5=8A=A0=20socpe=20=E4=B8=BA=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index df3db33..0a76ca7 100644 --- a/pom.xml +++ b/pom.xml @@ -82,6 +82,7 @@ org.easymock easymock ${easymock.version} + test -- Gitee