diff options
3 files changed, 33 insertions, 27 deletions
diff --git a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpArtifactForwarder.java b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpArtifactForwarder.java index 906827c..3fe6dd8 100644 --- a/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpArtifactForwarder.java +++ b/artifactbroker/plugins/forwarding-plugins/src/main/java/org/onap/policy/distribution/forwarding/xacml/pdp/XacmlPdpArtifactForwarder.java @@ -42,10 +42,10 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.FileEntity; +import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; -import org.apache.http.entity.StringEntity; import org.apache.http.util.EntityUtils; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -53,8 +53,8 @@ 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.PolicyInput; 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; @@ -145,8 +145,8 @@ public class XacmlPdpArtifactForwarder implements ArtifactForwarder { boolean found = false; for (String artifact: artifacts) { - if ( artifactMap.get(artifact) != null && - artifactMap.get(artifact).getArtifactType().equals("CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT")) { + if ( artifactMap.get(artifact) != null + && artifactMap.get(artifact).getArtifactType().equals("CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT")) { cloudArtifact = artifactMap.get(artifact); cloudUuid = cloudArtifact.getArtifactUUID(); found = true; @@ -185,7 +185,7 @@ public class XacmlPdpArtifactForwarder implements ArtifactForwarder { System.out.println("result2") ; String result = EntityUtils.toString(closeableHttpResponse.getEntity()); System.out.println("result = {}" + result); - System.out.println("status = {}"+ closeableHttpResponse.getStatusLine().getStatusCode()); + System.out.println("status = {}" + closeableHttpResponse.getStatusLine().getStatusCode()); if ( closeableHttpResponse.getStatusLine().getStatusCode() != 200 ) { System.out.println("exception: ret= " + closeableHttpResponse.getStatusLine().getStatusCode()); } else { diff --git a/artifactbroker/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpArtifactForwarderTest.java b/artifactbroker/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpArtifactForwarderTest.java index ca2fd0d..bad34c5 100644 --- a/artifactbroker/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpArtifactForwarderTest.java +++ b/artifactbroker/plugins/forwarding-plugins/src/test/java/org/onap/policy/distribution/forwarding/xacml/pdp/engine/XacmlPdpArtifactForwarderTest.java @@ -20,6 +20,8 @@ package org.onap.policy.distribution.forwarding.xacml.pdp.engine; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; @@ -28,14 +30,11 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import java.io.IOException; import java.io.ByteArrayInputStream; +import java.io.IOException; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.lang.reflect.Type; @@ -49,18 +48,18 @@ import java.util.HashMap; import java.util.List; import javax.ws.rs.client.Entity; import javax.ws.rs.core.Response; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.BeforeClass; -import org.junit.Test; +import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.HttpVersion; -import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.message.BasicStatusLine; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.junit.BeforeClass; +import org.junit.Test; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; import org.onap.policy.common.parameters.ParameterGroup; @@ -68,9 +67,9 @@ import org.onap.policy.common.parameters.ParameterService; import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpArtifactForwarder; import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpArtifactForwarderParameterGroup.XacmlPdpArtifactForwarderParameterGroupBuilder; import org.onap.policy.distribution.main.PolicyDistributionException; +import org.onap.policy.distribution.model.CloudArtifact; import org.onap.policy.distribution.model.GsonUtil; import org.onap.policy.distribution.model.Policy; -import org.onap.policy.distribution.model.CloudArtifact; import org.onap.policy.distribution.model.VfModuleModel; import org.onap.sdc.api.notification.IArtifactInfo; @@ -129,7 +128,7 @@ public class XacmlPdpArtifactForwarderTest { String data = new String(Files.readAllBytes(Paths.get("src/test/resource/modules.json"))); Type type = new TypeToken<ArrayList<VfModuleModel>>() {}.getType(); Gson gson = new Gson(); - vfModuleModels= gson.fromJson(data, type); + vfModuleModels = gson.fromJson(data, type); //vfModuleModels= GsonUtil.parseJsonArrayWithGson(data, VfModuleModel.class); assertEquals(4, vfModuleModels.size()); @@ -187,6 +186,7 @@ public class XacmlPdpArtifactForwarderTest { private IArtifactInfo generatedArtifact; private List<String> relatedArtifacts; private List<IArtifactInfo> relatedArtifactsInfo; + ArtifactInfoImpl(){} private ArtifactInfoImpl(IArtifactInfo iArtifactInfo){ @@ -207,9 +207,9 @@ public class XacmlPdpArtifactForwarderTest { private List<String> fillRelatedArtifactsUUID(List<IArtifactInfo> relatedArtifactsInfo) { List<String> relatedArtifactsUUID = null; - if( relatedArtifactsInfo != null && !relatedArtifactsInfo.isEmpty()){ + if ( relatedArtifactsInfo != null && !relatedArtifactsInfo.isEmpty()) { relatedArtifactsUUID = new ArrayList<>(); - for(IArtifactInfo curr: relatedArtifactsInfo){ + for (IArtifactInfo curr: relatedArtifactsInfo) { relatedArtifactsUUID.add(curr.getArtifactUUID()); } } diff --git a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java index 6b8f3b6..37fb314 100644 --- a/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java +++ b/artifactbroker/plugins/reception-plugins/src/main/java/org/onap/policy/distribution/reception/handling/sdc/SdcReceptionHandler.java @@ -28,8 +28,8 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; -import java.util.List; import java.util.HashMap; +import java.util.List; import org.onap.policy.common.logging.flexlogger.FlexLogger; import org.onap.policy.common.logging.flexlogger.Logger; @@ -228,13 +228,13 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo for (final IArtifactInfo artifact : resource.getArtifacts()) { artifactMap.put(artifact.getArtifactUUID(),artifact); - //extract the artifactlist and write them into MongoDB + //extract the artifactlist and write them into MongoDB if (artifact.getArtifactType().equals("VF_MODULES_METADATA")) { try { final IDistributionClientDownloadResult resultArtifact = downloadTheArtifact(artifact,notificationData); vfArtifactData = new String(resultArtifact.getArtifactPayload()); - vfModuleModels= GsonUtil.parseJsonArrayWithGson(vfArtifactData,VfModuleModel.class); + vfModuleModels = GsonUtil.parseJsonArrayWithGson(vfArtifactData,VfModuleModel.class); } catch (final ArtifactDownloadException exp) { LOGGER.error("Failed to process csar service artifacts ", exp); artifactsProcessedSuccessfully = false; @@ -256,10 +256,12 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo Path temp = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID()); path = Files.createDirectory(temp);//create UUID path //store the value to vfmodule-meta.json - String filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),"vfmodule-meta.json").toString(); + String filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(), + "vfmodule-meta.json").toString(); writeFileByFileWriter(filePath, vfArtifactData); //store the service level info to serivce-meta.json - filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(),"service-meta.json").toString(); + filePath = Paths.get("/data",vfModule.getVfModuleModelCustomizationUUID(), + "service-meta.json").toString(); writeFileByFileWriter(filePath, notificationData.toString()); } catch (final IOException exp) { LOGGER.error("Failed to create directory artifact file", exp); @@ -336,9 +338,13 @@ public class SdcReceptionHandler extends AbstractReceptionHandler implements INo private static void writeFileByFileWriter(String filePath, String content) throws IOException { File file = new File(filePath); synchronized (file) { - FileWriter fw = new FileWriter(filePath); - fw.write(content); - fw.close(); + 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); + } } } /** |