EncryptionTool unit tests
[appc.git] / appc-config / appc-config-adaptor / provider / src / test / java / org / onap / appc / ccadaptor / EncryptionToolTest.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP : APPC\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Copyright (C) 2017 Amdocs\r
8  * =============================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  * \r
13  *      http://www.apache.org/licenses/LICENSE-2.0\r
14  * \r
15  * Unless required by applicable law or agreed to in writing, software\r
16  * distributed under the License is distributed on an "AS IS" BASIS,\r
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18  * See the License for the specific language governing permissions and\r
19  * limitations under the License.\r
20  * \r
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * ============LICENSE_END=========================================================\r
23  */\r
24 \r
25 package org.onap.appc.ccadaptor;\r
26 \r
27 import static org.junit.Assert.assertEquals;\r
28 \r
29 import org.junit.BeforeClass;\r
30 import org.junit.Test;\r
31 \r
32 public class EncryptionToolTest {\r
33 \r
34     private static final String PLAIN_TEXT = "encrypt";\r
35     private static final String ENCRYPTED_TEXT = "enc:JjEZHlg7VQ==";\r
36     private static final String FAKE_ENCRYPTED_TEXT = "jsaASGou!na=e";\r
37 \r
38     private static EncryptionTool encryptionTool;\r
39 \r
40     @BeforeClass\r
41     public static void setup() {\r
42         encryptionTool = EncryptionTool.getInstance();\r
43     }\r
44 \r
45     @Test\r
46     public void should_return_null_when_given_null_to_encrypt() {\r
47         assertEquals(null, encryptionTool.encrypt(null));\r
48     }\r
49 \r
50     @Test\r
51     public void should_encrypt_given_string() {\r
52         assertEquals(ENCRYPTED_TEXT, encryptionTool.encrypt(PLAIN_TEXT));\r
53     }\r
54 \r
55     @Test\r
56     public void should_return_null_when_given_null_to_decrypt() {\r
57         assertEquals(null, encryptionTool.decrypt(null));\r
58     }\r
59 \r
60     @Test\r
61     public void should_return_same_string_when_given_unencrypted_string() {\r
62         assertEquals(FAKE_ENCRYPTED_TEXT, encryptionTool.decrypt(FAKE_ENCRYPTED_TEXT));\r
63     }\r
64 \r
65     @Test\r
66     public void should_decrypt_given_string() {\r
67         assertEquals(PLAIN_TEXT, encryptionTool.decrypt(ENCRYPTED_TEXT));\r
68     }\r
69 }