summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Dudycz <jakub.dudycz@nokia.com>2018-03-15 11:52:18 +0100
committerTakamune Cho <tc012c@att.com>2018-03-15 15:01:01 +0000
commit1275e425d9064fed66532aa2fddb34023dfd99b6 (patch)
tree72344a3b24bfd6d0c314a6afaf5c68ce68945831
parentb07e24e1886252cba634e17d6ccb8ced1cdfcbcb (diff)
EncryptionTool unit tests
Improved code coverage. Change-Id: I8882a9fd274b4ce03ef784aac89cdfbb786af4fe Issue-ID: APPC-742 Signed-off-by: Jakub Dudycz <jakub.dudycz@nokia.com>
-rw-r--r--appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java (renamed from appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java)47
1 files changed, 37 insertions, 10 deletions
diff --git a/appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java b/appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java
index aa9664d2e..15b7e55f3 100644
--- a/appc-common/src/test/java/org/onap/appc/encryption/TestEncryption.java
+++ b/appc-common/src/test/java/org/onap/appc/encryption/EncryptionToolTest.java
@@ -25,22 +25,49 @@
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;
-import org.onap.appc.encryption.EncryptionTool;
-public class TestEncryption {
+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 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));
+ 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));
+ }
}