Fix request handler class error
[appc.git] / appc-common / src / test / java / org / onap / appc / encryption / EncryptionToolTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.encryption;
25
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;
31
32 import org.junit.Test;
33
34 public class EncryptionToolTest {
35
36     private static final String PLAIN_TEXT = "text to encrypt";
37     private static final String EMPTY_STR = "";
38
39     private EncryptionTool encryptionTool = EncryptionTool.getInstance();
40
41     @Test
42     public void should_return_prefix_given_empty_string() {
43         assertEquals("enc:", encryptionTool.encrypt(EMPTY_STR));
44     }
45
46     @Test
47     public void should_return_null_given_null() {
48         assertNull(encryptionTool.encrypt(null));
49     }
50
51     @Test
52     public void should_encrypt_given_string() {
53         String encrypted = encryptionTool.encrypt(PLAIN_TEXT);
54
55         assertNotEquals(encrypted, PLAIN_TEXT);
56         assertTrue(encrypted.startsWith(EncryptionTool.ENCRYPTED_VALUE_PREFIX));
57     }
58
59     @Test
60     public void should_not_decrypt_string_when_not_starting_with_prefix() {
61
62         assertNull(encryptionTool.decrypt(null));
63         assertEquals("mdi/12!dsao91", encryptionTool.decrypt("mdi/12!dsao91"));
64     }
65
66     @Test
67     public void should_decrypt_given_encrypted_string() {
68         String encrypted = encryptionTool.encrypt(PLAIN_TEXT);
69
70         assertEquals(PLAIN_TEXT, encryptionTool.decrypt(encrypted));
71     }
72 }