Changes for Checkstyle 8.32
[policy/models.git] / models-provider / src / test / java / org / onap / policy / models / provider / impl / PolicyLegacyOperationalPersistenceTest.java
index e6ecf5a..e0250dc 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2020 AT&T.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,12 +23,11 @@ package org.onap.policy.models.provider.impl;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
 
+import java.net.URISyntaxException;
 import java.util.Base64;
-
+import java.util.Set;
 import lombok.NonNull;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -40,8 +40,6 @@ import org.onap.policy.models.provider.PolicyModelsProviderFactory;
 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.yaml.snakeyaml.Yaml;
 
 /**
@@ -50,24 +48,21 @@ import org.yaml.snakeyaml.Yaml;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class PolicyLegacyOperationalPersistenceTest {
-    // Logger for this class
-    private static final Logger LOGGER = LoggerFactory.getLogger(PolicyLegacyOperationalPersistenceTest.class);
-
     private StandardCoder standardCoder;
 
     private PolicyModelsProvider databaseProvider;
 
     // @formatter:off
     private String[] policyInputResourceNames = {
-        "policies/vCPE.policy.operational.input.json",
-        "policies/vDNS.policy.operational.input.json",
-        "policies/vFirewall.policy.operational.input.json"
+        "policies/vCPE.policy.operational.legacy.input.json",
+        "policies/vDNS.policy.operational.legacy.input.json",
+        "policies/vFirewall.policy.operational.legacy.input.json"
     };
 
     private String[] policyOutputResourceNames = {
-        "policies/vCPE.policy.operational.output.json",
-        "policies/vDNS.policy.operational.output.json",
-        "policies/vFirewall.policy.operational.output.json"
+        "policies/vCPE.policy.operational.legacy.output.json",
+        "policies/vDNS.policy.operational.legacy.output.json",
+        "policies/vFirewall.policy.operational.legacy.output.json"
     };
     // @formatter:on
 
@@ -107,16 +102,11 @@ public class PolicyLegacyOperationalPersistenceTest {
     }
 
     @Test
-    public void testPolicyPersistence() {
-        try {
-            for (int i = 0; i < policyInputResourceNames.length; i++) {
-                String policyInputString = ResourceUtils.getResourceAsString(policyInputResourceNames[i]);
-                String policyOutputString = ResourceUtils.getResourceAsString(policyOutputResourceNames[i]);
-                testJsonStringPolicyPersistence(policyInputString, policyOutputString);
-            }
-        } catch (Exception exc) {
-            LOGGER.warn("error processing policies", exc);
-            fail("test should not throw an exception");
+    public void testLegacyOperationalPolicyPersistence() throws Exception {
+        for (int i = 0; i < policyInputResourceNames.length; i++) {
+            String policyInputString = ResourceUtils.getResourceAsString(policyInputResourceNames[i]);
+            String policyOutputString = ResourceUtils.getResourceAsString(policyOutputResourceNames[i]);
+            testJsonStringPolicyPersistence(policyInputString, policyOutputString);
         }
     }
 
@@ -154,16 +144,18 @@ public class PolicyLegacyOperationalPersistenceTest {
                         "'"));
     }
 
-    private void createPolicyTypes() throws CoderException, PfModelException {
+    private void createPolicyTypes() throws CoderException, PfModelException, URISyntaxException {
+        Set<String> policyTypeResources = ResourceUtils.getDirectoryContents("policytypes");
 
-        Object yamlObject = new Yaml().load(
-                ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
-        String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+        for (String policyTypeResource : policyTypeResources) {
+            Object yamlObject = new Yaml().load(ResourceUtils.getResourceAsString(policyTypeResource));
+            String yamlAsJsonString = new StandardCoder().encode(yamlObject);
 
-        ToscaServiceTemplate toscaServiceTemplatePolicyType =
-                standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+            ToscaServiceTemplate toscaServiceTemplatePolicyType =
+                    standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
 
-        assertNotNull(toscaServiceTemplatePolicyType);
-        databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+            assertNotNull(toscaServiceTemplatePolicyType);
+            databaseProvider.createPolicyTypes(toscaServiceTemplatePolicyType);
+        }
     }
 }