diff options
Diffstat (limited to 'asdctool/src/test')
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) ); } } |