diff options
author | Francis Toth <francis.toth@yoppworks.com> | 2020-07-07 09:10:33 -0400 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-07-09 09:34:59 +0000 |
commit | 20903a7051c3ee2e938cd02e408021ea34e78d0c (patch) | |
tree | fd274d884f6e2f13dcb141c80a4ac541c5459686 /asdctool/src/test/java/org/openecomp | |
parent | bdeb28f273da2494d7eeabbb5329222dfd168e3b (diff) |
Clean ValidatorExecutor hierarchy
Signed-off-by: Francis Toth <francis.toth@yoppworks.com>
Change-Id: I9d919b1d57eac1d25c8b3874366c2cb9e906923a
Issue-ID: SDC-2499
Diffstat (limited to 'asdctool/src/test/java/org/openecomp')
8 files changed, 57 insertions, 254 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 138629b113..393f678af3 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 @@ -20,32 +20,34 @@ package org.openecomp.sdc.asdctool.impl.validator; -import static org.mockito.Mockito.mock; - -import java.util.ArrayList; -import java.util.LinkedList; -import org.junit.Test; +import org.junit.jupiter.api.Test; +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; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -public class ArtifactToolBLTest { +import java.util.ArrayList; +import java.util.List; - private ArtifactToolBL createTestSubject() { - return new ArtifactToolBL(new ArrayList<>()); - } +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; - //Generated test - @Test(expected = NullPointerException.class) +public class ArtifactToolBLTest { + + @Test public void testValidateAll() { JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - ArtifactToolBL testSubject = createTestSubject(); - testSubject.validators = new LinkedList<>(); - testSubject.validators.add(new NodeToscaArtifactsValidatorExecutor(janusGraphDaoMock, toscaOperationFacade)); + List<IArtifactValidatorExecutor> validators = new ArrayList<>(); + validators.add(new NodeToscaArtifactsValidatorExecutor(janusGraphDaoMock, toscaOperationFacade)); + ArtifactToolBL testSubject = new ArtifactToolBL(validators); + // Initially no outputFilePath was passed to this function (hence it is set to null) // TODO: Fix this null and see if the argument is used by this function - testSubject.validateAll(null); + assertThrows( + NullPointerException.class, + () -> testSubject.validateAll(null) + ); } } 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 74a252c5aa..b62be60594 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 @@ -20,32 +20,34 @@ package org.openecomp.sdc.asdctool.impl.validator; -import org.junit.Test; -import org.openecomp.sdc.asdctool.impl.validator.executor.ServiceValidatorExecutor; +import org.junit.jupiter.api.Test; +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.be.dao.jsongraph.JanusGraphDao; -import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile; -import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter; - import java.util.ArrayList; -import java.util.LinkedList; +import java.util.List; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; +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 ValidationToolBL createTestSubject() { - return new ValidationToolBL(new ArrayList<>()); - } - - @Test(expected = NullPointerException.class) + @Test public void testValidateAll() { JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ValidationToolBL testSubject = createTestSubject(); - testSubject.validators = new LinkedList<>(); - testSubject.validators.add(new ServiceValidatorExecutor(janusGraphDaoMock)); + + List<ValidatorExecutor> validators = new ArrayList<>(); + validators.add(TopologyTemplateValidatorExecutor.serviceValidatorExecutor(janusGraphDaoMock)); + ValidationToolBL testSubject = new ValidationToolBL(validators); + Report report = Report.make(); - testSubject.validateAll(report, makeTxtFile(makeConsoleWriter())); + assertThrows( + NullPointerException.class, + () -> testSubject.validateAll(report, makeTxtFile(makeConsoleWriter())) + ); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java index 47798f6777..9efd4c4893 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationToolConfigurationTest.java @@ -25,9 +25,7 @@ import org.openecomp.sdc.asdctool.impl.validator.ArtifactToolBL; import org.openecomp.sdc.asdctool.impl.validator.ValidationToolBL; import org.openecomp.sdc.asdctool.impl.validator.executor.NodeToscaArtifactsValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executor.ServiceToscaArtifactsValidatorExecutor; -import org.openecomp.sdc.asdctool.impl.validator.executor.ServiceValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.executor.VFToscaArtifactValidatorExecutor; -import org.openecomp.sdc.asdctool.impl.validator.executor.VfValidatorExecutor; import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ArtifactValidationUtils; import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.ServiceArtifactValidationTask; import org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts.VfArtifactValidationTask; @@ -56,13 +54,9 @@ public class ValidationToolConfigurationTest { @Test public void testBasicServiceValidator() { - ValidationToolConfiguration testSubject; - ServiceValidatorExecutor result; + ValidationToolConfiguration testSubject = createTestSubject(); JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - - // default test - testSubject = createTestSubject(); - result = testSubject.basicServiceValidator(janusGraphDaoMock); + testSubject.basicServiceValidator(janusGraphDaoMock); } @Test @@ -110,13 +104,9 @@ public class ValidationToolConfigurationTest { @Test public void testBasicVfValidator() { - ValidationToolConfiguration testSubject; - VfValidatorExecutor result; + ValidationToolConfiguration testSubject = createTestSubject(); JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - - // default test - testSubject = createTestSubject(); - result = testSubject.basicVfValidator(new ArrayList<>(), janusGraphDaoMock); + testSubject.basicVfValidator(new ArrayList<>(), janusGraphDaoMock); } @Test diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutorTest.java deleted file mode 100644 index 4888f42e8b..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutorTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.asdctool.impl.validator.executor; - -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; - -public class ServiceValidatorExecutorTest - implements ValidatorExecutorContract, TopologyTemplateValidatorExecutorContract { - - @Override - public ServiceValidatorExecutor createTestSubject(JanusGraphDao dao) { - return new ServiceValidatorExecutor(dao); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorContract.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorContract.java deleted file mode 100644 index 881782695f..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorContract.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2020 Bell Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.openecomp.sdc.asdctool.impl.validator.executor; - -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.Mockito.mock; -import static org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum.PRODUCT; - -import org.junit.jupiter.api.Test; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; - -public interface TopologyTemplateValidatorExecutorContract { - - TopologyTemplateValidatorExecutor createTestSubject(JanusGraphDao dao); - - @Test - default void testGetVerticesToValidate() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - TopologyTemplateValidatorExecutor testSubject = createTestSubject(janusGraphDaoMock); - assertThrows(NullPointerException.class, - () -> testSubject.getVerticesToValidate(PRODUCT)); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ValidatorExecutorContract.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ValidatorExecutorTest.java index de1f04923a..faab454a79 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ValidatorExecutorContract.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ValidatorExecutorTest.java @@ -19,25 +19,36 @@ */ package org.openecomp.sdc.asdctool.impl.validator.executor; +import org.junit.jupiter.api.Test; +import org.openecomp.sdc.asdctool.impl.validator.report.Report; +import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; + +import java.util.ArrayList; +import java.util.function.Function; + import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; +import static org.openecomp.sdc.asdctool.impl.validator.executor.TopologyTemplateValidatorExecutor.vfValidatorExecutor; import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.makeTxtFile; import static org.openecomp.sdc.asdctool.impl.validator.report.ReportFileWriterTestFactory.makeConsoleWriter; -import org.junit.jupiter.api.Test; -import org.openecomp.sdc.asdctool.impl.validator.report.Report; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; - -public interface ValidatorExecutorContract { +public final class ValidatorExecutorTest { - ValidatorExecutor createTestSubject(JanusGraphDao dao); + @Test + public void executeValidationsWithServiceValidator() { + testExecuteValidations(TopologyTemplateValidatorExecutor::serviceValidatorExecutor); + } @Test - default void testExecuteValidations() { + public void executeValidationsWithVFValidator() { + testExecuteValidations(dao -> vfValidatorExecutor(new ArrayList<>(), dao)); + } + + private void testExecuteValidations(Function<JanusGraphDao, ValidatorExecutor> factory) { Report report = Report.make(); JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); assertThrows(NullPointerException.class, () -> - createTestSubject(janusGraphDaoMock).executeValidations(report, makeTxtFile(makeConsoleWriter())) + factory.apply(janusGraphDaoMock).executeValidations(report, makeTxtFile(makeConsoleWriter())) ); } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutorTest.java deleted file mode 100644 index 85bf4bc719..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutorTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.asdctool.impl.validator.executor; - -import java.util.ArrayList; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; - -public class VfValidatorExecutorTest - implements ValidatorExecutorContract, TopologyTemplateValidatorExecutorContract { - - @Override - public VfValidatorExecutor createTestSubject(JanusGraphDao dao) { - return new VfValidatorExecutor(new ArrayList<>(), dao); - } -} diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java deleted file mode 100644 index 317932d9d9..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ElementTypeEnumTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SDC - * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.sdc.asdctool.impl.validator.utils; - -import org.junit.Test; - -import java.util.List; - - -public class ElementTypeEnumTest { - - private ElementTypeEnum createTestSubject() { - return ElementTypeEnum.VF; - } - - - @Test - public void testGetByType() { - String elementType = ""; - ElementTypeEnum result; - - // default test - result = ElementTypeEnum.getByType(elementType); - result = ElementTypeEnum.getByType(ElementTypeEnum.VF.getElementType()); - } - - - @Test - public void testGetAllTypes() { - List<String> result; - - // default test - result = ElementTypeEnum.getAllTypes(); - } - - - @Test - public void testGetElementType() { - ElementTypeEnum testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getElementType(); - } - - - @Test - public void testSetElementType() { - ElementTypeEnum testSubject; - String elementType = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setElementType(elementType); - } - - - @Test - public void testGetClazz() { - ElementTypeEnum testSubject; - Class result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getClazz(); - } - - - @Test - public void testSetClazz() { - ElementTypeEnum testSubject; - Class clazz = null; - - // default test - testSubject = createTestSubject(); - testSubject.setClazz(clazz); - } -} |