Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / adapter_utils / tests / CryptoTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapter_utils.tests;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
27 import java.security.GeneralSecurityException;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.onap.so.utils.CryptoUtils;
31
32 /**
33  * This class implements all test methods of the CryptoUtils features.
34  *
35  *
36  */
37 public class CryptoTest {
38
39     private static String testKey = "546573746F736973546573746F736973";
40
41     /**
42      * This method is called before any test occurs. It creates a fake tree from scratch
43      */
44     @BeforeClass
45     public static final void prepare() {
46
47     }
48
49     /**
50      * This method implements a test of tree structure, mainly the storage of the leaves structure.
51      * 
52      * @throws GeneralSecurityException
53      */
54     @Test
55     public final void testEncryption() throws GeneralSecurityException {
56         String hexString = CryptoUtils.byteArrayToHexString("testosistestosi".getBytes());
57
58         final String testData = "This is a test string";
59         final String nonTestData = "This is not the right String";
60
61         String encodeString = CryptoUtils.encrypt(testData, testKey);
62
63         assertNotNull(encodeString);
64
65         assertTrue(testData.equals(CryptoUtils.decrypt(encodeString, testKey)));
66         assertFalse(nonTestData.equals(CryptoUtils.decrypt(encodeString, testKey)));
67
68         String encode2String = CryptoUtils.encrypt(testData, testKey);
69         assertNotNull(encode2String);
70
71         assertEquals(CryptoUtils.decrypt(encodeString, testKey), CryptoUtils.decrypt(encode2String, testKey));
72
73         encodeString = CryptoUtils.encryptCloudConfigPassword(testData);
74
75         assertEquals(testData, CryptoUtils.decryptCloudConfigPassword(encodeString));
76
77         System.out.println(CryptoUtils.encrypt("poBpmn:password1$", "aa3871669d893c7fb8abbcda31b88b4f"));
78     }
79
80 }