Merge "Configuration object status to Inventoried" into dublin
authorSteve Smokowski <ss835w@att.com>
Thu, 25 Apr 2019 12:04:10 +0000 (12:04 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 25 Apr 2019 12:04:10 +0000 (12:04 +0000)
14 files changed:
adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/adapters/vnfrest/VfResponseCommon.java
adapters/mso-adapters-rest-interface/src/main/java/org/onap/so/openstack/mappers/MapElements.java
adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/JAXBMarshallingTest.java
adapters/mso-adapters-rest-interface/src/test/resources/VfRequest-marshalled-with-complex-object.xml [new file with mode: 0644]
adapters/mso-adapters-rest-interface/src/test/resources/createVfModuleRequest-with-params.xml
adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java [new file with mode: 0644]
bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/baseclient/BaseClientTest.java
bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFStartActivityTest.java
bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFUnlockActivityTest.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/oof/OofClient.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/SDNCClient.java
bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sniro/SniroClient.java
common/src/main/java/org/onap/so/client/BaseClient.java [moved from bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java with 97% similarity]

index 23bbbb3..7a2d4ec 100644 (file)
@@ -24,6 +24,8 @@ package org.onap.so.adapters.vnfrest;
 
 
 import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.Marshaller;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -71,7 +73,7 @@ public abstract class VfResponseCommon {
     public String toXmlString() {
         try {
             ByteArrayOutputStream bs = new ByteArrayOutputStream();
-            JAXBContext context = JAXBContext.newInstance(this.getClass());
+            JAXBContext context = JAXBContext.newInstance(this.getClass(), ArrayList.class, HashMap.class);
             Marshaller marshaller = context.createMarshaller();
             marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // pretty print XML
             marshaller.marshal(this, bs);
index d20d2b7..0327fd6 100644 (file)
 
 package org.onap.so.openstack.mappers;
 
+import java.util.List;
+import java.util.Map;
 import javax.xml.bind.annotation.XmlElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 public class MapElements {
+    private static final Logger logger = LoggerFactory.getLogger(MapElements.class);
     @XmlElement
     public String key;
     @XmlElement
@@ -32,6 +39,21 @@ public class MapElements {
 
     public MapElements(String key, Object value) {
         this.key = key;
-        this.value = value;
+        // this is required to handle marshalling raw json
+        // always write values as strings for XML
+        if (value != null) {
+            if (value instanceof List || value instanceof Map) {
+                try {
+                    this.value = new ObjectMapper().writeValueAsString(value);
+                } catch (JsonProcessingException e) {
+                    logger.warn("could not marshal value to json, calling toString");
+                    this.value = value.toString();
+                }
+            } else {
+                this.value = value;
+            }
+        } else {
+            this.value = value;
+        }
     }
 }
index 8d27e54..189d4cc 100644 (file)
@@ -24,17 +24,19 @@ import static org.junit.Assert.assertEquals;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.util.Arrays;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import org.junit.Test;
 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
+import com.fasterxml.jackson.databind.ObjectMapper;
 
 
 public class JAXBMarshallingTest {
 
 
     @Test
-    public void xmlMarshalTest() throws IOException, JAXBException {
+    public void xmlUnMarshalTest() throws IOException, JAXBException {
         JAXBContext context = JAXBContext.newInstance(CreateVfModuleRequest.class);
 
         CreateVfModuleRequest request = (CreateVfModuleRequest) context.createUnmarshaller().unmarshal(
@@ -43,6 +45,20 @@ public class JAXBMarshallingTest {
         assertEquals("ubuntu-16-04-cloud-amd64", request.getVfModuleParams().get("vcpe_image_name"));
         assertEquals("10.2.0.0/24", request.getVfModuleParams().get("cpe_public_net_cidr"));
         assertEquals("", request.getVfModuleParams().get("workload_context"));
+        assertEquals("[\"a\",\"b\",\"c\"]", request.getVfModuleParams().get("raw-json-param"));
+    }
+
+    @Test
+    public void xmlMarshalTest() throws IOException, JAXBException {
+
+        CreateVfModuleRequest request = new CreateVfModuleRequest();
+        request.getVfModuleParams().put("test-null", null);
+        request.getVfModuleParams().put("test array", Arrays.asList("a", "b", "c"));
+
+        assertEquals("documents are equal",
+                new String(Files
+                        .readAllBytes(Paths.get("src/test/resources/VfRequest-marshalled-with-complex-object.xml"))),
+                request.toXmlString());
 
     }
 
diff --git a/adapters/mso-adapters-rest-interface/src/test/resources/VfRequest-marshalled-with-complex-object.xml b/adapters/mso-adapters-rest-interface/src/test/resources/VfRequest-marshalled-with-complex-object.xml
new file mode 100644 (file)
index 0000000..ce17512
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<createVfModuleRequest>
+    <failIfExists>false</failIfExists>
+    <backout>true</backout>
+    <vfModuleParams>
+        <entry>
+            <key>test array</key>
+            <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">["a","b","c"]</value>
+        </entry>
+        <entry>
+            <key>test-null</key>
+        </entry>
+    </vfModuleParams>
+    <msoRequest/>
+</createVfModuleRequest>
index 1ff24a5..2718f1d 100644 (file)
@@ -1,4 +1,4 @@
-<createVfModuleRequest>
+  <createVfModuleRequest>
        <cloudSiteId>RegionOne</cloudSiteId>
        <cloudOwner>CloudOwner</cloudOwner>
        <tenantId>09d8566ea45e43aa974cf447ed591d77</tenantId>
                        <key>vf_module_index</key>
                        <value>0</value>
                </entry>
-
+        <entry>
+            <key>raw-json-param</key>
+            <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">["a","b","c"]</value>
+        </entry>
        </vfModuleParams>
        <msoRequest>
                <requestId>11c8ec20-a1f8-4aa2-926f-e55d67a30f8b</requestId>
index add3aac..2bddd43 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.onap.so.adapters.inventory.create;
 
-import java.io.IOException;
 import org.camunda.bpm.client.task.ExternalTask;
 import org.camunda.bpm.client.task.ExternalTaskService;
 import org.onap.logging.ref.slf4j.ONAPLogConstants;
@@ -30,7 +29,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.env.Environment;
 import org.springframework.stereotype.Component;
 
@@ -48,17 +46,16 @@ public class CreateInventoryTask {
     public Environment env;
 
     protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
+        setupMDC(externalTask);
         boolean success = true;
         String auditInventoryString = externalTask.getVariable("auditInventoryResult");
-        GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
         AAIObjectAuditList auditInventory = null;
         try {
+            GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
             auditInventory = objectMapper.getMapper().readValue(auditInventoryString, AAIObjectAuditList.class);
-        } catch (IOException e1) {
-            success = false;
+        } catch (Exception e) {
+            logger.error("Error Parsing Audit Results", e);
         }
-        setupMDC(externalTask);
-
         if (auditInventory != null) {
             try {
                 logger.info("Executing External Task Create Inventory, Retry Number: {} \n {}", auditInventory,
@@ -97,9 +94,13 @@ public class CreateInventoryTask {
     }
 
     private void setupMDC(ExternalTask externalTask) {
-        String msoRequestId = (String) externalTask.getVariable("mso-request-id");
-        if (msoRequestId != null && !msoRequestId.isEmpty())
-            MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
+        try {
+            String msoRequestId = (String) externalTask.getVariable("mso-request-id");
+            if (msoRequestId != null && !msoRequestId.isEmpty())
+                MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
+        } catch (Exception e) {
+            logger.error("Error in setting up MDC", e);
+        }
     }
 
     protected long calculateRetryDelay(int currentRetries) {
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/inventory/create/CreateInventoryTaskTest.java
new file mode 100644 (file)
index 0000000..03622db
--- /dev/null
@@ -0,0 +1,36 @@
+package org.onap.so.adapters.inventory.create;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.times;
+import org.camunda.bpm.client.task.ExternalTask;
+import org.camunda.bpm.client.task.ExternalTaskService;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+public class CreateInventoryTaskTest {
+
+    @Mock
+    ExternalTask externalTask;
+
+    @Mock
+    ExternalTaskService externalTaskService;
+
+    @InjectMocks
+    CreateInventoryTask inventoryTask;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void test_Runtime_Parse_Exception() {
+        doReturn(null).when(externalTask).getVariable("auditInventoryResult");
+        inventoryTask.executeExternalTask(externalTask, externalTaskService);
+        Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
+    }
+}
index ee2c10c..05af5f7 100644 (file)
@@ -29,6 +29,7 @@ import java.util.Map;
 import javax.ws.rs.core.UriBuilder;
 import org.junit.Test;
 import org.onap.so.BaseTest;
+import org.onap.so.client.BaseClient;
 import org.springframework.core.ParameterizedTypeReference;
 import wiremock.org.apache.http.entity.ContentType;
 
index a8e974d..2163e0b 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.
index b6faf1b..c5ddd56 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.
index e31285f..e8a7fef 100644 (file)
@@ -22,8 +22,8 @@ package org.onap.so.client.oof;
 
 
 import org.camunda.bpm.engine.delegate.BpmnError;
-import org.onap.so.bpmn.common.baseclient.BaseClient;
 import org.onap.so.bpmn.core.UrnPropertiesReader;
+import org.onap.so.client.BaseClient;
 import org.onap.so.client.exception.BadResponseException;
 import org.onap.so.client.oof.beans.OofProperties;
 import org.onap.so.client.oof.beans.OofRequest;
index 732bba8..f02d5e4 100644 (file)
@@ -24,7 +24,7 @@ package org.onap.so.client.sdnc;
 
 import java.util.LinkedHashMap;
 import javax.ws.rs.core.UriBuilder;
-import org.onap.so.bpmn.common.baseclient.BaseClient;
+import org.onap.so.client.BaseClient;
 import org.onap.so.client.exception.BadResponseException;
 import org.onap.so.client.exception.MapperException;
 import org.onap.so.client.sdnc.beans.SDNCProperties;
index f7aad55..21c0b97 100644 (file)
@@ -24,8 +24,8 @@ package org.onap.so.client.sniro;
 
 import java.util.LinkedHashMap;
 import org.camunda.bpm.engine.delegate.BpmnError;
-import org.onap.so.bpmn.common.baseclient.BaseClient;
 import org.onap.so.bpmn.core.UrnPropertiesReader;
+import org.onap.so.client.BaseClient;
 import org.onap.so.client.exception.BadResponseException;
 import org.onap.so.client.sniro.beans.ManagerProperties;
 import org.onap.so.client.sniro.beans.SniroConductorRequest;
@@ -18,7 +18,7 @@
  * ============LICENSE_END=========================================================
  */
 
-package org.onap.so.bpmn.common.baseclient;
+package org.onap.so.client;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -34,7 +34,6 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
 import org.springframework.web.client.RestClientException;
 import org.springframework.web.client.RestTemplate;
 
-// TODO move to common location
 public class BaseClient<I, O> {
 
     private HttpHeaders httpHeader;