Test Replace Jackson with GSON 49/31249/4
authorYiLi <li.yi101@zte.com.cn>
Sun, 11 Feb 2018 09:39:05 +0000 (17:39 +0800)
committerYiLi <li.yi101@zte.com.cn>
Mon, 12 Feb 2018 03:56:57 +0000 (11:56 +0800)
Change-Id: I7ac92dd83a4bf7dcfb70199f1d0f61e600db8904
Issue-ID: HOLMES-115
Signed-off-by: YiLi <li.yi101@zte.com.cn>
holmes-actions/pom.xml
holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java

index 850a03a..57f2eaa 100644 (file)
         <dependency>\r
             <groupId>org.onap.msb.java-sdk</groupId>\r
             <artifactId>msb-java-sdk</artifactId>\r
-            <!--<exclusions>-->\r
-                <!--<exclusion>-->\r
-                    <!--<groupId>com.eclipsesource.jaxrs</groupId>-->\r
-                    <!--<artifactId>jersey-all</artifactId>-->\r
-                <!--</exclusion>-->\r
-            <!--</exclusions>-->\r
         </dependency>\r
         <dependency>\r
             <groupId>org.apache.geronimo.specs</groupId>\r
                     <groupId>com.fasterxml.jackson.dataformat</groupId>\r
                     <artifactId>jackson-dataformat-yaml</artifactId>\r
                 </exclusion>\r
+                <exclusion>\r
+                    <groupId>com.fasterxml.jackson.core</groupId>\r
+                    <artifactId>jackson-databind</artifactId>\r
+                </exclusion>\r
             </exclusions>\r
         </dependency>\r
         <dependency>\r
             <groupId>io.swagger</groupId>\r
             <artifactId>swagger-jersey2-jaxrs</artifactId>\r
+            <exclusions>\r
+                <exclusion>\r
+                    <groupId>com.fasterxml.jackson.dataformat</groupId>\r
+                    <artifactId>jackson-dataformat-xml</artifactId>\r
+                </exclusion>\r
+            </exclusions>\r
         </dependency>\r
         <dependency>\r
             <groupId>org.projectlombok</groupId>\r
             <artifactId>gson</artifactId>\r
             <version>2.8.2</version>\r
         </dependency>\r
+        <dependency>\r
+            <groupId>com.alibaba</groupId>\r
+            <artifactId>fastjson</artifactId>\r
+            <version>1.1.23</version>\r
+        </dependency>\r
 \r
     </dependencies>\r
     <build>\r
index b80c40e..48e6ec0 100644 (file)
@@ -65,11 +65,7 @@ public class AaiQuery {
 
     private String getVmResourceLinks(String vserverId, String vserverName) throws CorrelationException {
         String response = getResourceLinksResponse(vserverId, vserverName);
-        try {
-            return aaiResponseUtil.convertJsonToVmResourceLink(response).get(0).getResourceLink();
-        } catch (Exception e) {
-            throw new CorrelationException("Failed to get aai resource link", e);
-        }
+        return aaiResponseUtil.convertJsonToVmResourceLink(response).get(0).getResourceLink();
     }
 
     private String getResourceLinksResponse(String vserverId, String vserverName) throws CorrelationException {
index 37bfc1d..a8d3c0d 100644 (file)
@@ -5,7 +5,7 @@
  * 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
+ * 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,
  */
 package org.onap.holmes.common.aai;
 
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import org.jvnet.hk2.annotations.Service;
+import org.onap.holmes.common.aai.entity.RelationshipList;
 import org.onap.holmes.common.aai.entity.RelationshipList.RelatedToProperty;
 import org.onap.holmes.common.aai.entity.RelationshipList.Relationship;
 import org.onap.holmes.common.aai.entity.RelationshipList.RelationshipData;
@@ -33,41 +35,36 @@ import org.onap.holmes.common.aai.entity.VnfEntity;
 public class AaiResponseUtil {
 
     public static final String RELATIONSHIP_LIST = "relationship-list";
-    public List<VmResourceLink> convertJsonToVmResourceLink(String responseJson) throws IOException {
-        ObjectMapper mapper = new ObjectMapper();
-        JsonNode jsonNode = mapper.readTree(responseJson);
 
+    public List<VmResourceLink> convertJsonToVmResourceLink(String responseJson)
+            {
         List<VmResourceLink> vmResourceLinkList = new ArrayList<>();
-        if (jsonNode.has("result-data")) {
-            JsonNode resultData = jsonNode.get("result-data");
+        String resultDataKey = "result-data";
+        JSONObject jsonNode = JSON.parseObject(responseJson);
+        if (jsonNode.get(resultDataKey) != null) {
+            JSONArray resultData = jsonNode.getJSONArray(resultDataKey);
             vmResourceLinkList = convertResultDataList(resultData);
         }
         return vmResourceLinkList;
     }
 
-    public VmEntity convertJsonToVmEntity(String responseJson) throws IOException {
-        ObjectMapper mapper = new ObjectMapper();
-        JsonNode jsonNode = mapper.readTree(responseJson);
-        if (!jsonNode.iterator().hasNext()) {
+    public VmEntity convertJsonToVmEntity(String responseJson) {
+        JSONObject jsonObject = JSON.parseObject(responseJson);
+        if (jsonObject == null ||jsonObject.isEmpty()) {
             return null;
         }
         VmEntity vmEntity = new VmEntity();
-        vmEntity.setInMaint(getBooleanElementByNode(jsonNode, "in-maint"));
-        vmEntity.setClosedLoopDisable(getBooleanElementByNode(jsonNode,"is-closed-loop-disabled"));
-        vmEntity.setProvStatus(getTextElementByNode(jsonNode, "prov-status"));
-        vmEntity.setResourceVersion(getTextElementByNode(jsonNode,"resource-version"));
-        vmEntity.setVserverId(getTextElementByNode(jsonNode,"vserver-id"));
-        vmEntity.setVserverName(getTextElementByNode(jsonNode,"vserver-name"));
-        vmEntity.setVserverName2(getTextElementByNode(jsonNode,"vserver-name2"));
-        vmEntity.setVserverSelflink(getTextElementByNode(jsonNode,"vserver-selflink"));
-
-        if (jsonNode.has(RELATIONSHIP_LIST)) {
-            JsonNode relationshipListNode = jsonNode.get(RELATIONSHIP_LIST);
-            if (relationshipListNode.has("relationship")) {
-                JsonNode relationshipNode = relationshipListNode.get("relationship");
-                vmEntity.getRelationshipList().setRelationships(convertRelationships(relationshipNode));
-            }
-        }
+        vmEntity.setInMaint(getBooleanElementByNode(jsonObject, "in-maint"));
+        vmEntity.setClosedLoopDisable(
+                getBooleanElementByNode(jsonObject, "is-closed-loop-disabled"));
+        vmEntity.setProvStatus(getTextElementByNode(jsonObject, "prov-status"));
+        vmEntity.setResourceVersion(getTextElementByNode(jsonObject, "resource-version"));
+        vmEntity.setVserverId(getTextElementByNode(jsonObject, "vserver-id"));
+        vmEntity.setVserverName(getTextElementByNode(jsonObject, "vserver-name"));
+        vmEntity.setVserverName2(getTextElementByNode(jsonObject, "vserver-name2"));
+        vmEntity.setVserverSelflink(getTextElementByNode(jsonObject, "vserver-selflink"));
+
+        setRelationShips(jsonObject, vmEntity.getRelationshipList());
         if (vmEntity.getRelationshipList().getRelationships() == null) {
             vmEntity.getRelationshipList().setRelationships(Collections.emptyList());
         }
@@ -75,110 +72,128 @@ public class AaiResponseUtil {
     }
 
     public VnfEntity convertJsonToVnfEntity(String responseJson) throws IOException {
-        ObjectMapper mapper = new ObjectMapper();
-        JsonNode jsonNode = mapper.readTree(responseJson);
+        JSONObject jsonObject = JSON.parseObject(responseJson);
 
-        if(!jsonNode.elements().hasNext())
+        if (jsonObject.isEmpty()) {
             return null;
+        }
 
         VnfEntity vnfEntity = new VnfEntity();
-        vnfEntity.setInMaint(getBooleanElementByNode(jsonNode, "in-maint"));
-        vnfEntity.setClosedLoopDisabled(getBooleanElementByNode(jsonNode, "is-closed-loop-disabled"));
-        vnfEntity.setOrchestrationStatus(getTextElementByNode(jsonNode, "orchestration-status"));
-        vnfEntity.setProvStatus(getTextElementByNode(jsonNode, "prov-status"));
-        vnfEntity.setResourceVersion(getTextElementByNode(jsonNode,"resource-version"));
-        vnfEntity.setServiceId(getTextElementByNode(jsonNode,"service-id"));
-        vnfEntity.setVnfId(getTextElementByNode(jsonNode,"vnf-id"));
-        vnfEntity.setVnfName(getTextElementByNode(jsonNode,"vnf-name"));
-        vnfEntity.setVnfType(getTextElementByNode(jsonNode,"vnf-type"));
-
-        if (jsonNode.has(RELATIONSHIP_LIST)) {
-            JsonNode relationshipListNode = jsonNode.get(RELATIONSHIP_LIST);
-            if (relationshipListNode.has("relationship")) {
-                JsonNode relationshipNode = relationshipListNode.get("relationship");
-                vnfEntity.getRelationshipList().setRelationships(convertRelationships(relationshipNode));
-            }
-        }
+        vnfEntity.setInMaint(getBooleanElementByNode(jsonObject, "in-maint"));
+        vnfEntity.setClosedLoopDisabled(
+                getBooleanElementByNode(jsonObject, "is-closed-loop-disabled"));
+        vnfEntity.setOrchestrationStatus(getTextElementByNode(jsonObject, "orchestration-status"));
+        vnfEntity.setProvStatus(getTextElementByNode(jsonObject, "prov-status"));
+        vnfEntity.setResourceVersion(getTextElementByNode(jsonObject, "resource-version"));
+        vnfEntity.setServiceId(getTextElementByNode(jsonObject, "service-id"));
+        vnfEntity.setVnfId(getTextElementByNode(jsonObject, "vnf-id"));
+        vnfEntity.setVnfName(getTextElementByNode(jsonObject, "vnf-name"));
+        vnfEntity.setVnfType(getTextElementByNode(jsonObject, "vnf-type"));
+
+        setRelationShips(jsonObject, vnfEntity.getRelationshipList());
         if (vnfEntity.getRelationshipList().getRelationships() == null) {
             vnfEntity.getRelationshipList().setRelationships(Collections.emptyList());
         }
         return vnfEntity;
     }
 
-    private List<VmResourceLink> convertResultDataList(JsonNode resultData) {
+    private void setRelationShips(JSONObject jsonObject, RelationshipList relationshipList) {
+        if (jsonObject.get(RELATIONSHIP_LIST) != null) {
+            JSONObject relationshipListNode = jsonObject.getJSONObject(RELATIONSHIP_LIST);
+            String relationship = "relationship";
+            if (relationshipListNode.get(relationship) != null) {
+                JSONArray relationshipNode = relationshipListNode.getJSONArray(relationship);
+                relationshipList
+                        .setRelationships(convertRelationships(relationshipNode));
+            }
+        }
+    }
+
+    private List<VmResourceLink> convertResultDataList(JSONArray resultData) {
         List<VmResourceLink> vmResourceLinkList = new ArrayList<>();
-        resultData.forEach(node ->{
-            if (node.has("resource-link") && node.has("resource-type")) {
+        String resourceLink = "resource-link";
+        String resourceType = "resource-type";
+        for (int i = 0; i < resultData.size(); i++) {
+            JSONObject jsonObject = resultData.getJSONObject(i);
+            if (jsonObject.get(resourceLink) != null
+                    && jsonObject.get(resourceType) != null) {
                 VmResourceLink vmResourceLink = new VmResourceLink();
-                vmResourceLink.setResourceLink(getTextElementByNode(node, "resource-link"));
-                vmResourceLink.setResourceType(getTextElementByNode(node, "resource-type"));
+                vmResourceLink.setResourceLink(getTextElementByNode(jsonObject, resourceLink));
+                vmResourceLink.setResourceType(getTextElementByNode(jsonObject, resourceType));
                 vmResourceLinkList.add(vmResourceLink);
             }
-        });
+        }
         return vmResourceLinkList;
     }
 
-    private List<Relationship> convertRelationships(JsonNode relationshipNode) {
+    private List<Relationship> convertRelationships(JSONArray relationshipNode) {
         List<Relationship> relationshipList = new ArrayList<>();
-        relationshipNode.forEach(node ->{
+        for (int i = 0; i < relationshipNode.size(); i++) {
             Relationship relationship = new Relationship();
-            relationship.setRelatedLink(getTextElementByNode(node, "related-link"));
-            relationship.setRelatedTo(getTextElementByNode(node, "related-to"));
-            if (node.has("related-to-property")) {
-                JsonNode relatedToPropertyNode = node.get("related-to-property");
+            JSONObject jsonObject = relationshipNode.getJSONObject(i);
+
+            relationship.setRelatedLink(getTextElementByNode(jsonObject, "related-link"));
+            relationship.setRelatedTo(getTextElementByNode(jsonObject, "related-to"));
+            if (jsonObject.get("related-to-property") != null) {
+                JSONArray relatedToPropertyNode = jsonObject.getJSONArray("related-to-property");
                 relationship.setRelatedToPropertyList(
                         convertRelatedToProperty(relatedToPropertyNode));
             } else {
                 relationship.setRelatedToPropertyList(Collections.emptyList());
             }
-            if (node.has("relationship-data")) {
-                JsonNode relationshipDataNode = node.get("relationship-data");
+            if (jsonObject.get("relationship-data") != null) {
+                JSONArray relationshipDataNode = jsonObject.getJSONArray("relationship-data");
                 relationship
                         .setRelationshipDataList(convertRelationshipDate(relationshipDataNode));
             } else {
                 relationship.setRelationshipDataList(Collections.emptyList());
             }
             relationshipList.add(relationship);
-        });
+        }
+
         return relationshipList;
     }
 
-    private List<RelationshipData> convertRelationshipDate(JsonNode relationshipDataNode) {
+    private List<RelationshipData> convertRelationshipDate(JSONArray relationshipDataNode) {
         List<RelationshipData> relationshipDataList = new ArrayList<>();
-        relationshipDataNode.forEach(node ->{
+        for (int i = 0; i < relationshipDataNode.size(); i++) {
+            JSONObject jsonObject = relationshipDataNode.getJSONObject(i);
             RelationshipData relationshipData = new RelationshipData();
             relationshipData.setRelationshipKey(
-                    getTextElementByNode(node,"relationship-key"));
+                    getTextElementByNode(jsonObject, "relationship-key"));
             relationshipData.setRelationshipValue(
-                    getTextElementByNode(node,"relationship-value"));
+                    getTextElementByNode(jsonObject, "relationship-value"));
             relationshipDataList.add(relationshipData);
-        });
+            relationshipDataList.add(relationshipData);
+
+        }
         return relationshipDataList;
     }
 
-    private List<RelatedToProperty> convertRelatedToProperty(JsonNode relatedToPropertyNode) {
+    private List<RelatedToProperty> convertRelatedToProperty(JSONArray relatedToPropertyNode) {
         List<RelatedToProperty> relatedToPropertyList = new ArrayList<>();
-        relatedToPropertyNode.forEach(node ->{
+        for (int i = 0; i < relatedToPropertyNode.size(); i++) {
+            JSONObject jsonObject = relatedToPropertyNode.getJSONObject(i);
             RelatedToProperty relatedToProperty = new RelatedToProperty();
             relatedToProperty
-                    .setPropertyKey(getTextElementByNode(node, "property-key"));
+                    .setPropertyKey(getTextElementByNode(jsonObject, "property-key"));
             relatedToProperty.setPropertyValue(
-                    getTextElementByNode(node, "property-value"));
+                    getTextElementByNode(jsonObject, "property-value"));
             relatedToPropertyList.add(relatedToProperty);
-        });
+        }
         return relatedToPropertyList;
     }
 
-    private String getTextElementByNode(JsonNode jsonNode,String name){
-        if(jsonNode.has(name)){
-            return jsonNode.get(name).asText();
+    private String getTextElementByNode(JSONObject jsonNode, String name) {
+        if (jsonNode.get(name) != null) {
+            return jsonNode.getString(name);
         }
         return null;
     }
 
-    private Boolean getBooleanElementByNode(JsonNode jsonNode,String name){
-        if(jsonNode.has(name)){
-            return jsonNode.get(name).asBoolean();
+    private Boolean getBooleanElementByNode(JSONObject jsonNode, String name) {
+        if (jsonNode.get(name) != null) {
+            return jsonNode.getBoolean(name);
         }
         return null;
     }
index 204f352..9a1b0ea 100644 (file)
@@ -21,7 +21,6 @@ import javax.ws.rs.core.Response;
 import lombok.extern.slf4j.Slf4j;\r
 import net.sf.json.JSONArray;\r
 import net.sf.json.JSONObject;\r
-import org.glassfish.jersey.client.ClientConfig;\r
 import org.onap.holmes.common.constant.AlarmConst;\r
 \r
 @Slf4j\r
@@ -63,7 +62,7 @@ public class MicroServiceConfig {
     }\r
 \r
     private static String execQuery(String queryString) {\r
-        Client client = ClientBuilder.newClient(new ClientConfig());\r
+        Client client = ClientBuilder.newBuilder().build();\r
         Response response = client.target(queryString).request().get();\r
         return response.readEntity(String.class);\r
     }\r
index 91e9d42..5c6965a 100644 (file)
@@ -15,8 +15,7 @@
  */\r
 package org.onap.holmes.common.dmaap;\r
 \r
-import com.fasterxml.jackson.core.JsonProcessingException;\r
-import com.fasterxml.jackson.databind.ObjectMapper;\r
+import com.alibaba.fastjson.JSON;\r
 import javax.ws.rs.client.Client;\r
 import javax.ws.rs.client.ClientBuilder;\r
 import javax.ws.rs.client.Entity;\r
@@ -43,14 +42,7 @@ public class Publisher {
 \r
     public boolean publish(PolicyMsg msg) throws CorrelationException {\r
         Client client = ClientBuilder.newClient(new ClientConfig());\r
-        ObjectMapper mapper = new ObjectMapper();\r
-        String content = null;\r
-        try {\r
-            content = mapper.writeValueAsString(msg);\r
-        } catch (JsonProcessingException e) {\r
-            throw new CorrelationException("Failed to convert the message object to a json string.",\r
-                    e);\r
-        }\r
+        String content = JSON.toJSONString(msg);\r
         WebTarget webTarget = client.target(url);\r
         Response response = null;\r
         try {\r
index 2b8e114..b8552b2 100644 (file)
  */
 package org.onap.holmes.common.dropwizard.ioc.bundle;
 
+import com.codahale.metrics.health.HealthCheck;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.collect.Lists;
+import io.dropwizard.Configuration;
+import io.dropwizard.ConfiguredBundle;
+import io.dropwizard.lifecycle.ServerLifecycleListener;
+import io.dropwizard.servlets.tasks.Task;
+import io.dropwizard.setup.Bootstrap;
+import io.dropwizard.setup.Environment;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Field;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
-
 import javax.ws.rs.Path;
 import javax.ws.rs.ext.Provider;
-
 import org.eclipse.jetty.util.component.LifeCycle;
 import org.glassfish.hk2.api.ServiceLocator;
 import org.glassfish.hk2.api.ServiceLocatorFactory;
@@ -49,19 +56,6 @@ import org.reflections.util.FilterBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.codahale.metrics.health.HealthCheck;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.Lists;
-
-import io.dropwizard.Configuration;
-import io.dropwizard.ConfiguredBundle;
-import io.dropwizard.configuration.ConfigurationSourceProvider;
-import io.dropwizard.lifecycle.Managed;
-import io.dropwizard.lifecycle.ServerLifecycleListener;
-import io.dropwizard.servlets.tasks.Task;
-import io.dropwizard.setup.Bootstrap;
-import io.dropwizard.setup.Environment;
-
 /**
  * complete the integration of hK2 container and dropwizard
  * 
index b3f1eb6..e0d5bf7 100644 (file)
@@ -16,8 +16,8 @@
 
 package org.onap.holmes.common.aai;
 import static org.easymock.EasyMock.anyObject;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
 import static org.powermock.api.mockito.PowerMockito.when;
 
 import java.util.HashMap;
@@ -110,36 +110,7 @@ public class AaiQueryTest {
 
 
 
-    @Test
-    public void testAaiQuery_getAaiVmData_exception() throws Exception {
-        PowerMock.resetAll();
-        thrown.expect(CorrelationException.class);
-        thrown.expectMessage("Failed to convert aai vm response data to vm entity");
-        aaiQuery = PowerMock.createPartialMock(AaiQuery.class, "getVmResourceLinks");
-
-        aaiResponseUtil = new AaiResponseUtil();
-        Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
-
-        PowerMockito.mockStatic(HttpsUtils.class);
-        Map<String, String> headers = new HashMap<>();
-        headers.put("X-TransactionId", AaiConfig.X_TRANSACTION_ID);
-        headers.put("X-FromAppId", AaiConfig.X_FROMAPP_ID);
-        headers.put("Authorization", AaiConfig.getAuthenticationCredentials());
-        headers.put("Accept", "application/json");
-        String url = "http://10.96.33.33/api/aai-cloudInfrastructure/v11";
-
-        when(HttpsUtils.get(url, headers)).thenReturn("");
-
-        PowerMockito.mockStatic(MicroServiceConfig.class);
-        when(MicroServiceConfig.getMsbServerAddrWithHttpPrefix()).thenReturn("http://10.96.33.33:80");
 
-        PowerMock.expectPrivate(aaiQuery, "getVmResourceLinks", "test1", "test2")
-                .andReturn("/aai/v11/cloud-infrastructure");
-
-        PowerMock.replayAll();
-        Whitebox.invokeMethod(aaiQuery, "getAaiVmData", "test1", "test2");
-        PowerMock.verifyAll();
-    }
 
     @Test
     public void testAaiQuery_getAaiVmData_httpsutils_exception() throws Exception {
@@ -189,23 +160,7 @@ public class AaiQueryTest {
         assertThat(resource, equalTo("le-vserver-id-val-51834"));
     }
 
-    @Test
-    public void testAaiQuery_getVmResourceLinks_exception() throws Exception {
-        PowerMock.resetAll();
-        thrown.expect(CorrelationException.class);
-        thrown.expectMessage("Failed to get aai resource link");
-        aaiQuery = PowerMock.createPartialMock(AaiQuery.class, "getResourceLinksResponse");
-
-        aaiResponseUtil = new AaiResponseUtil();
-        Whitebox.setInternalState(aaiQuery, "aaiResponseUtil", aaiResponseUtil);
-
-        PowerMock.expectPrivate(aaiQuery, "getResourceLinksResponse", "test1", "test2").andReturn("");
-        PowerMock.replayAll();
-        String resource = Whitebox.invokeMethod(aaiQuery, "getVmResourceLinks", "test1", "test2");
-        PowerMock.verifyAll();
 
-        assertThat(resource, equalTo("le-vserver-id-val-51834"));
-    }
 
     @Test
     public void testAaiQuery_getResourceLinksResponse() throws Exception {
index fee98b9..3d20af9 100644 (file)
@@ -16,8 +16,9 @@
 
 package org.onap.holmes.common.aai;
 
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
 import java.util.List;
@@ -112,12 +113,6 @@ public class AaiResponseUtilTest {
         assertThat(actual.isEmpty(), equalTo(true));
     }
 
-    @Test
-    public void testAaiResponseUtil_convert_resource_link_throw_IOException() throws IOException {
-        thrown.expect(IOException.class);
-        String json = "{**}";
-        aaiResponseUtil.convertJsonToVmResourceLink(json);
-    }
 
     @Test
     public void testAaiResponseUtil_convert_VmEntity_success() throws IOException {
@@ -142,12 +137,6 @@ public class AaiResponseUtilTest {
         assertThat(actual.getVserverSelflink(), equalTo("example-vserver-selflink-val-2"));
     }
 
-    @Test
-    public void testAaiResponseUtil_convert_VmEntity_throw_IOException() throws IOException {
-        thrown.expect(IOException.class);
-        String json = "{**}";
-        aaiResponseUtil.convertJsonToVmEntity(json);
-    }
 
     @Test
     public void testAaiResponseUtil_convert_VmEntity_input_empty() throws IOException {
@@ -221,13 +210,6 @@ public class AaiResponseUtilTest {
                         .getRelationshipValue(), equalTo("Demonstration3"));
     }
 
-    @Test
-    public void testAaiResponseUtil_throw_IOException() throws IOException {
-        thrown.expect(IOException.class);
-        String json = "{**}";
-        aaiResponseUtil.convertJsonToVnfEntity(json);
-    }
-
     @Test
     public void testAaiResponseUtil_convert_VnfEntity_input_empty() throws IOException {
         String json = "{}";
index 92658d6..d701f3d 100644 (file)
 
 package org.onap.holmes.common.api.stat;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 import java.util.Date;
 import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.assertFalse;
@@ -29,6 +34,7 @@ import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.onap.holmes.common.api.entity.ServiceNode;
 
 public class AlarmTest {
 
@@ -190,4 +196,16 @@ public class AlarmTest {
         alarm.setCenterType(centerType);
         assertThat(centerType, equalTo(alarm.getCenterType()));
     }
+    @Test
+    public void TestJson(){
+        ServiceNode serviceNode = new ServiceNode();
+        serviceNode.setIp("111");
+        String jsonString = "{\"uid\":\"189024\", \"region\":\"SouthChina\", \"order\":123}";
+        String  COMPLEX_JSON_STR = "{\"teacherName\":\"crystall\",\"teacherAge\":27,\"course\":{\"courseName\":\"english\",\"code\":1270},\"students\":[{\"studentName\":\"lily\",\"studentAge\":12},{\"studentName\":\"lucy\",\"studentAge\":15}]}";
+
+        JSONObject jsonObject = JSON.parseObject(COMPLEX_JSON_STR);
+        JSONArray jsonArray = jsonObject.getJSONArray("students");
+         System.out.printf("jsonObject:"+jsonArray);
+//     System.out.println("uid:" + retMap.get("uid") + ", " + "region:" + retMap.get("region") + ", " + "order:" + retMap.get("order"));
+    }
 }