f79564d649c3e8de55cc2f954c0732a4dc6f95b4
[aaf/cadi.git] / core / src / test / java / org / onap / aaf / cadi / test / JU_Hash.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cadi.test;\r
24 \r
25 import org.junit.Test;\r
26 import org.onap.aaf.cadi.CadiException;\r
27 import org.onap.aaf.cadi.Hash;\r
28 \r
29 import junit.framework.Assert;\r
30 \r
31 public class JU_Hash {\r
32 \r
33         @Test\r
34         public void test() throws CadiException {\r
35                 String init = "m82347@csp.att.com:kumquat8rie@#Tomatos3";\r
36                 String hashed = Hash.toHex(init.getBytes());\r
37                 System.out.println(hashed);\r
38                 byte[] ba = Hash.fromHex(hashed);\r
39                 String recon = new String(ba);\r
40                 System.out.println(recon);\r
41                 Assert.assertEquals(init, recon);\r
42                 \r
43                 init =hashed.substring(1);\r
44                 try {\r
45                         hashed = Hash.fromHex(init).toString();\r
46                         Assert.fail("Should have thrown Exception");\r
47                 } catch (CadiException e) {\r
48                         \r
49                 }\r
50                 \r
51                 init = hashed.replace('1', '~');\r
52                 try {\r
53                         hashed = Hash.fromHex(init).toString();\r
54                         Assert.fail("Should have thrown Exception");\r
55                 } catch (CadiException e) {\r
56                         \r
57                 }\r
58         }\r
59 \r
60         @Test\r
61         public void test1() throws CadiException {\r
62                 String init = "m8234337@csp.att.com:kumquat8rie@#Tomatos3";\r
63                 String hashed = Hash.toHex(init.getBytes());\r
64                 System.out.println(hashed);\r
65                 byte[] ba = Hash.fromHex(hashed);\r
66                 String recon = new String(ba);\r
67                 System.out.println(recon);\r
68                 Assert.assertEquals(init, recon);\r
69                 \r
70                 init =hashed.substring(1);\r
71                 try {\r
72                         hashed = Hash.fromHex(init).toString();\r
73                         Assert.fail("Should have thrown Exception");\r
74                 } catch (CadiException e) {\r
75                         \r
76                 }\r
77                 \r
78                 init = hashed.replace('1', '~');\r
79                 try {\r
80                         hashed = Hash.fromHex(init).toString();\r
81                         Assert.fail("Should have thrown Exception");\r
82                 } catch (CadiException e) {\r
83                         \r
84                 }\r
85         }\r
86 \r
87         \r
88         @Test\r
89         public void test2() throws CadiException {\r
90                 String init = "m823475@csp.att.com:kumquat8rie@#Tomatos3";\r
91                 String hashed = Hash.toHex(init.getBytes());\r
92                 System.out.println(hashed);\r
93                 byte[] ba = Hash.fromHex(hashed);\r
94                 String recon = new String(ba);\r
95                 System.out.println(recon);\r
96                 Assert.assertEquals(init, recon);\r
97                 \r
98                 init =hashed.substring(1);\r
99                 try {\r
100                         hashed = Hash.fromHex(init).toString();\r
101                         Assert.fail("Should have thrown Exception");\r
102                 } catch (CadiException e) {\r
103                         \r
104                 }\r
105                 \r
106                 init = hashed.replace('1', '~');\r
107                 try {\r
108                         hashed = Hash.fromHex(init).toString();\r
109                         Assert.fail("Should have thrown Exception");\r
110                 } catch (CadiException e) {\r
111                         \r
112                 }\r
113         }\r
114 \r
115 }\r