From 1275e425d9064fed66532aa2fddb34023dfd99b6 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Thu, 15 Mar 2018 11:52:18 +0100 Subject: EncryptionTool unit tests Improved code coverage. Change-Id: I8882a9fd274b4ce03ef784aac89cdfbb786af4fe Issue-ID: APPC-742 Signed-off-by: Jakub Dudycz --- .../onap/appc/encryption/EncryptionToolTest.java | 73 ++++++++++++++++++++++ .../org/onap/appc/encryption/TestEncryption.java | 46 -------------- 2 files changed, 73 insertions(+), 46 deletions(-) create mode 100644 appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java delete mode 100644 appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java (limited to 'appc-common') diff --git a/appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java b/appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java new file mode 100644 index 000000000..15b7e55f3 --- /dev/null +++ b/appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.onap.appc.encryption; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class EncryptionToolTest { + + private static final String PLAIN_TEXT = "text to encrypt"; + private static final String EMPTY_STR = ""; + + private EncryptionTool encryptionTool = EncryptionTool.getInstance(); + + @Test + public void should_return_prefix_given_empty_string() { + assertEquals("enc:", encryptionTool.encrypt(EMPTY_STR)); + } + + @Test + public void should_return_null_given_null() { + assertNull(encryptionTool.encrypt(null)); + } + + @Test + public void should_encrypt_given_string() { + String encrypted = encryptionTool.encrypt(PLAIN_TEXT); + + assertNotEquals(encrypted, PLAIN_TEXT); + assertTrue(encrypted.startsWith(EncryptionTool.ENCRYPTED_VALUE_PREFIX)); + } + + @Test + public void should_not_decrypt_string_when_not_starting_with_prefix() { + + assertNull(encryptionTool.decrypt(null)); + assertEquals("mdi/12!dsao91", encryptionTool.decrypt("mdi/12!dsao91")); + } + + @Test + public void should_decrypt_given_encrypted_string() { + String encrypted = encryptionTool.encrypt(PLAIN_TEXT); + + assertEquals(PLAIN_TEXT, encryptionTool.decrypt(encrypted)); + } +} diff --git a/appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java b/appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java deleted file mode 100644 index aa9664d2e..000000000 --- a/appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java +++ /dev/null @@ -1,46 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.onap.appc.encryption; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; - -import org.junit.Test; -import org.onap.appc.encryption.EncryptionTool; - -public class TestEncryption { - - @Test - public void testEncryptionDecryption() { - String plain = "AppC"; - String enc = EncryptionTool.getInstance().encrypt(plain); - assertNotEquals(plain, enc); - String dec = EncryptionTool.getInstance().decrypt(enc); - assertNotEquals(enc, dec); - assertEquals(plain, dec); - System.out.println(String.format("%s = [%s]", plain, enc)); - } - -} -- cgit 1.2.3-korg