2 * ============LICENSE_START=============================================================================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * ===================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS
14 * OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END===============================================================================================================
20 package org.onap.appc.flow.controller.utils;
22 import static org.junit.Assert.*;
24 import org.junit.Test;
26 public class EncryptionToolTest {
29 public final void testGetInstance() {
30 String encrypted = EncryptionTool.getInstance().encrypt("AbCdEf");
31 assertNotNull(encrypted);
35 public final void testGetInstanceTwice() {
36 String encrypted = EncryptionTool.getInstance().encrypt("GhIjKl");
37 assertNotNull(encrypted);
38 assertEquals(encrypted, "enc:BDczBmon");
39 String encrypted2 = EncryptionTool.getInstance().encrypt("MNOPQR");
40 assertNotNull(encrypted2);
41 assertEquals(encrypted2, "enc:DhE1PHAZ");
45 public void testAll() {
46 String plainText = "AnyString123";
47 String encrypted = EncryptionTool.getInstance().encrypt(plainText);
48 assertNotEquals(plainText, encrypted);
49 String dec = EncryptionTool.getInstance().decrypt(encrypted);
50 assertNotEquals(encrypted, dec);
51 assertEquals(plainText, dec);
52 System.out.println(String.format("%s = [%s]", plainText, encrypted));
56 public final void testDecrypt() {
57 String decrypted = EncryptionTool.getInstance().decrypt("enc:BBczJmoH");
58 assertNotNull(decrypted);
59 assertEquals(decrypted, "GHIJKL");
61 String decrypted2 = EncryptionTool.getInstance().decrypt("BBczJmoH");
62 assertEquals(decrypted2, "BBczJmoH");
66 public final void testEncrypt() {
67 String encrypted = EncryptionTool.getInstance().encrypt("GHIJKL");
68 assertEquals(encrypted, "enc:BBczJmoH");
72 public final void testIsEncrytpedWithNull() {
74 String encrypted = EncryptionTool.getInstance().encrypt(null);
75 assertNull(encrypted);