Update AAF Version 1.0.0
[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 }\r