Moved validation test util class to test jar

Change-Id: I113012ee0fbaeaaa1f4cecf69de442fdd66c89bf
Issue-ID: SDC-1243
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml
index 0b2cb5f..2eb7df7 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/pom.xml
@@ -86,6 +86,13 @@
             <artifactId>openecomp-sdc-validation-core</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.openecomp.sdc</groupId>
+            <artifactId>openecomp-sdc-validation-sdk</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/pom.xml b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/pom.xml
index ad49dac..180e318 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/pom.xml
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/pom.xml
@@ -42,5 +42,22 @@
         </dependency>
     </dependencies>
 
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <version>${mvn.jar.version}</version>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>test-jar</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
 
 </project>
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/test/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java
similarity index 63%
rename from openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java
rename to openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/test/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java
index 13f2d63..41fbf45 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/test/java/org/openecomp/sdc/validation/util/ValidationTestUtil.java
@@ -1,28 +1,21 @@
+/*
+ * Copyright © 2016-2018 European Support Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 package org.openecomp.sdc.validation.util;
 
-import org.apache.commons.collections4.MapUtils;
-import org.apache.commons.io.IOUtils;
-import org.openecomp.core.utilities.CommonMethods;
-import org.openecomp.core.utilities.file.FileUtils;
-import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
-import org.openecomp.core.validation.types.GlobalValidationContext;
-import org.openecomp.core.validation.types.MessageContainer;
-import org.openecomp.sdc.datatypes.configuration.ImplementationConfiguration;
-import org.openecomp.sdc.heat.datatypes.manifest.FileData;
-import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
-import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
-import org.openecomp.sdc.heat.datatypes.model.Resource;
-import org.openecomp.sdc.heat.services.HeatStructureUtil;
-import org.openecomp.sdc.heat.services.manifest.ManifestUtil;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.sdc.validation.ResourceValidator;
-import org.openecomp.sdc.validation.ValidationContext;
-import org.openecomp.sdc.validation.Validator;
-import org.openecomp.sdc.validation.base.ResourceBaseValidator;
-
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -31,15 +24,31 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.io.IOUtils;
+import org.openecomp.core.utilities.file.FileUtils;
+import org.openecomp.core.utilities.json.JsonUtil;
+import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
+import org.openecomp.core.validation.types.GlobalValidationContext;
+import org.openecomp.core.validation.types.MessageContainer;
+import org.openecomp.sdc.heat.datatypes.manifest.FileData;
+import org.openecomp.sdc.heat.datatypes.manifest.ManifestContent;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+import org.openecomp.sdc.heat.services.HeatStructureUtil;
+import org.openecomp.sdc.heat.services.manifest.ManifestUtil;
+import org.openecomp.sdc.validation.ResourceValidator;
+import org.openecomp.sdc.validation.ValidationContext;
+import org.openecomp.sdc.validation.Validator;
+import org.openecomp.sdc.validation.base.ResourceBaseValidator;
+import org.testng.Assert;
 
 /**
- * Created by TALIO on 2/26/2017.
+ * @author TALIO
+ * @since 26 Feb 2017
  */
 public class ValidationTestUtil {
 
-  private static final Logger LOG = LoggerFactory.getLogger(ValidationTestUtil.class
-      .getName());
-
   private ValidationTestUtil(){}
 
   public static GlobalValidationContext createGlobalContextFromPath(String path) {
@@ -48,8 +57,7 @@
     if (contentMap == null) {
       return null;
     }
-    contentMap.entrySet()
-        .forEach(entry -> globalValidationContext.addFileContext(entry.getKey(), entry.getValue()));
+    contentMap.forEach(globalValidationContext::addFileContext);
 
     return globalValidationContext;
   }
@@ -93,71 +101,69 @@
   }
 
   public static Map<String, MessageContainer> testValidator(ResourceBaseValidator baseValidator,
-                                                            ResourceValidator resourceValidator,
-                                                            String resourceTypeToValidate, String path) {
+          ResourceValidator resourceValidator,
+          String resourceTypeToValidate, String path) {
 
-    GlobalValidationContext globalContext = createGlobalContextFromPath(path);
+    GlobalValidationContext globalContext = Objects.requireNonNull(
+            createGlobalContextFromPath(path), "Global validation context cannot be null");
+
     ManifestContent manifestContent = ValidationUtil.validateManifest(globalContext);
     Map<String, FileData.Type> fileTypeMap = ManifestUtil.getFileTypeMap(manifestContent);
     Map<String, FileData> fileEnvMap = ManifestUtil.getFileAndItsEnv(manifestContent);
 
     validateFiles(baseValidator, resourceValidator, globalContext, fileEnvMap, fileTypeMap,
-        resourceTypeToValidate);
+            resourceTypeToValidate);
 
-    assert globalContext != null;
     return globalContext.getContextMessageContainers();
-
-
   }
 
   private static void validateFiles(ResourceBaseValidator baseValidator,
-                                    ResourceValidator resourceValidator,
-                                    GlobalValidationContext globalContext,
-                                    Map<String, FileData> fileEnvMap,
-                                    Map<String, FileData.Type> fileTypeMap,
-                                    String resourceTypeToValidate) {
+          ResourceValidator resourceValidator,
+          GlobalValidationContext globalContext,
+          Map<String, FileData> fileEnvMap,
+          Map<String, FileData.Type> fileTypeMap,
+          String resourceTypeToValidate) {
 
     Collection<String> files = globalContext.getFiles();
     for(String fileName : files){
       if(FileData.isHeatFile(fileTypeMap.get(fileName))) {
         HeatOrchestrationTemplate heatOrchestrationTemplate =
-            ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
+                ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalContext);
 
         if (Objects.isNull(heatOrchestrationTemplate)) {
           continue;
         }
 
-        ValidationContext validationContext = baseValidator.createValidationContext
-            (fileName,
+        ValidationContext validationContext = baseValidator.createValidationContext(fileName,
                 fileEnvMap.get(fileName) == null ? null : fileEnvMap.get(fileName).getFile(),
                 heatOrchestrationTemplate, globalContext);
 
         validateResources(fileName, resourceValidator, resourceTypeToValidate, validationContext,
-            globalContext);
+                globalContext);
       }
     }
   }
 
-  public static void validateResources(String fileName,
-                                       ResourceValidator resourceValidator,
-                                       String resourceTypeToValidate,
-                                       ValidationContext validationContext,
-                                       GlobalValidationContext globalValidationContext){
+  private static void validateResources(String fileName, ResourceValidator resourceValidator,
+          String resourceTypeToValidate, ValidationContext validationContext,
+          GlobalValidationContext globalValidationContext){
 
     HeatOrchestrationTemplate heatOrchestrationTemplate =
-        ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalValidationContext);
-    Map<String, Resource> resourcesMap = heatOrchestrationTemplate.getResources();
+            ValidationUtil.checkHeatOrchestrationPreCondition(fileName, globalValidationContext);
+
+    Map<String, Resource> resourcesMap =
+            Objects.requireNonNull(heatOrchestrationTemplate, "Orchestration template cannot be null").getResources();
 
     if(MapUtils.isEmpty(resourcesMap)){
       return;
     }
 
     resourcesMap.entrySet()
-        .stream()
-        .filter(resourceEntry -> isResourceNeedToBeTested(resourceEntry.getValue().getType(), resourceTypeToValidate))
-        .forEach(resourceEntry ->
-            resourceValidator.validate
-                (fileName, resourceEntry, globalValidationContext, validationContext));
+                .stream()
+                .filter(resourceEntry -> isResourceNeedToBeTested(resourceEntry.getValue().getType(), resourceTypeToValidate))
+                .forEach(resourceEntry ->
+                                 resourceValidator.validate
+                                                           (fileName, resourceEntry, globalValidationContext, validationContext));
   }
 
   private static boolean isResourceNeedToBeTested(String currResource, String resourceToTest){
@@ -169,25 +175,10 @@
   }
 
   public static void validateErrorMessage(String actualMessage, String expected, String... params) {
-    if (!Objects.equals(actualMessage.replace("\n", "").replace("\r", ""),
-        ErrorMessagesFormatBuilder.getErrorWithParameters(expected, params).replace("\n", "")
-            .replace("\r", ""))){
-      throw new RuntimeException("validation failed");
-    }
 
-  }
-
-  public static Validator cerateValidatorImpl(ImplementationConfiguration validatorConf) {
-    Validator validator = null;
-    try {
-      validator =
-          CommonMethods.newInstance(validatorConf.getImplementationClass(), Validator.class);
-      validator.init(validatorConf.getProperties());
-    } catch (IllegalArgumentException iae) {
-      LOG.debug("",iae);
-      return null;
-    }
-    return validator;
+    Assert.assertEquals(actualMessage.replace("\n", "").replace("\r", ""),
+            ErrorMessagesFormatBuilder.getErrorWithParameters(expected, params).replace("\n", "")
+                                      .replace("\r", ""));
   }
 
   public static Map<String, Object> getResourceMap(String configFileName) throws IOException {