2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.encryption;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28 import static org.junit.Assert.assertNotEquals;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.assertTrue;
32 import org.junit.Test;
34 public class EncryptionToolTest {
36 private static final String PLAIN_TEXT = "text to encrypt";
37 private static final String EMPTY_STR = "";
39 private EncryptionTool encryptionTool = EncryptionTool.getInstance();
42 public void should_return_prefix_given_empty_string() {
43 assertEquals("enc:", encryptionTool.encrypt(EMPTY_STR));
47 public void should_return_null_given_null() {
48 assertNull(encryptionTool.encrypt(null));
52 public void should_encrypt_given_string() {
53 String encrypted = encryptionTool.encrypt(PLAIN_TEXT);
55 assertNotEquals(encrypted, PLAIN_TEXT);
56 assertTrue(encrypted.startsWith(EncryptionTool.ENCRYPTED_VALUE_PREFIX));
60 public void should_not_decrypt_string_when_not_starting_with_prefix() {
62 assertNull(encryptionTool.decrypt(null));
63 assertEquals("mdi/12!dsao91", encryptionTool.decrypt("mdi/12!dsao91"));
67 public void should_decrypt_given_encrypted_string() {
68 String encrypted = encryptionTool.encrypt(PLAIN_TEXT);
70 assertEquals(PLAIN_TEXT, encryptionTool.decrypt(encrypted));