1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package org.onap.aaf.cadi.test;
\r
25 import org.junit.Test;
\r
26 import org.onap.aaf.cadi.CadiException;
\r
27 import org.onap.aaf.cadi.Hash;
\r
29 import junit.framework.Assert;
\r
31 public class JU_Hash {
\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
43 init =hashed.substring(1);
\r
45 hashed = Hash.fromHex(init).toString();
\r
46 Assert.fail("Should have thrown Exception");
\r
47 } catch (CadiException e) {
\r
51 init = hashed.replace('1', '~');
\r
53 hashed = Hash.fromHex(init).toString();
\r
54 Assert.fail("Should have thrown Exception");
\r
55 } catch (CadiException e) {
\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
70 init =hashed.substring(1);
\r
72 hashed = Hash.fromHex(init).toString();
\r
73 Assert.fail("Should have thrown Exception");
\r
74 } catch (CadiException e) {
\r
78 init = hashed.replace('1', '~');
\r
80 hashed = Hash.fromHex(init).toString();
\r
81 Assert.fail("Should have thrown Exception");
\r
82 } catch (CadiException e) {
\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
98 init =hashed.substring(1);
\r
100 hashed = Hash.fromHex(init).toString();
\r
101 Assert.fail("Should have thrown Exception");
\r
102 } catch (CadiException e) {
\r
106 init = hashed.replace('1', '~');
\r
108 hashed = Hash.fromHex(init).toString();
\r
109 Assert.fail("Should have thrown Exception");
\r
110 } catch (CadiException e) {
\r