From de9224b1ae01755c7cc46e4bdd1a50c1bc08936e Mon Sep 17 00:00:00 2001 From: xuegao Date: Thu, 25 Mar 2021 10:31:08 +0100 Subject: Improve test coverage Add unit tests to improve test coverage. Issue-ID: SDC-3428 Change-Id: I47da0decd6b6df93ace68b2af586b255ef0b792e Signed-off-by: xuegao --- .../impl/validator/ArtifactToolBLTest.java | 31 ++++++++++++++-- .../impl/validator/ValidationToolBLTest.java | 41 ++++++++++++++++++---- 2 files changed, 63 insertions(+), 9 deletions(-) (limited to 'asdctool/src/test') 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 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 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 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 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) ); } } -- cgit 1.2.3-korg