Fix the sonar issue and clm issue 14/85414/2
authorliboNet <libo.zhu@intel.com>
Tue, 16 Apr 2019 21:25:58 +0000 (05:25 +0800)
committerliboNet <libo.zhu@intel.com>
Tue, 16 Apr 2019 22:02:40 +0000 (06:02 +0800)
. Fix the bugs by using try-with-resources method
. Add unit test for GsonUtil
. Fix the org.springframework : spring-web issue by removing
  the dependency in forwarding plugin

Change-Id: I01f6461ea2a0f0363247dd3571dd56dcf68a7f90
Issue-ID: MULTICLOUD-569
Signed-off-by: liboNet <libo.zhu@intel.com>
artifactbroker/model/src/test/java/org/onap/policy/distribution/model/TestGsonUtil.java [new file with mode: 0644]
artifactbroker/model/src/test/resource/modules.json [new file with mode: 0644]
artifactbroker/plugins/forwarding-plugins/pom.xml
artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpArtifactForwarder.java
artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java [deleted file]
artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java [deleted file]
artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java [deleted file]
artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java

diff --git a/artifactbroker/model/src/test/java/org/onap/policy/distribution/model/TestGsonUtil.java b/artifactbroker/model/src/test/java/org/onap/policy/distribution/model/TestGsonUtil.java
new file mode 100644 (file)
index 0000000..172a1ef
--- /dev/null
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2019 Intel. All rights reserved.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.distribution.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import com.openpojo.reflection.filters.FilterPackageInfo;
+import com.openpojo.validation.Validator;
+import com.openpojo.validation.ValidatorBuilder;
+import com.openpojo.validation.test.impl.GetterTester;
+import com.openpojo.validation.test.impl.SetterTester;
+
+import java.util.List;
+import java.util.Map;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+
+import org.junit.Test;
+
+/**
+ * Class to perform unit testing of all GsonUtil models.
+ *
+ * @author libo zhu (libo.zhu@intel.com)
+ */
+public class TestGsonUtil {
+
+    @Test
+    public void testGsonUtil() {
+        try {
+            // Read the parameters from JSON using Gson
+
+            String data = new String(Files.readAllBytes(Paths.get("src/test/resource/modules.json")));
+            List<VfModuleModel> vfModuleModels= GsonUtil.parseJsonArrayWithGson(data, VfModuleModel.class);
+            assertEquals(4, vfModuleModels.size());
+        } catch (final Exception e) {
+            fail("test should not thrown an exception here: " + e.getMessage());
+        }
+
+
+    }
+}
diff --git a/artifactbroker/model/src/test/resource/modules.json b/artifactbroker/model/src/test/resource/modules.json
new file mode 100644 (file)
index 0000000..e363c52
--- /dev/null
@@ -0,0 +1,95 @@
+[
+  {
+    "vfModuleModelName": "Vfwnextgen..base_template..module-0",
+    "vfModuleModelInvariantUUID": "e40629e7-4fab-4ca3-b3ad-570763a32893",
+    "vfModuleModelVersion": "1",
+    "vfModuleModelUUID": "bff998ed-8322-4050-b1c0-181078ecbcd8",
+    "vfModuleModelCustomizationUUID": "4e00870e-87e2-4968-85ab-22d9c181b770",
+    "isBase": true,
+    "artifacts": [
+      "4d4a37ef-6a1f-4cb2-b3c9-b380a5940431",
+      "0a38b7ef-93b9-4d48-856d-efb56d53aab8"
+    ],
+    "properties": {
+      "min_vf_module_instances": "1",
+      "vf_module_label": "base_template",
+      "max_vf_module_instances": "1",
+      "vfc_list": "",
+      "vf_module_description": "",
+      "vf_module_type": "Base",
+      "availability_zone_count": "",
+      "volume_group": "false",
+      "initial_count": "1"
+    }
+  },
+  {
+    "vfModuleModelName": "Vfwnextgen..vsn..module-1",
+    "vfModuleModelInvariantUUID": "608cf695-83d9-4777-8d34-d4d76a5b5c19",
+    "vfModuleModelVersion": "1",
+    "vfModuleModelUUID": "8a5b6f0a-535d-4d86-ba6e-facf56302a39",
+    "vfModuleModelCustomizationUUID": "77320fa7-afa0-4e9c-b998-5a182c05ce0a",
+    "isBase": false,
+    "artifacts": [
+      "db75d79d-5e33-4e28-9a53-8d2c5d9df350",
+      "dd537ba7-a63a-4dff-8448-53b6bd450685"
+    ],
+    "properties": {
+      "min_vf_module_instances": "0",
+      "vf_module_label": "vsn",
+      "max_vf_module_instances": "",
+      "vfc_list": "",
+      "vf_module_description": "",
+      "vf_module_type": "Expansion",
+      "availability_zone_count": "",
+      "volume_group": "false",
+      "initial_count": "0"
+    }
+  },
+  {
+    "vfModuleModelName": "Vfwnextgen..vpg..module-2",
+    "vfModuleModelInvariantUUID": "4dd970d9-fc1c-4d06-bc29-c5eebc28a58c",
+    "vfModuleModelVersion": "1",
+    "vfModuleModelUUID": "8184982c-9706-4a4c-9d56-3d125772d55a",
+    "vfModuleModelCustomizationUUID": "ed4f1e52-17ab-458e-8b05-9620f97f2465",
+    "isBase": false,
+    "artifacts": [
+      "b57ab00a-b4c8-4732-9cad-06b341fc12bb",
+      "9753e2bc-8b85-4793-9591-5c65e82df6a4"
+    ],
+    "properties": {
+      "min_vf_module_instances": "0",
+      "vf_module_label": "vpg",
+      "max_vf_module_instances": "",
+      "vfc_list": "",
+      "vf_module_description": "",
+      "vf_module_type": "Expansion",
+      "availability_zone_count": "",
+      "volume_group": "false",
+      "initial_count": "0"
+    }
+  },
+  {
+    "vfModuleModelName": "Vfwnextgen..vfw..module-3",
+    "vfModuleModelInvariantUUID": "1b998683-0854-4bd1-bfab-345cccf1fc16",
+    "vfModuleModelVersion": "1",
+    "vfModuleModelUUID": "3a4a9712-9fab-4c20-9b82-f4ebbbf4437c",
+    "vfModuleModelCustomizationUUID": "1d177995-1861-4036-993c-37642d768694",
+    "isBase": false,
+    "artifacts": [
+      "450a0635-73ce-4394-ad7d-a3ab354b044c",
+      "7d7a9ab4-ef1d-4d3f-baa4-e9c1361a23ef"
+    ],
+    "properties": {
+      "min_vf_module_instances": "0",
+      "vf_module_label": "vfw",
+      "max_vf_module_instances": "",
+      "vfc_list": "",
+      "vf_module_description": "",
+      "vf_module_type": "Expansion",
+      "availability_zone_count": "",
+      "volume_group": "false",
+      "initial_count": "0"
+    }
+  }
+]
+
index 9ceab89..8b4e8cb 100644 (file)
             <artifactId>multicloud-framework-artifactbroker-main</artifactId>
             <version>${project.version}</version>
         </dependency>
-       <dependency>
-            <groupId>org.onap.policy.engine</groupId>
-            <artifactId>PolicyEngineAPI</artifactId>
-            <version>${policy.engine.version}</version>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.eclipse.persistence</groupId>
-                    <artifactId>eclipselink</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
         <dependency>
             <groupId>org.mockito</groupId>
             <artifactId>mockito-all</artifactId>
index 3fe6dd8..4179fc7 100644 (file)
@@ -52,12 +52,10 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
 import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.distribution.forwarding.ArtifactForwarder;
-import org.onap.policy.distribution.forwarding.xacml.pdp.adapters.XacmlPdpOptimizationPolicyAdapter;
 import org.onap.policy.distribution.model.CloudArtifact;
 import org.onap.policy.distribution.model.PolicyInput;
 import org.onap.policy.distribution.model.VfModuleModel;
 import org.onap.sdc.api.notification.IArtifactInfo;
-import org.springframework.http.HttpStatus;
 
 
 /**
diff --git a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpPolicyAdapter.java
deleted file mode 100644 (file)
index c50eac1..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- * 
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.distribution.forwarding.xacml.pdp;
-
-import org.onap.policy.api.PolicyParameters;
-import org.onap.policy.api.PushPolicyParameters;
-import org.onap.policy.distribution.model.Policy;
-
-/**
- * Adapts {@link Policy} objects to objects compatible with the XACML PDP API.
- */
-public interface XacmlPdpPolicyAdapter<T extends Policy> {
-
-    /**
-     * Get the policy.
-     * 
-     * @return the policy
-     */
-    T getPolicy();
-
-    /**
-     * Get as a {@link PolicyParameters} object.
-     * 
-     * @returna {@link PolicyParameters} object
-     */
-    PolicyParameters getAsPolicyParameters();
-
-    /**
-     * Get as a {@link PushPolicyParameters} object.
-     * 
-     * @returna {@link PushPolicyParameters} object
-     */
-    PushPolicyParameters getAsPushPolicyParameters(final String pdpGroups);
-
-}
diff --git a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/AbstractXacmlPdpPolicyAdapter.java
deleted file mode 100644 (file)
index c136516..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- * 
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.distribution.forwarding.xacml.pdp.adapters;
-
-import org.onap.policy.api.PushPolicyParameters;
-import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyAdapter;
-import org.onap.policy.distribution.model.Policy;
-
-/**
- * Base class for {@link XacmlPdpPolicyAdapter} implementations.
- * 
- * @param <T> the type of policy the adapter handles
- */
-public abstract class AbstractXacmlPdpPolicyAdapter<T extends Policy> implements XacmlPdpPolicyAdapter<T> {
-
-    private T policy;
-
-    protected AbstractXacmlPdpPolicyAdapter(T policy) {
-        this.policy = policy;
-    }
-
-    @Override
-    public T getPolicy() {
-        return policy;
-    }
-
-    @Override
-    public PushPolicyParameters getAsPushPolicyParameters(String pdpGroups) {
-        PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
-        pushPolicyParameters.setPolicyName(policy.getPolicyName());
-        pushPolicyParameters.setPolicyType(policy.getPolicyType());
-        pushPolicyParameters.setPdpGroup(pdpGroups);
-        return pushPolicyParameters;
-    }
-
-}
diff --git a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/adapters/XacmlPdpOptimizationPolicyAdapter.java
deleted file mode 100644 (file)
index 1ec654f..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- *  Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * 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.
- * 
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.distribution.forwarding.xacml.pdp.adapters;
-
-import org.onap.policy.api.PolicyConfigType;
-import org.onap.policy.api.PolicyParameters;
-import org.onap.policy.distribution.model.OptimizationPolicy;
-
-/**
- * Adapts {@link OptimizationPolicy} objects to objects compatible with the XACML PDP API.
- */
-public class XacmlPdpOptimizationPolicyAdapter extends AbstractXacmlPdpPolicyAdapter<OptimizationPolicy> {
-
-    /**
-     * Create an instance to adapt the given {@link OptimizationPolicy}.
-     * 
-     * @param optimizationPolicy the {@link OptimizationPolicy} to be adapted
-     */
-    public XacmlPdpOptimizationPolicyAdapter(final OptimizationPolicy optimizationPolicy) {
-        super(optimizationPolicy);
-    }
-
-    @Override
-    public PolicyParameters getAsPolicyParameters() {
-        PolicyParameters policyParameters = new PolicyParameters();
-        policyParameters.setPolicyName(getPolicy().getPolicyName());
-        policyParameters.setPolicyDescription(getPolicy().getPolicyDescription());
-        policyParameters.setPolicyConfigType(PolicyConfigType.valueOf(getPolicy().getPolicyConfigType()));
-        policyParameters.setOnapName(getPolicy().getOnapName());
-        policyParameters.setRiskLevel(getPolicy().getRiskLevel());
-        policyParameters.setConfigBody(getPolicy().getConfigBody());
-        policyParameters.setRiskType(getPolicy().getRiskType());
-        return policyParameters;
-    }
-
-}
index 37fb314..8bf69da 100644 (file)
@@ -338,10 +338,8 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo
     private static void writeFileByFileWriter(String filePath, String content) throws IOException {
         File file = new File(filePath);
         synchronized (file) {
-            try {
-                FileWriter fw = new FileWriter(filePath);
+            try (FileWriter fw = new FileWriter(filePath)) {
                 fw.write(content);
-                fw.close();
             } catch (final IOException exp) {
                 LOGGER.error("Failed to write File by File Writer ", exp);
             }