From bbc49d304603dd4cccade55cc5f5711df3024592 Mon Sep 17 00:00:00 2001 From: Jakub Dudycz Date: Mon, 12 Mar 2018 13:53:32 +0100 Subject: EncryptionTool unit tests Improved code coverage + some test class refactor. Change-Id: I7e3637c07b580acea383d1ccfd6a0608f69109fe Issue-ID: APPC-722 Signed-off-by: Jakub Dudycz --- .../onap/appc/ccadaptor/EncryptionToolTest.java | 53 ++++++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'appc-config/appc-config-adaptor') diff --git a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/EncryptionToolTest.java b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/EncryptionToolTest.java index afa9137db..00e036ce3 100644 --- a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/EncryptionToolTest.java +++ b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/EncryptionToolTest.java @@ -1,9 +1,9 @@ /*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ + * ============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"); @@ -18,29 +18,52 @@ * 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. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. * ============LICENSE_END========================================================= */ package org.onap.appc.ccadaptor; -import org.junit.Assert; +import static org.junit.Assert.assertEquals; + +import org.junit.BeforeClass; import org.junit.Test; public class EncryptionToolTest { + private static final String PLAIN_TEXT = "encrypt"; + private static final String ENCRYPTED_TEXT = "enc:JjEZHlg7VQ=="; + private static final String FAKE_ENCRYPTED_TEXT = "jsaASGou!na=e"; + + private static EncryptionTool encryptionTool; + + @BeforeClass + public static void setup() { + encryptionTool = EncryptionTool.getInstance(); + } + @Test - public void testEncrypt() { - EncryptionTool tool = EncryptionTool.getInstance(); - String value = tool.encrypt("encrypt"); - Assert.assertEquals("enc:JjEZHlg7VQ==", value); + public void should_return_null_when_given_null_to_encrypt() { + assertEquals(null, encryptionTool.encrypt(null)); } @Test - public void testDecrypt() { - EncryptionTool tool = EncryptionTool.getInstance(); - String value = tool.decrypt("enc:JjEZHlg7VQ=="); - Assert.assertEquals("encrypt", value); + public void should_encrypt_given_string() { + assertEquals(ENCRYPTED_TEXT, encryptionTool.encrypt(PLAIN_TEXT)); } + @Test + public void should_return_null_when_given_null_to_decrypt() { + assertEquals(null, encryptionTool.decrypt(null)); + } + + @Test + public void should_return_same_string_when_given_unencrypted_string() { + assertEquals(FAKE_ENCRYPTED_TEXT, encryptionTool.decrypt(FAKE_ENCRYPTED_TEXT)); + } + + @Test + public void should_decrypt_given_string() { + assertEquals(PLAIN_TEXT, encryptionTool.decrypt(ENCRYPTED_TEXT)); + } } \ No newline at end of file -- cgit 1.2.3-korg