aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java (renamed from src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java)54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java
index f03fe83c7..6fe447556 100644
--- a/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java
+++ b/src/test/java/org/onap/clamp/clds/util/CryptoUtilsTest.java
@@ -21,56 +21,60 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.clamp.clds.it;
+package org.onap.clamp.clds.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
+import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.onap.clamp.clds.util.CryptoUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.context.TestPropertySource;
-import org.springframework.test.context.junit4.SpringRunner;
/**
* Test Crypto Utils with Spring.
*/
-@RunWith(SpringRunner.class)
-@SpringBootTest
-@TestPropertySource(locations = "classpath:application-no-camunda.properties")
-public class CryptoUtilsItCase {
- @Autowired
- private CryptoUtils cryptoUtils;
+public class CryptoUtilsTest {
+ private CryptoUtils cryptoUtils = new CryptoUtils();
+ final String data = "This is a test string";
/**
* This method tests encryption.
*
* @throws GeneralSecurityException
+ * @throws DecoderException
+ * @throws UnsupportedEncodingException
*/
@Test
- public final void testEncryption() throws GeneralSecurityException {
- final String testData = "This is a test string";
- final String encodedStringExpected = "A5CB112C9F608A220B35AFED08024D98B9653333AF4C9527C2E934DE473F6145";
- String encodedString = cryptoUtils.encrypt(testData);
+ public final void testEncryption() throws GeneralSecurityException, DecoderException, UnsupportedEncodingException {
+ String encodedString = cryptoUtils.encrypt(data);
assertNotNull(encodedString);
- assertEquals(encodedStringExpected, encodedString);
+ assertEquals(data, cryptoUtils.decrypt(encodedString));
}
/**
- * This method tests decryption.
+ * This method tests encryption.
*
* @throws GeneralSecurityException
+ * @throws DecoderException
+ * @throws UnsupportedEncodingException
*/
@Test
- public final void testDecryption() throws GeneralSecurityException {
- final String decodedStringExpected = "This is a test string";
- final String encodedString = "A5CB112C9F608A220B35AFED08024D98B9653333AF4C9527C2E934DE473F6145";
- String decryptedString = cryptoUtils.decrypt(encodedString);
- assertNotNull(decryptedString);
- assertEquals(decodedStringExpected, decryptedString);
+ public final void testEncryptedStringIsDifferent()
+ throws GeneralSecurityException, DecoderException, UnsupportedEncodingException {
+ String encodedString1 = cryptoUtils.encrypt(data);
+ String encodedString2 = cryptoUtils.encrypt(data);
+ byte[] encryptedMessage1 = Hex.decodeHex(encodedString1.toCharArray());
+ byte[] encryptedMessage2 = Hex.decodeHex(encodedString2.toCharArray());
+ assertNotNull(encryptedMessage1);
+ assertNotNull(encryptedMessage2);
+ assertNotEquals(encryptedMessage1, encryptedMessage2);
+ byte[] subData1 = ArrayUtils.subarray(encryptedMessage1, 16, encryptedMessage1.length);
+ byte[] subData2 = ArrayUtils.subarray(encryptedMessage2, 16, encryptedMessage2.length);
+ assertNotEquals(subData1, subData2);
}
} \ No newline at end of file