aboutsummaryrefslogtreecommitdiffstats
path: root/asdctool
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 /asdctool
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 'asdctool')
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java31
-rw-r--r--asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java41
2 files changed, 63 insertions, 9 deletions
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
index 393f678af3..79166e552c 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
@@ -21,6 +21,7 @@
package org.openecomp.sdc.asdctool.impl.validator;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
import org.openecomp.sdc.asdctool.impl.validator.executor.IArtifactValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executor.NodeToscaArtifactsValidatorExecutor;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
@@ -29,13 +30,39 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade
import java.util.ArrayList;
import java.util.List;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.*;
public class ArtifactToolBLTest {
@Test
- public void testValidateAll() {
+ public void testValidateAllOK() {
+ List<IArtifactValidatorExecutor> validators = new ArrayList<>();
+ NodeToscaArtifactsValidatorExecutor executor = Mockito.mock(NodeToscaArtifactsValidatorExecutor.class);
+ when(executor.executeValidations(Mockito.anyString())).thenReturn(true);
+ validators.add(executor);
+ ArtifactToolBL testSubject = new ArtifactToolBL(validators);
+
+ verify(executor, Mockito.times(0)).executeValidations(Mockito.anyString());
+ assertTrue(testSubject.validateAll(""));
+ }
+
+ @Test
+ public void testValidateAllNOK() {
+ List<IArtifactValidatorExecutor> validators = new ArrayList<>();
+ NodeToscaArtifactsValidatorExecutor executor = Mockito.mock(NodeToscaArtifactsValidatorExecutor.class);
+ when(executor.executeValidations(Mockito.anyString())).thenReturn(false);
+ validators.add(executor);
+ ArtifactToolBL testSubject = new ArtifactToolBL(validators);
+
+ verify(executor, Mockito.times(0)).executeValidations(Mockito.anyString());
+ assertFalse(testSubject.validateAll(""));
+ }
+
+ @Test
+ public void testValidateAllException() {
JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class);
ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class);
diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
index b62be60594..529a9b6768 100644
--- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
+++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
@@ -21,33 +21,60 @@
package org.openecomp.sdc.asdctool.impl.validator;
import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
import org.openecomp.sdc.asdctool.impl.validator.executor.TopologyTemplateValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.executor.ValidatorExecutor;
import org.openecomp.sdc.asdctool.impl.validator.report.Report;
+import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile;
import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao;
import java.util.ArrayList;
import java.util.List;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.*;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile;
import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter;
public class ValidationToolBLTest {
+ private List<ValidatorExecutor> validators = new ArrayList<>();
+ private Report report = Report.make();
+ private ValidatorExecutor executor = Mockito.mock(ValidatorExecutor.class);
+ private ReportFile.TXTFile file= makeTxtFile(makeConsoleWriter());
+
@Test
- public void testValidateAll() {
- JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class);
+ public void testValidateAllOK() {
+ when(executor.executeValidations(report, file)).thenReturn(true);
+ validators.add(executor);
+ ValidationToolBL testSubject = new ValidationToolBL(validators);
+
+ verify(executor, Mockito.times(0)).executeValidations(report, file);
+ assertTrue(testSubject.validateAll(report, file));
+ }
- List<ValidatorExecutor> validators = new ArrayList<>();
+ @Test
+ public void testValidateAllNOK() {
+ when(executor.executeValidations(report, file)).thenReturn(false);
+ validators.add(executor);
+ ValidationToolBL testSubject = new ValidationToolBL(validators);
+
+ verify(executor, Mockito.times(0)).executeValidations(report, file);
+ assertFalse(testSubject.validateAll(report, file));
+ }
+
+ @Test
+ public void testValidateAll() {
+ JanusGraphDao janusGraphDaoMock = Mockito.mock(JanusGraphDao.class);
validators.add(TopologyTemplateValidatorExecutor.serviceValidatorExecutor(janusGraphDaoMock));
ValidationToolBL testSubject = new ValidationToolBL(validators);
- Report report = Report.make();
assertThrows(
NullPointerException.class,
- () -> testSubject.validateAll(report, makeTxtFile(makeConsoleWriter()))
+ () -> testSubject.validateAll(report, file)
);
}
}