aboutsummaryrefslogtreecommitdiffstats
path: root/common-be/src/test/java/org
diff options
context:
space:
mode:
authorxuegao <xue.gao@intl.att.com>2021-03-25 10:31:08 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2021-03-25 16:27:18 +0000
commitde9224b1ae01755c7cc46e4bdd1a50c1bc08936e (patch)
tree86369286ebb95412426a73f1e36e317040f6b2d0 /common-be/src/test/java/org
parent7af307919d19761959a61ac64603312b3fb45b58 (diff)
Improve test coverage
Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I47da0decd6b6df93ace68b2af586b255ef0b792e Signed-off-by: xuegao <xue.gao@intl.att.com>
Diffstat (limited to 'common-be/src/test/java/org')
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java24
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java27
2 files changed, 29 insertions, 22 deletions
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java b/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java
index 2f0031d6e1..c8f1c68037 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/csar/security/Sha256WithRsaCmsContentSignerTest.java
@@ -19,10 +19,6 @@
package org.openecomp.sdc.be.csar.security;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
import java.io.File;
import java.io.IOException;
import java.net.URL;
@@ -48,6 +44,11 @@ import org.openecomp.sdc.be.csar.security.api.CertificateReader;
import org.openecomp.sdc.be.csar.security.api.PrivateKeyReader;
import org.openecomp.sdc.be.csar.security.exception.CmsSignatureException;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.fail;
+
class Sha256WithRsaCmsContentSignerTest {
private Sha256WithRsaCmsContentSigner cmsContentSigner;
@@ -85,6 +86,21 @@ class Sha256WithRsaCmsContentSignerTest {
}
@Test
+ void formatToPemSignatureTest() throws OperatorCreationException, CMSException, IOException, CmsSignatureException {
+ final File certFile = getResourceFile(certFilesPath.resolve("realCert1.cert"));
+ final File keyFile = getResourceFile(certFilesPath.resolve("realCert1.key"));
+ final File fileToSign = getResourceFile(testFilesPath.resolve("fileToSign.txt"));
+ final Key privateKey = privateKeyReader.loadPrivateKey(keyFile);
+ final Certificate certificate = certificateReader.loadCertificate(certFile);
+ final byte[] actualSignatureBytes = cmsContentSigner
+ .signData(Files.readAllBytes(fileToSign.toPath()), certificate, privateKey);
+
+ assertNotNull(cmsContentSigner.formatToPemSignature(actualSignatureBytes));
+ assertThrows(CmsSignatureException.class,
+ () -> cmsContentSigner.formatToPemSignature(new byte[10]));
+ }
+
+ @Test
void signDataInvalidCertAndKeyTest() {
assertThrows(CmsSignatureException.class,
() -> cmsContentSigner.signData(null, null, null));
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java
index 4001599277..b6862393e0 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/elements/MapListRequirementDataDefinitionTest.java
@@ -20,11 +20,12 @@
package org.openecomp.sdc.be.datatypes.elements;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.Map;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class MapListRequirementDataDefinitionTest {
@@ -33,26 +34,16 @@ public class MapListRequirementDataDefinitionTest {
return new MapListRequirementDataDefinition(map);
}
-
- @Test
- public void testGetMapToscaDataDefinition() throws Exception {
- MapListRequirementDataDefinition testSubject;
- Map<String, ListRequirementDataDefinition> result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getMapToscaDataDefinition();
- }
-
-
@Test
public void testAdd() throws Exception {
- MapListRequirementDataDefinition testSubject;
- String key = "";
+ MapListRequirementDataDefinition testSubject = new MapListRequirementDataDefinition();
RequirementDataDefinition value = null;
- // default test
- testSubject = createTestSubject();
- testSubject.add(key, value);
+ testSubject.add("key1", value);
+ testSubject.add("key2", value);
+ testSubject.add("key2", value);
+ Map<String, ListRequirementDataDefinition> result = testSubject.getMapToscaDataDefinition();
+ assertEquals(2, result.size());
+ assertEquals(2, result.get("key2").getListToscaDataDefinition().size());
}
}