From 0132d3637a889f84897d6a08688b20ff6f606041 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Tue, 7 Jul 2020 07:24:48 -0400 Subject: Add test contracts for ValidatorExecutor and TopologyTemplateValidatorExecutor Signed-off-by: Francis Toth Change-Id: I10f0de565588e0bc7cd0f47ba7f714eab3f1f7f7 Issue-ID: SDC-2499 --- .../executor/ServiceValidatorExecutor.java | 3 +- .../TopologyTemplateValidatorExecutor.java | 17 ++---- .../validator/executor/VfValidatorExecutor.java | 3 +- .../executor/ServiceValidatorExecutorTest.java | 26 ++------- .../TopologyTemplateValidatorExecutorContract.java | 40 +++++++++++++ .../TopologyTemplateValidatorExecutorTest.java | 65 ---------------------- .../executor/ValidatorExecutorContract.java | 43 ++++++++++++++ .../executor/VfValidatorExecutorTest.java | 30 ++-------- 8 files changed, 100 insertions(+), 127 deletions(-) create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorContract.java delete mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorTest.java create mode 100644 asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ValidatorExecutorContract.java diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java index ff27b667d5..27bcd1f60d 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/ServiceValidatorExecutor.java @@ -39,8 +39,7 @@ public class ServiceValidatorExecutor extends TopologyTemplateValidatorExecutor @Autowired(required = false) public ServiceValidatorExecutor(JanusGraphDao janusGraphDao) { - super(janusGraphDao); - setName("SERVICE_VALIDATOR"); + super(janusGraphDao, "SERVICE_VALIDATOR"); } @Override diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java index 9ba2f5ab46..95a9fce9af 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutor.java @@ -27,6 +27,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import lombok.Getter; import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.asdctool.impl.validator.report.ReportFile.TXTFile; import org.openecomp.sdc.asdctool.impl.validator.tasks.TopologyTemplateValidationTask; @@ -39,29 +40,21 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum; import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.common.log.wrappers.Logger; -import org.springframework.beans.factory.annotation.Autowired; public class TopologyTemplateValidatorExecutor { private static final Logger log = Logger.getLogger(VfValidatorExecutor.class); - protected JanusGraphDao janusGraphDao; + private final JanusGraphDao janusGraphDao; - protected String name; + @Getter + private final String name; - @Autowired - public TopologyTemplateValidatorExecutor(JanusGraphDao janusGraphDao) { + public TopologyTemplateValidatorExecutor(JanusGraphDao janusGraphDao, String name) { this.janusGraphDao = janusGraphDao; - } - - public void setName(String name) { this.name = name; } - public String getName() { - return name; - } - protected List getVerticesToValidate(ComponentTypeEnum type) { Map props = new EnumMap<>(GraphPropertyEnum.class); props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name()); diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java index 4729e63c16..f8aaf5480d 100644 --- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java +++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executor/VfValidatorExecutor.java @@ -36,9 +36,8 @@ public class VfValidatorExecutor extends TopologyTemplateValidatorExecutor imple @Autowired(required = false) public VfValidatorExecutor(List tasks, JanusGraphDao janusGraphDao) { - super(janusGraphDao); + super(janusGraphDao, "BASIC_VF_VALIDATOR"); this.tasks = tasks; - setName("BASIC_VF_VALIDATOR"); } @Override 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 index bc0eb25da2..4888f42e8b 100644 --- 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 @@ -20,29 +20,13 @@ package org.openecomp.sdc.asdctool.impl.validator.executor; -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; - -import org.junit.Test; -import org.openecomp.sdc.asdctool.impl.validator.report.Report; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -public class ServiceValidatorExecutorTest { - - private ServiceValidatorExecutor createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - return new ServiceValidatorExecutor(janusGraphDaoMock); - } - - @Test - public void testGetName() { - createTestSubject().getName(); - } +public class ServiceValidatorExecutorTest + implements ValidatorExecutorContract, TopologyTemplateValidatorExecutorContract { - @Test(expected = NullPointerException.class) - public void testExecuteValidations() { - Report report = Report.make(); - createTestSubject().executeValidations(report, makeTxtFile(makeConsoleWriter())); + @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 new file mode 100644 index 0000000000..881782695f --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorContract.java @@ -0,0 +1,40 @@ +/*- + * ============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/TopologyTemplateValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorTest.java deleted file mode 100644 index 57e99c3865..0000000000 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/TopologyTemplateValidatorExecutorTest.java +++ /dev/null @@ -1,65 +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.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; - -import static org.mockito.Mockito.mock; - -public class TopologyTemplateValidatorExecutorTest { - - private TopologyTemplateValidatorExecutor createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - return new TopologyTemplateValidatorExecutor(janusGraphDaoMock); - } - - @Test - public void testSetName() { - TopologyTemplateValidatorExecutor testSubject; - String name = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } - - @Test - public void testGetName() { - TopologyTemplateValidatorExecutor testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test - public void testGetVerticesToValidate() { - TopologyTemplateValidatorExecutor testSubject; - - // default test - testSubject = createTestSubject(); - Assertions.assertThrows(NullPointerException.class, () -> testSubject.getVerticesToValidate(ComponentTypeEnum.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/ValidatorExecutorContract.java new file mode 100644 index 0000000000..de1f04923a --- /dev/null +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executor/ValidatorExecutorContract.java @@ -0,0 +1,43 @@ +/*- + * ============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.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 { + + ValidatorExecutor createTestSubject(JanusGraphDao dao); + + @Test + default void testExecuteValidations() { + Report report = Report.make(); + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + assertThrows(NullPointerException.class, () -> + createTestSubject(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 index c40f660d45..85bf4bc719 100644 --- 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 @@ -20,34 +20,14 @@ package org.openecomp.sdc.asdctool.impl.validator.executor; -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; - import java.util.ArrayList; -import java.util.List; -import org.junit.Test; -import org.openecomp.sdc.asdctool.impl.validator.report.Report; -import org.openecomp.sdc.asdctool.impl.validator.tasks.VfValidationTask; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; -public class VfValidatorExecutorTest { - - private VfValidatorExecutor createTestSubject() { - List validationTasks = new ArrayList<>(); - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - - return new VfValidatorExecutor(validationTasks, janusGraphDaoMock); - } - - @Test - public void testGetName() { - createTestSubject().getName(); - } +public class VfValidatorExecutorTest + implements ValidatorExecutorContract, TopologyTemplateValidatorExecutorContract { - @Test(expected = NullPointerException.class) - public void testExecuteValidations() { - Report report = Report.make(); - createTestSubject().executeValidations(report, makeTxtFile(makeConsoleWriter())); + @Override + public VfValidatorExecutor createTestSubject(JanusGraphDao dao) { + return new VfValidatorExecutor(new ArrayList<>(), dao); } } -- cgit 1.2.3-korg