From 83df155640dd015d68f01f784dfab24d4c252af1 Mon Sep 17 00:00:00 2001 From: Francis Toth Date: Sun, 19 Apr 2020 20:16:33 -0400 Subject: Remove csvReportFilePath from ValidationConfigManager This commit aims to extract the csvReportFilePath field from ValidationConfigManager in order to improve testability. This commit contains multiple minor modifications resulting from bubbling up the csvReportFilePath static field to where it is actually set. Put differently, most of the modifications result from changing the signature of the functions which formerly relied on ValidationConfigManager.getCSVReportFilePath. Change-Id: I82c3b0fca8a0f407319e40ecfff45e89ec1d4323 Signed-off-by: Francis Toth Issue-ID: SDC-2499 --- .../config/ValidationConfigManagerTest.java | 27 +++++++-------- .../artifacts/ArtifactValidationUtilsTest.java | 31 ++++++++++-------- .../impl/validator/utils/ReportManagerHelper.java | 8 ++--- .../impl/validator/utils/ReportManagerTest.java | 38 ++++++++++++---------- 4 files changed, 54 insertions(+), 50 deletions(-) (limited to 'asdctool/src/test/java/org') 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 efc7dd82a8..570e5b21df 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 @@ -20,6 +20,10 @@ package org.openecomp.sdc.asdctool.impl.validator.config; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager.csvReportFilePath; + import org.junit.Test; import org.junit.runner.RunWith; import org.openecomp.sdc.asdctool.impl.validator.utils.ReportManager; @@ -33,27 +37,20 @@ import java.util.Properties; public class ValidationConfigManagerTest { @Test - public void testGetOutputFilePath() { - String result; - - // default test - result = ValidationConfigManager.getOutputFilePath(); + public void testCsvReportFilePath() { + String randomOutput = System.currentTimeMillis() + ""; + long millis = System.currentTimeMillis(); + assertThat( + csvReportFilePath(randomOutput, () -> millis), + is(randomOutput + "/csvSummary_" + millis + ".csv")); } @Test - public void testGetCsvReportFilePath() { + public void testGetOutputFilePath() { String result; // default test - result = ValidationConfigManager.getCsvReportFilePath(); - } - - @Test - public void testSetCsvReportFilePath() { - String outputPath = ""; - - // default test - ValidationConfigManager.setCsvReportFilePath(outputPath); + result = ValidationConfigManager.getOutputFilePath(); } @Test 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 b5ce1abca0..1af4a13472 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 @@ -64,7 +64,7 @@ import static org.mockito.Mockito.when; @PowerMockRunnerDelegate(MockitoJUnitRunner.class) @PrepareForTest({ReportManager.class}) public class ArtifactValidationUtilsTest { - + @Mock private ArtifactCassandraDao artifactCassandraDao; @Mock @@ -91,12 +91,15 @@ public class ArtifactValidationUtilsTest { private static final String UNIQUE_ID = "4321"; private static final String UNIQUE_ID_VERTEX = "321"; + private final static String resourcePath = new File("src/test/resources").getAbsolutePath(); + private final static String csvReportFilePath = ValidationConfigManager.DEFAULT_CSV_PATH; + public void initReportManager() { String resourcePath = new File(Objects .requireNonNull(ArtifactValidationUtilsTest.class.getClassLoader().getResource("")) .getFile()).getAbsolutePath(); ValidationConfigManager.setOutputFullFilePath(resourcePath); - new ReportManager(); + ReportManager.make(csvReportFilePath); } @Before @@ -115,7 +118,7 @@ public class ArtifactValidationUtilsTest { @After public void clean() { - ReportManagerHelper.cleanReports(); + ReportManagerHelper.cleanReports(csvReportFilePath); } @Test @@ -146,7 +149,7 @@ public class ArtifactValidationUtilsTest { // when ArtifactsVertexResult result = testSubject.validateArtifactsAreInCassandra(vertex, TASK_NAME, artifacts); - ReportManager.reportEndOfToolRun(); + ReportManager.reportEndOfToolRun(csvReportFilePath); List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); @@ -203,19 +206,19 @@ public class ArtifactValidationUtilsTest { @Test public void testValidateTopologyTemplateArtifacts() { // given - Map artifacts = new HashMap<>(); - artifacts.put(ES_ID, artifactDataDefinition); + Map artifacts = new HashMap<>(); + artifacts.put(ES_ID, artifactDataDefinition); - when(topologyTemplate.getDeploymentArtifacts()).thenReturn(artifacts); - when(topologyTemplate.getArtifacts()).thenReturn(artifacts); - when(topologyTemplate.getServiceApiArtifacts()).thenReturn(artifacts); + when(topologyTemplate.getDeploymentArtifacts()).thenReturn(artifacts); + when(topologyTemplate.getArtifacts()).thenReturn(artifacts); + when(topologyTemplate.getServiceApiArtifacts()).thenReturn(artifacts); - when(mapToscaDataDefinition.getMapToscaDataDefinition()).thenReturn(artifacts); - Map artifactsMap = new HashMap<>(); - artifactsMap.put(ES_ID, mapToscaDataDefinition); + when(mapToscaDataDefinition.getMapToscaDataDefinition()).thenReturn(artifacts); + Map artifactsMap = new HashMap<>(); + artifactsMap.put(ES_ID, mapToscaDataDefinition); - when(topologyTemplate.getInstanceArtifacts()).thenReturn(artifactsMap); - when(topologyTemplate.getInstDeploymentArtifacts()).thenReturn(artifactsMap); + when(topologyTemplate.getInstanceArtifacts()).thenReturn(artifactsMap); + when(topologyTemplate.getInstDeploymentArtifacts()).thenReturn(artifactsMap); when(topologyTemplateOperation.getToscaElement(eq(vertex.getUniqueId()), any())) .thenReturn(Either.left(topologyTemplate)); 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 c832c47df4..011039d591 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 @@ -38,12 +38,12 @@ public class ReportManagerHelper { return readFileAsList(ValidationConfigManager.getOutputFullFilePath()); } - public static List getReportCsvFileAsList() { - return readFileAsList(ValidationConfigManager.getCsvReportFilePath()); + public static List getReportCsvFileAsList(String csvReportFilePath) { + return readFileAsList(csvReportFilePath); } - public static void cleanReports() { - cleanFile(ValidationConfigManager.getCsvReportFilePath()); + public static void cleanReports(String csvReportFilePath) { + cleanFile(csvReportFilePath); cleanFile(ValidationConfigManager.getOutputFullFilePath()); } 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 4926c1dee1..22aaf6e539 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 @@ -74,24 +74,28 @@ public class ReportManagerTest { private VertexResult successResult = new VertexResult(); + private final static String resourcePath = new File("src/test/resources").getAbsolutePath(); + private final static String csvReportFilePath = ValidationConfigManager + .csvReportFilePath(resourcePath, System::currentTimeMillis); + + @Mock GraphVertex vertexScanned; - @Before + @Before public void setup() { String resourcePath = new File(Objects .requireNonNull(ReportManagerTest.class.getClassLoader().getResource("")).getFile()) - .getAbsolutePath(); + .getAbsolutePath(); ValidationConfigManager.setOutputFullFilePath(resourcePath); - ValidationConfigManager.setCsvReportFilePath(resourcePath); - new ReportManager(); + ReportManager.make(csvReportFilePath); successResult.setStatus(true); } @After public void clean() { - ReportManagerHelper.cleanReports(); + ReportManagerHelper.cleanReports(csvReportFilePath); } @Test @@ -99,9 +103,9 @@ public class ReportManagerTest { // when ReportManager.reportTaskEnd(VERTEX_1_ID, TASK_1_NAME, successResult); ReportManager.reportTaskEnd(VERTEX_2_ID, TASK_2_NAME, successResult); - ReportManager.printAllResults(); + ReportManager.printAllResults(csvReportFilePath); - List reportCsvFile = ReportManagerHelper.getReportCsvFileAsList(); + List reportCsvFile = ReportManagerHelper.getReportCsvFileAsList(csvReportFilePath); // then assertNotNull(reportCsvFile); @@ -114,7 +118,7 @@ public class ReportManagerTest { public void testAddFailedVertex() { // when ReportManager.addFailedVertex(TASK_1_NAME, VERTEX_1_ID); - ReportManager.reportEndOfToolRun(); + ReportManager.reportEndOfToolRun(csvReportFilePath); List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); @@ -178,19 +182,19 @@ public class ReportManagerTest { reportOutputFile.get(4)); } - @Test - public void testReportStartValidatorRun() { - // when - ReportManager.reportStartValidatorRun(VALIDATOR_NAME, COMPONENT_SUM); + @Test + public void testReportStartValidatorRun() { + // when + ReportManager.reportStartValidatorRun(VALIDATOR_NAME, COMPONENT_SUM); - List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); + List reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(); - // then + // then assertNotNull(reportOutputFile); assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportOutputFile.get(0)); assertEquals("------ValidatorExecuter " + VALIDATOR_NAME + " Validation Started, on " + COMPONENT_SUM + " components---------", reportOutputFile.get(2)); - } + } @Test public void testReportStartTaskRun() { @@ -206,11 +210,11 @@ public class ReportManagerTest { assertNotNull(reportOutputFile); assertEquals(EXPECTED_OUTPUT_FILE_HEADER, reportOutputFile.get(0)); assertEquals("-----------------------Vertex: " + UNIQUE_ID + ", Task " + TASK_1_NAME - + " Started-----------------------", reportOutputFile.get(2)); + + " Started-----------------------", reportOutputFile.get(2)); } private String getCsvExpectedResult(String vertexID, String taskID) { - return String.join(",", new String[] {vertexID, taskID, + return String.join(",", new String[]{vertexID, taskID, String.valueOf(successResult.getStatus()), successResult.getResult()}); } } \ No newline at end of file -- cgit 1.2.3-korg