X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fit%2FCryptoUtilsItCase.java;fp=src%2Ftest%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fit%2FCryptoUtilsItCase.java;h=f03fe83c73a4ee3d143beb125e573fe9208d8c05;hb=434170f50621917a7fb2cbe7c7b01c4b29a8211e;hp=0000000000000000000000000000000000000000;hpb=2e5ec6aaac811c9a0efd8f80eef39fd91a1ac9ea;p=clamp.git diff --git a/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java b/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java new file mode 100644 index 00000000..f03fe83c --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/CryptoUtilsItCase.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.security.GeneralSecurityException; + +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; + + /** + * This method tests encryption. + * + * @throws GeneralSecurityException + */ + @Test + public final void testEncryption() throws GeneralSecurityException { + final String testData = "This is a test string"; + final String encodedStringExpected = "A5CB112C9F608A220B35AFED08024D98B9653333AF4C9527C2E934DE473F6145"; + String encodedString = cryptoUtils.encrypt(testData); + assertNotNull(encodedString); + assertEquals(encodedStringExpected, encodedString); + } + + /** + * This method tests decryption. + * + * @throws GeneralSecurityException + */ + @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); + } +} \ No newline at end of file