aboutsummaryrefslogtreecommitdiffstats
path: root/common-app-api
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-app-api
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-app-api')
-rw-r--r--common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java63
1 files changed, 53 insertions, 10 deletions
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java
index 5c7865e879..1cacd7a32b 100644
--- a/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java
+++ b/common-app-api/src/test/java/org/openecomp/sdc/common/config/EcompErrorConfigurationTest.java
@@ -22,14 +22,15 @@
package org.openecomp.sdc.common.config;
-import static org.hamcrest.core.StringContains.containsString;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.HashMap;
-import org.junit.Before;
-import org.junit.Test;
import java.util.Map;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.common.api.ConfigurationSource;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
@@ -42,7 +43,7 @@ public class EcompErrorConfigurationTest {
private ConfigurationManager configurationManager;
- @Before
+ @BeforeEach
public void loadEcompErrorConfiguration() {
String appConfigDir = "src/test/resources/config/common";
ConfigurationSource configurationSource =
@@ -76,20 +77,62 @@ public class EcompErrorConfigurationTest {
//when
String result = ecompErrorConfiguration.toString();
//then
- assertThat(result, containsString(
+ assertTrue(result.contains(
"EcompErrorConfiguration [errors={BeRestApiGeneralError=org.openecomp.sdc.common.config.EcompErrorInfo@"));
}
@Test
public void testValidateEcompoErrorInfo() {
- //given
+ Map<String, EcompErrorInfo> errors = new HashMap();
EcompErrorInfo ecompErrorInfo = ecompErrorConfiguration.getEcompErrorInfo("BeInitializationError");
- Map<String, EcompErrorInfo> errors = new HashMap<>();
errors.put("BeInitializationError", ecompErrorInfo);
//when
ecompErrorConfiguration.setErrors(errors);
//then
- assertEquals(ecompErrorConfiguration.getErrors(), errors);
+ assertEquals(errors, ecompErrorConfiguration.getErrors());
+
+ // error info is null
+ errors.clear();
+ ecompErrorConfiguration.setErrors(new HashMap());
+ errors.put("error1", null);
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+ assertNull(ecompErrorConfiguration.getEcompErrorInfo("error1"));
+ errors.clear();
+
+ // type is null or invalid
+ EcompErrorInfo errorInfo = new EcompErrorInfo();
+ errors.put("error1", errorInfo);
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+ errorInfo.setType("type");
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+
+ // severity is null or invalid
+ errorInfo.setType(EcompErrorConfiguration.EcompErrorType.CONFIG_ERROR.name());
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+ errorInfo.setSeverity("severity");
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+
+ // alarmSeverify is null or invalid
+ errorInfo.setSeverity(EcompErrorConfiguration.EcompErrorSeverity.INFO.name());
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+ errorInfo.setAlarmSeverity("alarmSeverify");
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+
+ // code is null or invalid
+ errorInfo.setAlarmSeverity(EcompErrorConfiguration.EcompAlarmSeverity.CRITICAL.name());
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+ errorInfo.setCode("ASDC_0001");
+ ecompErrorConfiguration.setErrors(errors);
+ assertEquals(0, ecompErrorConfiguration.getErrors().size());
+
}
}