Remove outputFullFilePath from ValidationConfigManager 98/106798/5
authorFrancis Toth <francis.toth@yoppworks.com>
Mon, 20 Apr 2020 00:55:37 +0000 (20:55 -0400)
committerOjas Dubey <Ojas.Dubey@amdocs.com>
Tue, 12 May 2020 04:59:28 +0000 (04:59 +0000)
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 <francis.toth@yoppworks.com>
Issue-ID: SDC-2499

35 files changed:
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBL.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBL.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManager.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/IArtifactValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutor.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/TopologyTemplateValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutor.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/ValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuter.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/TopologyTemplateValidationTask.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtils.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTask.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTask.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTask.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManager.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ArtifactValidatorTool.java
asdctool/src/main/java/org/openecomp/sdc/asdctool/main/ValidationTool.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ArtifactToolBLTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/ValidationToolBLTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/config/ValidationConfigManagerTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ArtifactValidatorExecuterTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/NodeToscaArtifactsValidatorExecuterTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceToscaArtifactsValidatorExecutorTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/ServiceValidatorExecuterTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VFToscaArtifactValidatorExecutorTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/executers/VfValidatorExecuterTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ArtifactValidationUtilsTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/ServiceArtifactValidationTaskTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/artifacts/VfArtifactValidationTaskTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/tasks/moduleJson/ModuleJsonTaskTest.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerHelper.java
asdctool/src/test/java/org/openecomp/sdc/asdctool/impl/validator/utils/ReportManagerTest.java

index 2b63193..ebd5482 100644 (file)
@@ -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,31 +27,29 @@ import org.springframework.beans.factory.annotation.Autowired;
 import java.util.List;
 
 public class ArtifactToolBL {
-       
-        private static Logger log = Logger.getLogger(ValidationToolBL.class.getName());
-
-           protected List<IArtifactValidatorExecuter> validators;
-
-           private boolean allValid = true;
-
-       @Autowired
-       public ArtifactToolBL(
-               List<IArtifactValidatorExecuter> validators) {
-               this.validators = validators;
-       }
-
-       public boolean validateAll() {
-               for (IArtifactValidatorExecuter validatorExec: validators) {
-                   log.debug("ValidatorExecuter "+validatorExec.getName()+" started");
-                   if (!validatorExec.executeValidations()) {
-                       allValid = false;
-                       log.debug("ValidatorExecuter "+validatorExec.getName()+" finished with warnings");
-                   }
-                   else {
-                       log.debug("ValidatorExecuter "+validatorExec.getName()+" finished successfully");
-                   }
-               }
-               return allValid;
-           }
 
+    private static Logger log = Logger.getLogger(ValidationToolBL.class.getName());
+
+    protected List<IArtifactValidatorExecuter> validators;
+
+    private boolean allValid = true;
+
+    @Autowired
+    public ArtifactToolBL(
+        List<IArtifactValidatorExecuter> validators) {
+        this.validators = validators;
+    }
+
+    public boolean validateAll(String outputFilePath) {
+        for (IArtifactValidatorExecuter validatorExec : validators) {
+            log.debug("ValidatorExecuter " + validatorExec.getName() + " started");
+            if (!validatorExec.executeValidations(outputFilePath)) {
+                allValid = false;
+                log.debug("ValidatorExecuter " + validatorExec.getName() + " finished with warnings");
+            } else {
+                log.debug("ValidatorExecuter " + validatorExec.getName() + " finished successfully");
+            }
+        }
+        return allValid;
+    }
 }
index ae25c31..c73e4d4 100644 (file)
@@ -45,10 +45,10 @@ public class ValidationToolBL {
         this.validators = validators;
     }
 
-    public boolean validateAll() {
+    public boolean validateAll(String outputFilePath) {
         for (ValidatorExecuter validatorExec: validators) {
             log.debug("ValidatorExecuter "+validatorExec.getName()+" started");
-            if (!validatorExec.executeValidations()) {
+            if (!validatorExec.executeValidations(outputFilePath)) {
                 allValid = false;
                 log.debug("ValidatorExecuter "+validatorExec.getName()+" finished with warnings");
             }
index 3c09a54..6178fe3 100644 (file)
@@ -26,32 +26,21 @@ package org.openecomp.sdc.asdctool.impl.validator.config;
 
 import java.util.function.Supplier;
 
-public class ValidationConfigManager {
+public final class ValidationConfigManager {
 
+    private static final String REPORT_OUTPUT_FILE_NAME = "/reportOutput.txt";
     private static final String CSV_FILE_PREFIX = "/csvSummary_";
     private static final String CSV_EXT = ".csv";
     public static final String DEFAULT_CSV_PATH = "summary.csv";
 
-    private static String outputFullFilePath;
-    private static String outputFilePath;
-
     private ValidationConfigManager() {
     }
 
-    public static String csvReportFilePath(String outputPath, Supplier<Long> getTime) {
-        return outputPath + CSV_FILE_PREFIX + getTime.get() + CSV_EXT;
-    }
-
-    public static String getOutputFullFilePath() {
-        return outputFullFilePath;
+    public static String txtReportFilePath(String outputPath) {
+        return outputPath + REPORT_OUTPUT_FILE_NAME;
     }
 
-    public static String getOutputFilePath() {
-        return outputFilePath;
-    }
-
-    public static void setOutputFullFilePath(String outputPath) {
-        ValidationConfigManager.outputFilePath = outputPath;
-        ValidationConfigManager.outputFullFilePath = outputPath + "/reportOutput.txt";
+    public static String csvReportFilePath(String outputPath, Supplier<Long> getTime) {
+        return outputPath + CSV_FILE_PREFIX + getTime.get() + CSV_EXT;
     }
 }
index a5e7d78..9007d8c 100644 (file)
@@ -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.
@@ -49,111 +49,116 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 
-public class ArtifactValidatorExecuter{
-
-        protected JanusGraphDao janusGraphDao;
-       protected ToscaOperationFacade toscaOperationFacade;
-
-       public ArtifactValidatorExecuter(JanusGraphDao janusGraphDao,
-               ToscaOperationFacade toscaOperationFacade) {
-               this.janusGraphDao = janusGraphDao;
-               this.toscaOperationFacade = toscaOperationFacade;
-       }
-
-       private static Logger log = Logger.getLogger(ArtifactValidatorExecuter.class.getName());
-        
-        protected String name;
-
-           public void setName(String name) {
-               this.name = name;
-           }
-
-           public String getName() {
-               return name;
-           }
-
-        
-       
-          public Map<String, List<Component>> getVerticesToValidate(VertexTypeEnum type, Map<GraphPropertyEnum, Object> hasProps){
-                  Map<String, List<Component>> result = new HashMap<>();
-               Either<List<GraphVertex>, JanusGraphOperationStatus> resultsEither = janusGraphDao
-              .getByCriteria(type, hasProps);
-               if (resultsEither.isRight()) {
-                       log.error("getVerticesToValidate failed "+ resultsEither.right().value());
-                   return result;
-               }
-               System.out.println("getVerticesToValidate: "+resultsEither.left().value().size()+" vertices to scan");
-               List<GraphVertex> componentsList = resultsEither.left().value();
-               componentsList.forEach(vertex -> {
-                       String ivariantUuid = (String)vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
-                       if(!result.containsKey(ivariantUuid)){
-                               List<Component> compList = new ArrayList<Component>();
-                               result.put(ivariantUuid, compList);
-                       }
-                       List<Component> compList = result.get(ivariantUuid);
-                       
-                       ComponentParametersView filter = new ComponentParametersView(true);                             
-                               filter.setIgnoreArtifacts(false);
-                               
-                               Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade.getToscaElement(vertex.getUniqueId(), filter);
-                               if (toscaElement.isRight()) {
-                                       log.error("getVerticesToValidate: failed to find element"+ vertex.getUniqueId()+" staus is" + toscaElement.right().value());
-                               }else{
-                                       compList.add(toscaElement.left().value());
-                               }
-                        
-               });             
-             
-                       return result;
-           }
-           
-          public boolean validate( Map<String, List<Component>> vertices) {
-                  boolean result = true;
-                  long time = System.currentTimeMillis();
-                  String fileName = ValidationConfigManager.getOutputFilePath() + this.getName() + "_"+ time + ".csv";
-                  try(Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
-                       writer.write("name, UUID, invariantUUID, state, version\n");
-                       Collection<List<Component>> collection = vertices.values();
-                       for(List<Component> compList: collection ){
-                               Set<String> artifactEsId = new HashSet<>();
-                               for(Component component: compList ){
-                                       Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
-                                       Optional<ArtifactDefinition> op = toscaArtifacts.values().
-                                                       stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny();
-                                       if(op.isPresent()){
-                                               result = false;
-                                               writeModuleResultToFile(writer, compList);
-                                               writer.flush();
-                                               break;
-                                       }else{
-                                               artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId).collect(Collectors.toList()))     ;
-                                       }
-                               }
-                               
-                       }
-                       
-                  } catch (Exception e) {
-                               log.error("Failed to fetch vf resources ", e);
-                               return false;
-                       } finally {
-                               janusGraphDao.commit();
-                       }
-                       return result;
-           }
-          
-          private void writeModuleResultToFile(Writer writer, List<Component> components) {
-                       try {
-                               // "service name, service id, state, version
-                               for(Component component: components ){
-                                       StringBuffer sb = new StringBuffer(component.getName());
-                                       sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID()).append(",").append(component.getLifecycleState()).append(",").append(component.getVersion());
-                                       
-                                       sb.append("\n");
-                                       writer.write(sb.toString());
-                               }
-                       } catch (IOException e) {
-                               log.error("Failed to write module result to file ", e);
-                       }
-               }
+public class ArtifactValidatorExecuter {
+
+    protected JanusGraphDao janusGraphDao;
+    protected ToscaOperationFacade toscaOperationFacade;
+
+    public ArtifactValidatorExecuter(JanusGraphDao janusGraphDao,
+        ToscaOperationFacade toscaOperationFacade) {
+        this.janusGraphDao = janusGraphDao;
+        this.toscaOperationFacade = toscaOperationFacade;
+    }
+
+    private static Logger log = Logger.getLogger(ArtifactValidatorExecuter.class.getName());
+
+    protected String name;
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+
+    public Map<String, List<Component>> getVerticesToValidate(VertexTypeEnum type,
+        Map<GraphPropertyEnum, Object> hasProps) {
+        Map<String, List<Component>> result = new HashMap<>();
+        Either<List<GraphVertex>, JanusGraphOperationStatus> resultsEither = janusGraphDao
+            .getByCriteria(type, hasProps);
+        if (resultsEither.isRight()) {
+            log.error("getVerticesToValidate failed " + resultsEither.right().value());
+            return result;
+        }
+        System.out.println("getVerticesToValidate: " + resultsEither.left().value().size() + " vertices to scan");
+        List<GraphVertex> componentsList = resultsEither.left().value();
+        componentsList.forEach(vertex -> {
+            String ivariantUuid = (String) vertex.getMetadataProperty(GraphPropertyEnum.INVARIANT_UUID);
+            if (!result.containsKey(ivariantUuid)) {
+                List<Component> compList = new ArrayList<Component>();
+                result.put(ivariantUuid, compList);
+            }
+            List<Component> compList = result.get(ivariantUuid);
+
+            ComponentParametersView filter = new ComponentParametersView(true);
+            filter.setIgnoreArtifacts(false);
+
+            Either<Component, StorageOperationStatus> toscaElement = toscaOperationFacade
+                .getToscaElement(vertex.getUniqueId(), filter);
+            if (toscaElement.isRight()) {
+                log.error(
+                    "getVerticesToValidate: failed to find element" + vertex.getUniqueId() + " staus is" + toscaElement
+                        .right().value());
+            } else {
+                compList.add(toscaElement.left().value());
+            }
+
+        });
+
+        return result;
+    }
+
+    public boolean validate(Map<String, List<Component>> vertices, String outputFilePath) {
+        boolean result = true;
+        long time = System.currentTimeMillis();
+        String fileName = outputFilePath + this.getName() + "_" + time + ".csv";
+        try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), "utf-8"))) {
+            writer.write("name, UUID, invariantUUID, state, version\n");
+            Collection<List<Component>> collection = vertices.values();
+            for (List<Component> compList : collection) {
+                Set<String> artifactEsId = new HashSet<>();
+                for (Component component : compList) {
+                    Map<String, ArtifactDefinition> toscaArtifacts = component.getToscaArtifacts();
+                    Optional<ArtifactDefinition> op = toscaArtifacts.values().
+                        stream().filter(a -> artifactEsId.contains(a.getEsId())).findAny();
+                    if (op.isPresent()) {
+                        result = false;
+                        writeModuleResultToFile(writer, compList);
+                        writer.flush();
+                        break;
+                    } else {
+                        artifactEsId.addAll(toscaArtifacts.values().stream().map(ArtifactDefinition::getEsId)
+                            .collect(Collectors.toList()));
+                    }
+                }
+
+            }
+
+        } catch (Exception e) {
+            log.error("Failed to fetch vf resources ", e);
+            return false;
+        } finally {
+            janusGraphDao.commit();
+        }
+        return result;
+    }
+
+    private void writeModuleResultToFile(Writer writer, List<Component> components) {
+        try {
+            // "service name, service id, state, version
+            for (Component component : components) {
+                StringBuffer sb = new StringBuffer(component.getName());
+                sb.append(",").append(component.getUniqueId()).append(",").append(component.getInvariantUUID())
+                    .append(",").append(component.getLifecycleState()).append(",").append(component.getVersion());
+
+                sb.append("\n");
+                writer.write(sb.toString());
+            }
+        } catch (IOException e) {
+            log.error("Failed to write module result to file ", e);
+        }
+    }
 
 }
index a0d700c..1b3c037 100644 (file)
@@ -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,9 +21,8 @@
 package org.openecomp.sdc.asdctool.impl.validator.executers;
 
 public interface IArtifactValidatorExecuter {
-    boolean executeValidations();
+
+    boolean executeValidations(String outputFilePath);
+
     String getName();
-    
-  
-    
 }
index 9fa9220..6a52e07 100644 (file)
@@ -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.
@@ -32,34 +32,33 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-public class NodeToscaArtifactsValidatorExecuter extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter{
-        protected String name;
-       
-        public NodeToscaArtifactsValidatorExecuter(JanusGraphDao janusGraphDao,
-                ToscaOperationFacade toscaOperationFacade) {
-                                       super(janusGraphDao, toscaOperationFacade);
-               setName("RESOURCE_TOSCA_ARTIFACTS");
-           }
-       @Override
-       public boolean executeValidations() {
-               
-               Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
-               hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());              
-               hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());             
-               
-               Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.NODE_TYPE, hasProps);
-        return validate(vertices);
-               
-       }
+public class NodeToscaArtifactsValidatorExecuter extends ArtifactValidatorExecuter implements
+    IArtifactValidatorExecuter {
 
-       @Override
-       public String getName() {               
-               return name;
-       }       
-       
+    protected String name;
 
-       public void setName(String name) {
-               this.name = name;
-       }
+    public NodeToscaArtifactsValidatorExecuter(JanusGraphDao janusGraphDao,
+        ToscaOperationFacade toscaOperationFacade) {
+        super(janusGraphDao, toscaOperationFacade);
+        setName("RESOURCE_TOSCA_ARTIFACTS");
+    }
 
+    @Override
+    public boolean executeValidations(String outputFilePath) {
+        Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+        hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+        hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
+
+        Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.NODE_TYPE, hasProps);
+        return validate(vertices, outputFilePath);
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 }
index aad803e..21a8065 100644 (file)
@@ -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.
@@ -34,33 +34,32 @@ import java.util.List;
 import java.util.Map;
 
 @org.springframework.stereotype.Component
-public class ServiceToscaArtifactsValidatorExecutor extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter{
-        
-               @Autowired
-        public ServiceToscaArtifactsValidatorExecutor(JanusGraphDao janusGraphDao,
-                       ToscaOperationFacade toscaOperationFacade) {
-                       super(janusGraphDao, toscaOperationFacade);
-                       setName("SERVICE_TOSCA_ARTIFACTS");
-               }
+public class ServiceToscaArtifactsValidatorExecutor extends ArtifactValidatorExecuter implements
+    IArtifactValidatorExecuter {
 
-       @Override
-       public boolean executeValidations() {
-               Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
-               hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
-               hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
-               
-               Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
-        return validate(vertices);
-       }
+    @Autowired
+    public ServiceToscaArtifactsValidatorExecutor(JanusGraphDao janusGraphDao,
+        ToscaOperationFacade toscaOperationFacade) {
+        super(janusGraphDao, toscaOperationFacade);
+        setName("SERVICE_TOSCA_ARTIFACTS");
+    }
 
-       @Override
-       public String getName() {               
-               return name;
-       }       
-       
+    @Override
+    public boolean executeValidations(String outputFilePath) {
+        Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+        hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name());
+        hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
 
-       public void setName(String name) {
-               this.name = name;
-       }
+        Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
+        return validate(vertices, outputFilePath);
+    }
 
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 }
index a52fb37..6d580d0 100644 (file)
@@ -45,9 +45,9 @@ public class ServiceValidatorExecuter extends TopologyTemplateValidatorExecuter
     }
 
     @Override
-    public boolean executeValidations() {
+    public boolean executeValidations(String outputFilePath) {
         List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.SERVICE);
-        return validate(tasks, vertices);
+        return validate(tasks, vertices, outputFilePath);
     }
 
     @Override
index ca027cb..b7195de 100644 (file)
@@ -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.
@@ -68,34 +68,35 @@ public class TopologyTemplateValidatorExecuter {
     protected List<GraphVertex> getVerticesToValidate(ComponentTypeEnum type) {
         Map<GraphPropertyEnum, Object> props = new EnumMap<>(GraphPropertyEnum.class);
         props.put(GraphPropertyEnum.COMPONENT_TYPE, type.name());
-        if(type.equals(ComponentTypeEnum.RESOURCE)) {
+        if (type.equals(ComponentTypeEnum.RESOURCE)) {
             props.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
         }
 
         Either<List<GraphVertex>, JanusGraphOperationStatus> results = janusGraphDao
             .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, props);
         if (results.isRight()) {
-            log.error("getVerticesToValidate failed "+ results.right().value());
+            log.error("getVerticesToValidate failed " + results.right().value());
             return new ArrayList<>();
         }
-        log.info("getVerticesToValidate: "+results.left().value().size()+" vertices to scan");
+        log.info("getVerticesToValidate: " + results.left().value().size() + " vertices to scan");
         return results.left().value();
     }
 
-    protected boolean validate(List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices) {
-        ReportManager.reportStartValidatorRun(getName(), vertices.size());
+    protected boolean validate(List<? extends TopologyTemplateValidationTask> tasks, List<GraphVertex> vertices,
+        String outputFilePath) {
+        ReportManager.reportStartValidatorRun(getName(), vertices.size(), outputFilePath);
         Set<String> failedTasks = new HashSet<>();
         Set<String> successTasks = new HashSet<>();
         boolean successAllVertices = true;
         int vertexNum = 0;
         int verticesSize = vertices.size();
 
-        for (GraphVertex vertex: vertices) {
+        for (GraphVertex vertex : vertices) {
             vertexNum++;
             boolean successAllTasks = true;
-            for (TopologyTemplateValidationTask task: tasks) {
-                ReportManager.reportStartTaskRun(vertex, task.getTaskName());
-                VertexResult result = task.validate(vertex);
+            for (TopologyTemplateValidationTask task : tasks) {
+                ReportManager.reportStartTaskRun(vertex, task.getTaskName(), outputFilePath);
+                VertexResult result = task.validate(vertex, outputFilePath);
                 if (!result.getStatus()) {
                     failedTasks.add(task.getTaskName());
                     successAllVertices = false;
@@ -103,13 +104,13 @@ public class TopologyTemplateValidatorExecuter {
                 } else if (successAllTasks && vertexNum == verticesSize) {
                     successTasks.add(task.getTaskName());
                 }
-                ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus());
+                ReportManager.printValidationTaskStatus(vertex, task.getTaskName(), result.getStatus(), outputFilePath);
                 ReportManager.reportTaskEnd(vertex.getUniqueId(), task.getTaskName(), result);
             }
-            String componentScanStatus = successAllTasks? "success" : "failed";
-            log.info("Topology Template "+vertex.getUniqueId()+" Validation finished with "+componentScanStatus);
+            String componentScanStatus = successAllTasks ? "success" : "failed";
+            log.info("Topology Template " + vertex.getUniqueId() + " Validation finished with " + componentScanStatus);
         }
-        ReportManager.reportValidatorTypeSummary(getName(), failedTasks, successTasks);
+        ReportManager.reportValidatorTypeSummary(getName(), failedTasks, successTasks, outputFilePath);
         return successAllVertices;
     }
 }
index f1c9af6..b5347a2 100644 (file)
@@ -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.
@@ -33,35 +33,32 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-public class VFToscaArtifactValidatorExecutor extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter{
-       
-       public VFToscaArtifactValidatorExecutor(JanusGraphDao janusGraphDao,
-               ToscaOperationFacade toscaOperationFacade) {
-               super(janusGraphDao, toscaOperationFacade);
-               setName("VF_TOSCA_ARTIFACTS");
-           }
-       @Override
-       public boolean executeValidations() {
-               
-               Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
-               hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());      
-               hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
-               hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());             
-               
-               Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
-               return validate( vertices);
-               
-       }
+public class VFToscaArtifactValidatorExecutor extends ArtifactValidatorExecuter implements IArtifactValidatorExecuter {
 
-       @Override
-       public String getName() {               
-               return name;
-       }       
-       
+    public VFToscaArtifactValidatorExecutor(JanusGraphDao janusGraphDao,
+        ToscaOperationFacade toscaOperationFacade) {
+        super(janusGraphDao, toscaOperationFacade);
+        setName("VF_TOSCA_ARTIFACTS");
+    }
 
-       public void setName(String name) {
-               this.name = name;
-       }
-       
+    @Override
+    public boolean executeValidations(String outputFilePath) {
+        Map<GraphPropertyEnum, Object> hasProps = new HashMap<>();
+        hasProps.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.RESOURCE.name());
+        hasProps.put(GraphPropertyEnum.RESOURCE_TYPE, ResourceTypeEnum.VF);
+        hasProps.put(GraphPropertyEnum.STATE, LifecycleStateEnum.CERTIFIED.name());
 
+        Map<String, List<Component>> vertices = getVerticesToValidate(VertexTypeEnum.TOPOLOGY_TEMPLATE, hasProps);
+        return validate(vertices, outputFilePath);
+
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 }
index 3164b6c..db41cb5 100644 (file)
@@ -25,6 +25,6 @@ package org.openecomp.sdc.asdctool.impl.validator.executers;
  */
 public interface ValidatorExecuter {
 
-    boolean executeValidations();
+    boolean executeValidations(String outputFilePath);
     String getName();
 }
index 181495a..dc4ebab 100644 (file)
@@ -43,9 +43,9 @@ public class VfValidatorExecuter extends TopologyTemplateValidatorExecuter imple
     }
 
     @Override
-    public boolean executeValidations() {
+    public boolean executeValidations(String outputFilePath) {
         List<GraphVertex> vertices = getVerticesToValidate(ComponentTypeEnum.RESOURCE);
-        return validate(tasks, vertices);
+        return validate(tasks, vertices, outputFilePath);
     }
 
     @Override
index ee05d58..576848d 100644 (file)
@@ -27,7 +27,7 @@ import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
  * Created by chaya on 7/5/2017.
  */
 public interface TopologyTemplateValidationTask {
-    VertexResult validate(GraphVertex vertex);
+    VertexResult validate(GraphVertex vertex, String outputFilePath);
     String getTaskName();
     String getTaskResultStatus();
     void setTaskResultStatus(String status);
index 11c80ea..6da79cf 100644 (file)
@@ -60,13 +60,14 @@ public class ArtifactValidationUtils {
         this.topologyTemplateOperation = topologyTemplateOperation;
     }
 
-    public ArtifactsVertexResult validateArtifactsAreInCassandra(GraphVertex vertex, String taskName, List<ArtifactDataDefinition> artifacts) {
+    public ArtifactsVertexResult validateArtifactsAreInCassandra(GraphVertex vertex, String taskName,
+        List<ArtifactDataDefinition> artifacts, String outputFilePath) {
         ArtifactsVertexResult result = new ArtifactsVertexResult(true);
-        for(ArtifactDataDefinition artifact:artifacts) {
+        for (ArtifactDataDefinition artifact : artifacts) {
             boolean isArtifactExist = isArtifactInCassandra(artifact.getEsId());
             String status = isArtifactExist ? "Artifact " + artifact.getEsId() + " is in Cassandra" :
-                    "Artifact " + artifact.getEsId() + " doesn't exist in Cassandra";
-            ReportManager.writeReportLineToFile(status);
+                "Artifact " + artifact.getEsId() + " doesn't exist in Cassandra";
+            ReportManager.writeReportLineToFile(status, outputFilePath);
             if (!isArtifactExist) {
                 ReportManager.addFailedVertex(taskName, vertex.getUniqueId());
                 result.setStatus(false);
@@ -97,13 +98,15 @@ public class ArtifactValidationUtils {
         return artifacts;
     }
 
-    public ArtifactsVertexResult validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName) {
+    public ArtifactsVertexResult validateTopologyTemplateArtifacts(GraphVertex vertex, String taskName,
+        String outputFilePath) {
         ArtifactsVertexResult result = new ArtifactsVertexResult();
         ComponentParametersView paramView = new ComponentParametersView();
         paramView.disableAll();
         paramView.setIgnoreArtifacts(false);
         paramView.setIgnoreComponentInstances(false);
-        Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView);
+        Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation
+            .getToscaElement(vertex.getUniqueId(), paramView);
         if (toscaElementEither.isRight()) {
             result.setStatus(false);
             return result;
@@ -123,14 +126,14 @@ public class ArtifactValidationUtils {
 
         if (instanceArtifacts != null) {
             instanceArtifacts.forEach((key, artifactMap) ->
-                    allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())));
+                allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())));
         }
 
         if (instanceDeploymentArtifacts != null) {
             instanceDeploymentArtifacts.forEach((key, artifactMap) ->
-                    allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())));
+                allArtifacts.addAll(addRelevantArtifacts(artifactMap.getMapToscaDataDefinition())));
         }
 
-        return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts);
+        return validateArtifactsAreInCassandra(vertex, taskName, allArtifacts, outputFilePath);
     }
 }
index 3b47a81..7caaa3c 100644 (file)
@@ -39,7 +39,7 @@ public class ServiceArtifactValidationTask extends ServiceValidationTask {
     }
 
     @Override
-    public ArtifactsVertexResult validate(GraphVertex vertex) {
-        return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName());
+    public ArtifactsVertexResult validate(GraphVertex vertex, String outputFilePath) {
+        return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName(), outputFilePath);
     }
 }
index c445521..eb65b0c 100644 (file)
@@ -40,7 +40,7 @@ public class VfArtifactValidationTask extends VfValidationTask {
     }
 
     @Override
-    public VertexResult validate(GraphVertex vertex) {
-        return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName());
+    public VertexResult validate(GraphVertex vertex, String outputFilePath) {
+        return artifactValidationUtils.validateTopologyTemplateArtifacts(vertex, getTaskName(), outputFilePath);
     }
 }
index d45c896..47f00dc 100644 (file)
@@ -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.
@@ -59,7 +59,7 @@ public class ModuleJsonTask extends ServiceValidationTask {
     }
 
     @Override
-    public VertexResult validate(GraphVertex vertex) {
+    public VertexResult validate(GraphVertex vertex, String outputFilePath) {
         if (!isAfterSubmitForTesting(vertex)) {
             return new VertexResult(true);
         }
@@ -69,7 +69,8 @@ public class ModuleJsonTask extends ServiceValidationTask {
         paramView.setIgnoreArtifacts(false);
         paramView.setIgnoreGroups(false);
         paramView.setIgnoreComponentInstances(false);
-        Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation.getToscaElement(vertex.getUniqueId(), paramView);
+        Either<ToscaElement, StorageOperationStatus> toscaElementEither = topologyTemplateOperation
+            .getToscaElement(vertex.getUniqueId(), paramView);
         if (toscaElementEither.isRight()) {
             return new VertexResult(false);
         }
@@ -77,42 +78,47 @@ public class ModuleJsonTask extends ServiceValidationTask {
         Map<String, MapGroupsDataDefinition> instGroups = element.getInstGroups();
         Map<String, MapArtifactDataDefinition> instDeploymentArtifacts = element.getInstDeploymentArtifacts();
 
-        for (Map.Entry<String, MapGroupsDataDefinition> pair : Optional.ofNullable(instGroups).orElse(Collections.emptyMap()).entrySet()) {
+        for (Map.Entry<String, MapGroupsDataDefinition> pair : Optional.ofNullable(instGroups)
+            .orElse(Collections.emptyMap()).entrySet()) {
             MapGroupsDataDefinition groups = pair.getValue();
             if (groups != null && !groups.getMapToscaDataDefinition().isEmpty()) {
-                return new VertexResult(findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex));
+                return new VertexResult(findCoordinateModuleJson(pair, instDeploymentArtifacts, vertex, outputFilePath));
             }
             return new VertexResult(true);
         }
         return new VertexResult(true);
     }
 
-    private boolean findCoordinateModuleJson(Map.Entry<String, MapGroupsDataDefinition> pair, Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, GraphVertex vertex) {
+    private boolean findCoordinateModuleJson(Map.Entry<String, MapGroupsDataDefinition> pair,
+        Map<String, MapArtifactDataDefinition> instDeploymentArtifacts, GraphVertex vertex, String outputFilePath) {
         String groupKey = pair.getKey();
         String[] split = groupKey.split("\\.");
-        String instanceName = split[split.length-1];
+        String instanceName = split[split.length - 1];
         MapArtifactDataDefinition deploymentsArtifacts = instDeploymentArtifacts.get(groupKey);
         if (deploymentsArtifacts != null && !deploymentsArtifacts.getMapToscaDataDefinition().isEmpty()) {
-            List<ArtifactDataDefinition> moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values().stream().filter(artifact -> {
-                String artifactName = artifact.getArtifactName();
-                if (artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json")) {
-                    return true;
-                }
-                return false;
-            }).collect(Collectors.toList());
+            List<ArtifactDataDefinition> moduleJsonArtifacts = deploymentsArtifacts.getMapToscaDataDefinition().values()
+                .stream().filter(artifact -> {
+                    String artifactName = artifact.getArtifactName();
+                    if (artifactName.startsWith(instanceName) && artifactName.endsWith("modules.json")) {
+                        return true;
+                    }
+                    return false;
+                }).collect(Collectors.toList());
             if (moduleJsonArtifacts.size() > 0) {
-                String status = "Instance "+instanceName+" has a corresponding modules.json file: "+moduleJsonArtifacts.get(0).getArtifactName();
-                ReportManager.writeReportLineToFile(status);
+                String status =
+                    "Instance " + instanceName + " has a corresponding modules.json file: " + moduleJsonArtifacts.get(0)
+                        .getArtifactName();
+                ReportManager.writeReportLineToFile(status, outputFilePath);
                 return true;
             }
         }
-        String status = "Instance "+instanceName+" doesn't have a corresponding modules.json file";
-        ReportManager.writeReportLineToFile(status);
+        String status = "Instance " + instanceName + " doesn't have a corresponding modules.json file";
+        ReportManager.writeReportLineToFile(status, outputFilePath);
         ReportManager.addFailedVertex(getTaskName(), vertex.getUniqueId());
         return false;
     }
 
-    private boolean isAfterSubmitForTesting(GraphVertex vertex){
+    private boolean isAfterSubmitForTesting(GraphVertex vertex) {
         List allowedStates = new ArrayList<>(Arrays.asList(LifecycleStateEnum.CERTIFIED.name()));
         return allowedStates.contains(vertex.getMetadataProperty(GraphPropertyEnum.STATE));
     }
index feef9ea..78910df 100644 (file)
@@ -22,7 +22,6 @@
 package org.openecomp.sdc.asdctool.impl.validator.utils;
 
 import org.apache.commons.lang.text.StrBuilder;
-import org.openecomp.sdc.asdctool.impl.validator.config.ValidationConfigManager;
 import org.openecomp.sdc.be.dao.jsongraph.GraphVertex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,28 +39,27 @@ import java.util.Set;
 public class ReportManager {
 
     private static Logger log = LoggerFactory.getLogger(ReportManager.class);
-    private static String reportOutputFilePath;
+
     private static final Map<String, Set<String>> failedVerticesPerTask = new HashMap<>();
     private static final Map<String, Map<String, VertexResult>> resultsPerVertex = new HashMap<>();
 
-    public static ReportManager make(String csvReportFilePath) {
-        return new ReportManager(csvReportFilePath);
+    public static ReportManager make(String csvReportFilePath, String txtReportFilePath) {
+        return new ReportManager(csvReportFilePath, txtReportFilePath);
     }
 
-    private ReportManager(String csvReportFilePath) {
+    private ReportManager(String csvReportFilePath, String txtReportFilePath) {
         try {
             initCsvFile(csvReportFilePath);
-            initReportFile();
+            initReportFile(txtReportFilePath);
         } catch (IOException e) {
             log.info("Init file failed - {}", e.getClass().getSimpleName(), e);
         }
     }
 
-    private void initReportFile() throws IOException {
-        reportOutputFilePath = ValidationConfigManager.getOutputFullFilePath();
+    private void initReportFile(String txtReportFilePath) throws IOException {
         StrBuilder sb = new StrBuilder();
         sb.appendln("-----------------------Validation Tool Results:-------------------------");
-        Files.write(Paths.get(reportOutputFilePath), sb.toString().getBytes());
+        Files.write(Paths.get(txtReportFilePath), sb.toString().getBytes());
     }
 
     private void initCsvFile(String csvReportFilePath) throws IOException {
@@ -87,51 +85,52 @@ public class ReportManager {
         failedVerticesPerTask.put(taskName, failedVertices);
     }
 
-    public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success) {
+    public static void printValidationTaskStatus(GraphVertex vertexScanned, String taskName, boolean success,
+        String outputFilePath) {
         String successStatus = success ? "success" : "failed";
         String line =
             "-----------------------Vertex: " + vertexScanned.getUniqueId() + ", Task " + taskName + " " + successStatus
                 + "-----------------------";
         StrBuilder sb = new StrBuilder();
         sb.appendln(line);
-        writeReportLineToFile(line);
+        writeReportLineToFile(line, outputFilePath);
     }
 
-    public static void writeReportLineToFile(String message) {
+    public static void writeReportLineToFile(String message, String outputFilePath) {
         try {
-            Files.write(Paths.get(reportOutputFilePath), new StrBuilder().appendNewLine().toString().getBytes(),
+            Files.write(Paths.get(outputFilePath), new StrBuilder().appendNewLine().toString().getBytes(),
                 StandardOpenOption.APPEND);
-            Files.write(Paths.get(reportOutputFilePath), message.getBytes(), StandardOpenOption.APPEND);
+            Files.write(Paths.get(outputFilePath), message.getBytes(), StandardOpenOption.APPEND);
         } catch (IOException e) {
             log.info("write to file failed - {}", e.getClass().getSimpleName(), e);
         }
     }
 
     public static void reportValidatorTypeSummary(String validatorName, Set<String> failedTasksNames,
-        Set<String> successTasksNames) {
+        Set<String> successTasksNames, String outputFilePath) {
         StrBuilder sb = new StrBuilder();
         sb.appendln(
             "-----------------------ValidatorExecuter " + validatorName + " Validation Summary-----------------------");
         sb.appendln("Failed tasks: " + failedTasksNames);
         sb.appendln("Success tasks: " + successTasksNames);
-        writeReportLineToFile(sb.toString());
+        writeReportLineToFile(sb.toString(), outputFilePath);
     }
 
-    public static void reportStartValidatorRun(String validatorName, int componenentsNum) {
+    public static void reportStartValidatorRun(String validatorName, int componenentsNum, String outputFilePath) {
         StrBuilder sb = new StrBuilder();
         sb.appendln("------ValidatorExecuter " + validatorName + " Validation Started, on " + componenentsNum
             + " components---------");
-        writeReportLineToFile(sb.toString());
+        writeReportLineToFile(sb.toString(), outputFilePath);
     }
 
-    public static void reportStartTaskRun(GraphVertex vertex, String taskName) {
+    public static void reportStartTaskRun(GraphVertex vertex, String taskName, String outputFilePath) {
         StrBuilder sb = new StrBuilder();
         sb.appendln("-----------------------Vertex: " + vertex.getUniqueId() + ", Task " + taskName
             + " Started-----------------------");
-        writeReportLineToFile(sb.toString());
+        writeReportLineToFile(sb.toString(), outputFilePath);
     }
 
-    public static void reportEndOfToolRun(String csvReportFilePath) {
+    public static void reportEndOfToolRun(String csvReportFilePath, String outputFilePath) {
         StrBuilder sb = new StrBuilder();
         sb.appendln("-----------------------------------Validator Tool Summary-----------------------------------");
         failedVerticesPerTask.forEach((taskName, failedVertices) -> {
@@ -140,7 +139,7 @@ public class ReportManager {
             sb.append("FailedVertices: " + failedVertices);
             sb.appendNewLine();
         });
-        writeReportLineToFile(sb.toString());
+        writeReportLineToFile(sb.toString(), outputFilePath);
         printAllResults(csvReportFilePath);
     }
 
index 063f3f6..0978f4e 100644 (file)
@@ -31,14 +31,14 @@ public class ArtifactValidatorTool {
     public static void main(String[] args) {
 
         String outputPath = args[0];
-        ValidationConfigManager.setOutputFullFilePath(outputPath);
+        String txtReportFilePath = ValidationConfigManager.txtReportFilePath(outputPath);
 
         String appConfigDir = args[1];
         AnnotationConfigApplicationContext context = initContext(appConfigDir);
         ArtifactToolBL validationToolBL = context.getBean(ArtifactToolBL.class);
 
         System.out.println("Start ArtifactValidation Tool");
-        Boolean result = validationToolBL.validateAll();
+        Boolean result = validationToolBL.validateAll(txtReportFilePath);
         if (result) {
             System.out.println("ArtifactValidation finished successfully");
             System.exit(0);
index 23b9c18..d98a26b 100644 (file)
@@ -41,7 +41,7 @@ public class ValidationTool {
     public static void main(String[] args) {
 
         String outputPath = args[0];
-        ValidationConfigManager.setOutputFullFilePath(outputPath);
+        String txtReportFilePath = ValidationConfigManager.txtReportFilePath(outputPath);
         String csvReportFilePath = ValidationConfigManager.csvReportFilePath(outputPath, System::currentTimeMillis);
 
         String appConfigDir = args[1];
@@ -49,8 +49,8 @@ public class ValidationTool {
         ValidationToolBL validationToolBL = context.getBean(ValidationToolBL.class);
 
         log.info("Start Validation Tool");
-        boolean result = validationToolBL.validateAll();
-        ReportManager.reportEndOfToolRun(csvReportFilePath);
+        boolean result = validationToolBL.validateAll(txtReportFilePath);
+        ReportManager.reportEndOfToolRun(csvReportFilePath, txtReportFilePath);
         if (result) {
             log.info("Validation finished successfully");
             System.exit(0);
index ee41d62..e6ae05f 100644 (file)
@@ -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.
 
 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);
+    }
 }
index f7f8307..b412d7b 100644 (file)
@@ -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);
+    }
 }
index 570e5b2..b763520 100644 (file)
@@ -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.
 
 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);
-    }
 }
index 176a0ca..46fae43 100644 (file)
@@ -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<GraphPropertyEnum, Object> hasProps = null;
+    @Test(expected = NullPointerException.class)
+    public void testGetVerticesToValidate() throws Exception {
+        ArtifactValidatorExecuter testSubject;
+        VertexTypeEnum type = null;
+        Map<GraphPropertyEnum, Object> 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<String, List<Component>> vertices = new HashMap<>();
-               LinkedList<Component> linkedList = new LinkedList<Component>();
-               linkedList.add(new Resource());
-               vertices.put("stam", linkedList);
-               boolean result;
+    @Test
+    public void testValidate() {
+        ArtifactValidatorExecuter testSubject;
+        Map<String, List<Component>> vertices = new HashMap<>();
+        LinkedList<Component> linkedList = new LinkedList<Component>();
+        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);
+    }
 }
index e84b89a..c9c90b2 100644 (file)
@@ -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);
+    }
 }
index 51f1cc6..1e24867 100644 (file)
@@ -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);
+    }
 }
index 16e3636..a1728d8 100644 (file)
@@ -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);
+    }
 }
index c8edb7d..783b888 100644 (file)
@@ -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);
+    }
 }
index 457c9b0..c9bc5de 100644 (file)
@@ -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<VfValidationTask> validationTasks = new ArrayList<>();
-               JanusGraphDao janusGraphDaoMock = mock(JanusGraphDao.class);
+    private VfValidatorExecuter createTestSubject() {
+        List<VfValidationTask> 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);
+    }
 }
index 1af4a13..99733a7 100644 (file)
@@ -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<String> 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<String> 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<String> 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());
index 0aab992..cf28d74 100644 (file)
@@ -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.
 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()));
+    }
 }
index 0dba956..5302f4f 100644 (file)
@@ -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()));
+    }
 }
index 33ebd09..9a9f20b 100644 (file)
@@ -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
         }
     }
 }
index 011039d..938b2c2 100644 (file)
@@ -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<String> getReportOutputFileAsList() {
-        return readFileAsList(ValidationConfigManager.getOutputFullFilePath());
+    public static List<String> getReportOutputFileAsList(String txtReportFilePath) {
+        return readFileAsList(txtReportFilePath);
     }
 
     public static List<String> 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<String> readFileAsList(String filePath) {
index 22aaf6e..6be7f47 100644 (file)
@@ -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<String> 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<String> 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<String> 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<String> 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<String> reportOutputFile = ReportManagerHelper.getReportOutputFileAsList(txtReportFilePath);
 
         // then
         assertNotNull(reportOutputFile);