From 7717944e41ecbb9447a56d870821b6d494e7ebe3 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Sun, 19 Apr 2020 20:55:37 -0400 Subject: Remove outputFullFilePath from ValidationConfigManager This commit aims to extract the outputFullFilePath field from ValidationConfigManager in order to improve testability. This commit contains multiple minor modifications resulting from bubbling up the outputFullFilePath static field to where it is actually set. Most of the modifications result from changing the signature of the functions which formerly relied on ValidationConfigManager.getOutputFullFilePath. Change-Id: I0a28e527cabe606de8af62b8dcbc4b4e70db98ed Signed-off-by: Francis Toth Issue-ID: SDC-2499 --- .../impl/validator/ArtifactToolBLTest.java | 49 ++++++------ .../impl/validator/ValidationToolBLTest.java | 34 ++++---- .../config/ValidationConfigManagerTest.java | 38 +++------ .../executers/ArtifactValidatorExecuterTest.java | 92 +++++++++++----------- .../NodeToscaArtifactsValidatorExecuterTest.java | 61 +++++++------- ...ServiceToscaArtifactsValidatorExecutorTest.java | 61 +++++++------- .../executers/ServiceValidatorExecuterTest.java | 44 +++++------ .../VFToscaArtifactValidatorExecutorTest.java | 64 +++++++-------- .../executers/VfValidatorExecuterTest.java | 42 ++++------ .../artifacts/ArtifactValidationUtilsTest.java | 26 +++--- .../ServiceArtifactValidationTaskTest.java | 38 ++++----- .../artifacts/VfArtifactValidationTaskTest.java | 37 ++++----- .../tasks/moduleJson/ModuleJsonTaskTest.java | 19 +++-- .../impl/validator/utils/ReportManagerHelper.java | 10 +-- .../impl/validator/utils/ReportManagerTest.java | 36 ++++----- 15 files changed, 306 insertions(+), 345 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 ee41d626b2..e6ae05f493 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 @@ -7,9 +7,9 @@ * 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. @@ -20,35 +20,32 @@ 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.openecomp.sdc.asdctool.impl.validator.executers.NodeToscaArtifactsValidatorExecuter; import org.openecomp.sdc.be.dao.jsongraph.JanusGraphDao; import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade; -import java.util.ArrayList; -import java.util.LinkedList; - -import static org.mockito.Mockito.mock; - public class ArtifactToolBLTest { - private ArtifactToolBL createTestSubject() { - return new ArtifactToolBL(new ArrayList<>()); - } - - //Generated test - @Test(expected=NullPointerException.class) - public void testValidateAll() throws Exception { - ArtifactToolBL testSubject; - boolean result; - - // default test - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - - testSubject = createTestSubject(); - testSubject.validators = new LinkedList(); - testSubject.validators.add(new NodeToscaArtifactsValidatorExecuter(janusGraphDaoMock,toscaOperationFacade)); - result = testSubject.validateAll(); - } + private ArtifactToolBL createTestSubject() { + return new ArtifactToolBL(new ArrayList<>()); + } + + //Generated test + @Test(expected = NullPointerException.class) + public void testValidateAll() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + + ArtifactToolBL testSubject = createTestSubject(); + testSubject.validators = new LinkedList<>(); + testSubject.validators.add(new NodeToscaArtifactsValidatorExecuter(janusGraphDaoMock, toscaOperationFacade)); + // 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); + } } 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 f7f8307638..b412d7bc92 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 @@ -7,9 +7,9 @@ * 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. @@ -31,20 +31,18 @@ import static org.mockito.Mockito.mock; public class ValidationToolBLTest { - private ValidationToolBL createTestSubject() { - return new ValidationToolBL(new ArrayList<>()); - } - - @Test(expected=NullPointerException.class) - public void testValidateAll() throws Exception { - ValidationToolBL testSubject; - boolean result; - - // default test - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - testSubject = createTestSubject(); - testSubject.validators = new LinkedList<>(); - testSubject.validators.add(new ServiceValidatorExecuter(janusGraphDaoMock)); - result = testSubject.validateAll(); - } + private ValidationToolBL createTestSubject() { + return new ValidationToolBL(new ArrayList<>()); + } + + @Test(expected = NullPointerException.class) + public void testValidateAll() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ValidationToolBL testSubject = createTestSubject(); + testSubject.validators = new LinkedList<>(); + testSubject.validators.add(new ServiceValidatorExecuter(janusGraphDaoMock)); + // 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); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java index 570e5b21df..b763520318 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java @@ -7,9 +7,9 @@ * 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. @@ -20,9 +20,11 @@ package org.openecomp.sdc.asdctool.impl.validator.config; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import static org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager.csvReportFilePath; +import static org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager.txtReportFilePath; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,12 +32,16 @@ import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; -import java.util.Properties; - @RunWith(PowerMockRunner.class) @PrepareForTest({ReportManager.class}) public class ValidationConfigManagerTest { + @Test + public void testTxtReportFilePath() { + String randomOutput = System.currentTimeMillis() + ""; + assertThat(txtReportFilePath(randomOutput), equalTo(randomOutput + "/reportOutput.txt")); + } + @Test public void testCsvReportFilePath() { String randomOutput = System.currentTimeMillis() + ""; @@ -44,28 +50,4 @@ public class ValidationConfigManagerTest { csvReportFilePath(randomOutput, () -> millis), is(randomOutput + "/csvSummary_" + millis + ".csv")); } - - @Test - public void testGetOutputFilePath() { - String result; - - // default test - result = ValidationConfigManager.getOutputFilePath(); - } - - @Test - public void testGetOutputFullFilePath() throws Exception { - String result; - - // default test - result = ValidationConfigManager.getOutputFullFilePath(); - } - - @Test - public void testSetOutputFullFilePath() throws Exception { - String outputPath = ""; - - // default test - ValidationConfigManager.setOutputFullFilePath(outputPath); - } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java index 176a0ca79c..46fae4312d 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java @@ -7,9 +7,9 @@ * 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. @@ -38,56 +38,58 @@ import static org.mockito.Mockito.mock; public class ArtifactValidatorExecuterTest { - private ArtifactValidatorExecuter createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + private ArtifactValidatorExecuter createTestSubject() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - return new ArtifactValidatorExecuter(janusGraphDaoMock, toscaOperationFacade); - } + return new ArtifactValidatorExecuter(janusGraphDaoMock, toscaOperationFacade); + } - @Test - public void testGetName() throws Exception { - ArtifactValidatorExecuter testSubject; - String result; + @Test + public void testGetName() throws Exception { + ArtifactValidatorExecuter testSubject; + String result; - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } + // default test + testSubject = createTestSubject(); + result = testSubject.getName(); + } - @Test(expected=NullPointerException.class) - public void testGetVerticesToValidate() throws Exception { - ArtifactValidatorExecuter testSubject; - VertexTypeEnum type = null; - Map hasProps = null; + @Test(expected = NullPointerException.class) + public void testGetVerticesToValidate() throws Exception { + ArtifactValidatorExecuter testSubject; + VertexTypeEnum type = null; + Map hasProps = null; - // default test - testSubject = createTestSubject(); - testSubject.getVerticesToValidate(type, hasProps); - } + // default test + testSubject = createTestSubject(); + testSubject.getVerticesToValidate(type, hasProps); + } - @Test - public void testSetName() throws Exception { - ArtifactValidatorExecuter testSubject; - String name = ""; + @Test + public void testSetName() throws Exception { + ArtifactValidatorExecuter testSubject; + String name = ""; - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } + // default test + testSubject = createTestSubject(); + testSubject.setName(name); + } - @Test - public void testValidate() { - ArtifactValidatorExecuter testSubject; - Map> vertices = new HashMap<>(); - LinkedList linkedList = new LinkedList(); - linkedList.add(new Resource()); - vertices.put("stam", linkedList); - boolean result; + @Test + public void testValidate() { + ArtifactValidatorExecuter testSubject; + Map> vertices = new HashMap<>(); + LinkedList linkedList = new LinkedList(); + linkedList.add(new Resource()); + vertices.put("stam", linkedList); + boolean result; - // default test - testSubject = createTestSubject(); - result = testSubject.validate(vertices); - Assert.assertFalse(result); - } + // default test + testSubject = createTestSubject(); + // 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 + result = testSubject.validate(vertices, null); + Assert.assertFalse(result); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java index e84b89af71..c9c90b2aa4 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java @@ -7,9 +7,9 @@ * 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. @@ -28,40 +28,37 @@ import static org.mockito.Mockito.mock; public class NodeToscaArtifactsValidatorExecuterTest { - private NodeToscaArtifactsValidatorExecuter createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + private NodeToscaArtifactsValidatorExecuter createTestSubject() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - return new NodeToscaArtifactsValidatorExecuter(janusGraphDaoMock, toscaOperationFacade); - } - - @Test(expected=NullPointerException.class) - public void testExecuteValidations() throws Exception { - NodeToscaArtifactsValidatorExecuter testSubject; - boolean result; + return new NodeToscaArtifactsValidatorExecuter(janusGraphDaoMock, toscaOperationFacade); + } - // default test - testSubject = createTestSubject(); - result = testSubject.executeValidations(); - } + @Test(expected = NullPointerException.class) + public void testExecuteValidations() { + // 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 + createTestSubject().executeValidations(null); + } - @Test - public void testGetName() throws Exception { - NodeToscaArtifactsValidatorExecuter testSubject; - String result; + @Test + public void testGetName() throws Exception { + NodeToscaArtifactsValidatorExecuter testSubject; + String result; - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } + // default test + testSubject = createTestSubject(); + result = testSubject.getName(); + } - @Test - public void testSetName() throws Exception { - NodeToscaArtifactsValidatorExecuter testSubject; - String name = ""; + @Test + public void testSetName() throws Exception { + NodeToscaArtifactsValidatorExecuter testSubject; + String name = ""; - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } + // default test + testSubject = createTestSubject(); + testSubject.setName(name); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java index 51f1cc63da..1e24867358 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java @@ -7,9 +7,9 @@ * 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. @@ -28,40 +28,37 @@ import static org.mockito.Mockito.mock; public class ServiceToscaArtifactsValidatorExecutorTest { - private ServiceToscaArtifactsValidatorExecutor createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + private ServiceToscaArtifactsValidatorExecutor createTestSubject() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - return new ServiceToscaArtifactsValidatorExecutor(janusGraphDaoMock, toscaOperationFacade); - } + return new ServiceToscaArtifactsValidatorExecutor(janusGraphDaoMock, toscaOperationFacade); + } - @Test(expected = NullPointerException.class) - public void testExecuteValidations() throws Exception { - ServiceToscaArtifactsValidatorExecutor testSubject; - boolean result; + @Test(expected = NullPointerException.class) + public void testExecuteValidations() { + // 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 + createTestSubject().executeValidations(null); + } - // default test - testSubject = createTestSubject(); - result = testSubject.executeValidations(); - } + @Test + public void testGetName() throws Exception { + ServiceToscaArtifactsValidatorExecutor testSubject; + String result; - @Test - public void testGetName() throws Exception { - ServiceToscaArtifactsValidatorExecutor testSubject; - String result; + // default test + testSubject = createTestSubject(); + result = testSubject.getName(); + } - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } + @Test + public void testSetName() throws Exception { + ServiceToscaArtifactsValidatorExecutor testSubject; + String name = ""; - @Test - public void testSetName() throws Exception { - ServiceToscaArtifactsValidatorExecutor testSubject; - String name = ""; - - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } + // default test + testSubject = createTestSubject(); + testSubject.setName(name); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java index 16e36369e6..a1728d8a94 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java @@ -7,9 +7,9 @@ * 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. @@ -27,28 +27,20 @@ import static org.mockito.Mockito.mock; public class ServiceValidatorExecuterTest { - private ServiceValidatorExecuter createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - return new ServiceValidatorExecuter(janusGraphDaoMock); - } - - @Test - public void testGetName() { - ServiceValidatorExecuter testSubject; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test(expected=NullPointerException.class) - public void testExecuteValidations() throws Exception { - ServiceValidatorExecuter testSubject; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.executeValidations(); - } + private ServiceValidatorExecuter createTestSubject() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + return new ServiceValidatorExecuter(janusGraphDaoMock); + } + + @Test + public void testGetName() { + createTestSubject().getName(); + } + + @Test(expected = NullPointerException.class) + public void testExecuteValidations() { + // 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 + createTestSubject().executeValidations(null); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java index c8edb7d05a..783b888dec 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java @@ -7,9 +7,9 @@ * 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. @@ -29,40 +29,42 @@ import static org.mockito.Mockito.mock; public class VFToscaArtifactValidatorExecutorTest { - private VFToscaArtifactValidatorExecutor createTestSubject() { - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); + private VFToscaArtifactValidatorExecutor createTestSubject() { + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + ToscaOperationFacade toscaOperationFacade = mock(ToscaOperationFacade.class); - return new VFToscaArtifactValidatorExecutor(janusGraphDaoMock, toscaOperationFacade); - } + return new VFToscaArtifactValidatorExecutor(janusGraphDaoMock, toscaOperationFacade); + } - @Test - public void testExecuteValidations() { - VFToscaArtifactValidatorExecutor testSubject; - boolean result; + @Test + public void testExecuteValidations() { + VFToscaArtifactValidatorExecutor testSubject; + boolean result; - // default test - testSubject = createTestSubject(); - Assertions.assertThrows(NullPointerException.class, () -> testSubject.executeValidations()); - } + // default test + testSubject = createTestSubject(); + // 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 + Assertions.assertThrows(NullPointerException.class, () -> testSubject.executeValidations(null)); + } - @Test - public void testGetName() throws Exception { - VFToscaArtifactValidatorExecutor testSubject; - String result; + @Test + public void testGetName() throws Exception { + VFToscaArtifactValidatorExecutor testSubject; + String result; - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } + // default test + testSubject = createTestSubject(); + result = testSubject.getName(); + } - @Test - public void testSetName() throws Exception { - VFToscaArtifactValidatorExecutor testSubject; - String name = ""; + @Test + public void testSetName() throws Exception { + VFToscaArtifactValidatorExecutor testSubject; + String name = ""; - // default test - testSubject = createTestSubject(); - testSubject.setName(name); - } + // default test + testSubject = createTestSubject(); + testSubject.setName(name); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java index 457c9b0d19..c9bc5debd6 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java @@ -7,9 +7,9 @@ * 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. @@ -31,30 +31,22 @@ import static org.mockito.Mockito.mock; public class VfValidatorExecuterTest { - private VfValidatorExecuter createTestSubject() { - List validationTasks = new ArrayList<>(); - JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); + private VfValidatorExecuter createTestSubject() { + List validationTasks = new ArrayList<>(); + JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class); - return new VfValidatorExecuter(validationTasks, janusGraphDaoMock); - } + return new VfValidatorExecuter(validationTasks, janusGraphDaoMock); + } - @Test - public void testGetName() { - VfValidatorExecuter testSubject; - String result; + @Test + public void testGetName() { + createTestSubject().getName(); + } - // default test - testSubject = createTestSubject(); - result = testSubject.getName(); - } - - @Test(expected=NullPointerException.class) - public void testExecuteValidations() throws Exception { - VfValidatorExecuter testSubject; - boolean result; - - // default test - testSubject = createTestSubject(); - result = testSubject.executeValidations(); - } + @Test(expected = NullPointerException.class) + public void testExecuteValidations() { + // 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 + createTestSubject().executeValidations(null); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java index 1af4a13472..99733a7bd3 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java @@ -50,7 +50,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.IntStream; import static org.junit.Assert.assertEquals; @@ -93,13 +92,10 @@ public class ArtifactValidationUtilsTest { private final static String resourcePath = new File("src/test/resources").getAbsolutePath(); private final static String csvReportFilePath = ValidationConfigManager.DEFAULT_CSV_PATH; + private final static String txtReportFilePath = ValidationConfigManager.txtReportFilePath(resourcePath); public void initReportManager() { - String resourcePath = new File(Objects - .requireNonNull(ArtifactValidationUtilsTest.class.getClassLoader().getResource("")) - .getFile()).getAbsolutePath(); - ValidationConfigManager.setOutputFullFilePath(resourcePath); - ReportManager.make(csvReportFilePath); + ReportManager.make(csvReportFilePath, txtReportFilePath); } @Before @@ -118,7 +114,7 @@ public class ArtifactValidationUtilsTest { @After public void clean() { - ReportManagerHelper.cleanReports(csvReportFilePath); + ReportManagerHelper.cleanReports(csvReportFilePath, txtReportFilePath); } @Test @@ -129,9 +125,9 @@ public class ArtifactValidationUtilsTest { // when ArtifactsVertexResult result = - testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts); + testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertTrue(result.getStatus()); @@ -148,10 +144,10 @@ public class ArtifactValidationUtilsTest { // when ArtifactsVertexResult result = - testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts); - ReportManager.reportEndOfToolRun(csvReportFilePath); + testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts, txtReportFilePath); + ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertFalse(result.getStatus()); @@ -225,9 +221,9 @@ public class ArtifactValidationUtilsTest { // when ArtifactsVertexResult result = - testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME); + testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertTrue(result.getStatus()); @@ -245,7 +241,7 @@ public class ArtifactValidationUtilsTest { // when ArtifactsVertexResult result = - testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME); + testSubject.validateTopologyTemplateArtifacts(vertex, TASK_NAME, txtReportFilePath); // then assertFalse(result.getStatus()); diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java index 0aab99237b..cf28d74803 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java @@ -7,9 +7,9 @@ * 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. @@ -21,26 +21,28 @@ package org.openecomp.sdc.asdctool.impl.validator.tasks.artifacts; import org.junit.Test; +import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; public class ServiceArtifactValidationTaskTest { - private ServiceArtifactValidationTask createTestSubject() { - ArtifactValidationUtils artifactValidationUtilsMock = mock(ArtifactValidationUtils.class); - return new ServiceArtifactValidationTask(artifactValidationUtilsMock); - } - - @Test - public void testValidate() throws Exception { - ServiceArtifactValidationTask testSubject; - GraphVertex vertex = null; - ArtifactsVertexResult result; - - // default test - testSubject = createTestSubject(); - result = testSubject.validate(vertex); - } - + private ServiceArtifactValidationTask createTestSubject() { + ArtifactValidationUtils artifactValidationUtilsMock = mock(ArtifactValidationUtils.class); + return new ServiceArtifactValidationTask(artifactValidationUtilsMock); + } + + @Test + public void testValidate() { + GraphVertex vertex = null; + ServiceArtifactValidationTask testSubject = createTestSubject(); + // 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 + VertexResult actual = testSubject.validate(vertex, null); + assertThat(actual, is(nullValue())); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java index 0dba9569ac..5302f4f23e 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java @@ -7,9 +7,9 @@ * 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. @@ -24,24 +24,25 @@ import org.junit.Test; import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; public class VfArtifactValidationTaskTest { - private VfArtifactValidationTask createTestSubject() { - ArtifactValidationUtils artifactValidationUtilsMock = mock(ArtifactValidationUtils.class); - return new VfArtifactValidationTask(artifactValidationUtilsMock); - } - - @Test - public void testValidate() throws Exception { - VfArtifactValidationTask testSubject; - GraphVertex vertex = null; - VertexResult result; - - // default test - testSubject = createTestSubject(); - result = testSubject.validate(vertex); - } - + private VfArtifactValidationTask createTestSubject() { + ArtifactValidationUtils artifactValidationUtilsMock = mock(ArtifactValidationUtils.class); + return new VfArtifactValidationTask(artifactValidationUtilsMock); + } + + @Test + public void testValidate() { + GraphVertex vertex = null; + VfArtifactValidationTask testSubject = createTestSubject(); + // 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 + VertexResult actual = testSubject.validate(vertex, null); + assertThat(actual, is(nullValue())); + } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java index 33ebd09159..9a9f20bcc7 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java @@ -7,9 +7,9 @@ * 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. @@ -27,6 +27,7 @@ import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.openecomp.sdc.asdctool.impl.validator.utils.VertexResult; import org.openecomp.sdc.be.dao.jsongraph.GraphVertex; import org.openecomp.sdc.be.datatypes.elements.ArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.elements.GroupInstanceDataDefinition; @@ -41,6 +42,8 @@ import org.openecomp.sdc.be.model.jsonjanusgraph.operations.TopologyTemplateOper import java.util.HashMap; import java.util.Map; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -80,11 +83,17 @@ public class ModuleJsonTaskTest { TopologyTemplate topologyTemplate = new TopologyTemplate(); topologyTemplate.setInstGroups(instGroups); topologyTemplate.setInstDeploymentArtifacts(instDeploymentArtifacts); - when(topologyTemplateOperation.getToscaElement(ArgumentMatchers.eq(vertex.getUniqueId()), ArgumentMatchers.any(ComponentParametersView.class))).thenReturn(Either.left(topologyTemplate)); + when(topologyTemplateOperation.getToscaElement(ArgumentMatchers.eq(vertex.getUniqueId()), + ArgumentMatchers.any(ComponentParametersView.class))).thenReturn(Either.left(topologyTemplate)); + + // 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 try { - test.validate(vertex); + VertexResult actual = test.validate(vertex, null); + assertThat(actual.getStatus(), is(true)); } catch (Exception e) { - + // TODO: Fix this test, as currently, any exception is ignored + // This will be addressed in another change } } } diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java index 011039d591..938b2c2202 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java @@ -20,8 +20,6 @@ package org.openecomp.sdc.asdctool.impl.validator.utils; -import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager; - import java.io.BufferedReader; import java.io.IOException; import java.nio.file.Files; @@ -34,17 +32,17 @@ public class ReportManagerHelper { private ReportManagerHelper() { } - public static List getReportOutputFileAsList() { - return readFileAsList(ValidationConfigManager.getOutputFullFilePath()); + public static List getReportOutputFileAsList(String txtReportFilePath) { + return readFileAsList(txtReportFilePath); } public static List getReportCsvFileAsList(String csvReportFilePath) { return readFileAsList(csvReportFilePath); } - public static void cleanReports(String csvReportFilePath) { + public static void cleanReports(String csvReportFilePath, String txtReportFilePath) { cleanFile(csvReportFilePath); - cleanFile(ValidationConfigManager.getOutputFullFilePath()); + cleanFile(txtReportFilePath); } private static List readFileAsList(String filePath) { diff --git a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java index 22aaf6e539..6be7f472aa 100644 --- a/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java +++ b/asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java @@ -77,25 +77,20 @@ public class ReportManagerTest { private final static String resourcePath = new File("src/test/resources").getAbsolutePath(); private final static String csvReportFilePath = ValidationConfigManager .csvReportFilePath(resourcePath, System::currentTimeMillis); - + private final static String txtReportFilePath = ValidationConfigManager.txtReportFilePath(resourcePath); @Mock GraphVertex vertexScanned; @Before public void setup() { - String resourcePath = new File(Objects - .requireNonNull(ReportManagerTest.class.getClassLoader().getResource("")).getFile()) - .getAbsolutePath(); - ValidationConfigManager.setOutputFullFilePath(resourcePath); - ReportManager.make(csvReportFilePath); - + ReportManager.make(csvReportFilePath, txtReportFilePath); successResult.setStatus(true); } @After public void clean() { - ReportManagerHelper.cleanReports(csvReportFilePath); + ReportManagerHelper.cleanReports(csvReportFilePath, txtReportFilePath); } @Test @@ -118,9 +113,9 @@ public class ReportManagerTest { public void testAddFailedVertex() { // when ReportManager.addFailedVertex(TASK_1_NAME, VERTEX_1_ID); - ReportManager.reportEndOfToolRun(csvReportFilePath); + ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); @@ -137,9 +132,9 @@ public class ReportManagerTest { when(vertexScanned.getUniqueId()).thenReturn(UNIQUE_ID); // when - ReportManager.printValidationTaskStatus(vertexScanned, TASK_1_NAME, false); + ReportManager.printValidationTaskStatus(vertexScanned, TASK_1_NAME, false, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); @@ -152,9 +147,9 @@ public class ReportManagerTest { @Test public void testWriteReportLineToFile() { // when - ReportManager.writeReportLineToFile(DUMMY_MESSAGE); + ReportManager.writeReportLineToFile(DUMMY_MESSAGE, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); @@ -166,9 +161,10 @@ public class ReportManagerTest { @Test public void testReportValidatorTypeSummary() { // when - ReportManager.reportValidatorTypeSummary(VALIDATOR_NAME, failedTasksNames, successTasksNames); + ReportManager + .reportValidatorTypeSummary(VALIDATOR_NAME, failedTasksNames, successTasksNames, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); @@ -185,9 +181,9 @@ public class ReportManagerTest { @Test public void testReportStartValidatorRun() { // when - ReportManager.reportStartValidatorRun(VALIDATOR_NAME, COMPONENT_SUM); + ReportManager.reportStartValidatorRun(VALIDATOR_NAME, COMPONENT_SUM, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); @@ -202,9 +198,9 @@ public class ReportManagerTest { when(vertexScanned.getUniqueId()).thenReturn(UNIQUE_ID); // when - ReportManager.reportStartTaskRun(vertexScanned, TASK_1_NAME); + ReportManager.reportStartTaskRun(vertexScanned, TASK_1_NAME, txtReportFilePath); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath); // then assertNotNull(reportOutputFile); -- cgit 1.2.3-korg