e5d2d6bc1eb0c22960e0e8c5f443b0069c29ed7e
[aaf/cadi.git] / core / src / test / java / com / att / 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 com.att.cadi.test;\r
24 \r
25 import org.junit.Test;\r
26 \r
27 import com.att.cadi.CadiException;\r
28 import com.att.cadi.Hash;\r
29 \r
30 import junit.framework.Assert;\r
31 \r
32 public class JU_Hash {\r
33 \r
34         @Test\r
35         public void test() throws CadiException {\r
36                 String init = "m82347@csp.att.com:kumquat8rie@#Tomatos3";\r
37                 String hashed = Hash.toHex(init.getBytes());\r
38                 System.out.println(hashed);\r
39                 byte[] ba = Hash.fromHex(hashed);\r
40                 String recon = new String(ba);\r
41                 System.out.println(recon);\r
42                 Assert.assertEquals(init, recon);\r
43                 \r
44                 init =hashed.substring(1);\r
45                 try {\r
46                         hashed = Hash.fromHex(init).toString();\r
47                         Assert.fail("Should have thrown Exception");\r
48                 } catch (CadiException e) {\r
49                         \r
50                 }\r
51                 \r
52                 init = hashed.replace('1', '~');\r
53                 try {\r
54                         hashed = Hash.fromHex(init).toString();\r
55                         Assert.fail("Should have thrown Exception");\r
56                 } catch (CadiException e) {\r
57                         \r
58                 }\r
59         }\r
60 \r
61 }\r