summaryrefslogtreecommitdiffstats
path: root/holmes-actions
diff options
context:
space:
mode:
authorYiLi <li.yi101@zte.com.cn>2018-02-11 17:39:05 +0800
committerYiLi <li.yi101@zte.com.cn>2018-02-12 11:56:57 +0800
commit83307e37a264972f4f9c60a114f40a375e32634b (patch)
treeed6639132fb0a97d8853ded37e9faa9f6eab4e24 /holmes-actions
parentd4a991ad631f16831d380eef8e7405d9c2ea85c5 (diff)
Test Replace Jackson with GSON
Change-Id: I7ac92dd83a4bf7dcfb70199f1d0f61e600db8904 Issue-ID: HOLMES-115 Signed-off-by: YiLi <li.yi101@zte.com.cn>
Diffstat (limited to 'holmes-actions')
-rw-r--r--holmes-actions/pom.xml21
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java6
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java173
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java3
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java12
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java24
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java49
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java24
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java18
9 files changed, 145 insertions, 185 deletions
diff --git a/holmes-actions/pom.xml b/holmes-actions/pom.xml
index 850a03a..57f2eaa 100644
--- a/holmes-actions/pom.xml
+++ b/holmes-actions/pom.xml
@@ -22,12 +22,6 @@
<dependency>
<groupId>org.onap.msb.java-sdk</groupId>
<artifactId>msb-java-sdk</artifactId>
- <!--<exclusions>-->
- <!--<exclusion>-->
- <!--<groupId>com.eclipsesource.jaxrs</groupId>-->
- <!--<artifactId>jersey-all</artifactId>-->
- <!--</exclusion>-->
- <!--</exclusions>-->
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
@@ -57,11 +51,21 @@
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey2-jaxrs</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>com.fasterxml.jackson.dataformat</groupId>
+ <artifactId>jackson-dataformat-xml</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
@@ -169,6 +173,11 @@
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ <version>1.1.23</version>
+ </dependency>
</dependencies>
<build>
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
index b80c40e..48e6ec0 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
@@ -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 {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
index 37bfc1d..a8d3c0d 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiResponseUtil.java
@@ -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,
@@ -15,13 +15,15 @@
*/
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;
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
index 204f352..9a1b0ea 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/config/MicroServiceConfig.java
@@ -21,7 +21,6 @@ import javax.ws.rs.core.Response;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
-import org.glassfish.jersey.client.ClientConfig;
import org.onap.holmes.common.constant.AlarmConst;
@Slf4j
@@ -63,7 +62,7 @@ public class MicroServiceConfig {
}
private static String execQuery(String queryString) {
- Client client = ClientBuilder.newClient(new ClientConfig());
+ Client client = ClientBuilder.newBuilder().build();
Response response = client.target(queryString).request().get();
return response.readEntity(String.class);
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
index 91e9d42..5c6965a 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
@@ -15,8 +15,7 @@
*/
package org.onap.holmes.common.dmaap;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.alibaba.fastjson.JSON;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
@@ -43,14 +42,7 @@ public class Publisher {
public boolean publish(PolicyMsg msg) throws CorrelationException {
Client client = ClientBuilder.newClient(new ClientConfig());
- ObjectMapper mapper = new ObjectMapper();
- String content = null;
- try {
- content = mapper.writeValueAsString(msg);
- } catch (JsonProcessingException e) {
- throw new CorrelationException("Failed to convert the message object to a json string.",
- e);
- }
+ String content = JSON.toJSONString(msg);
WebTarget webTarget = client.target(url);
Response response = null;
try {
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
index 2b8e114..b8552b2 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dropwizard/ioc/bundle/AutoConfigBundle.java
@@ -15,16 +15,23 @@
*/
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
*
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
index b3f1eb6..e0d5bf7 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java
@@ -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 {
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
index fee98b9..3d20af9 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiResponseUtilTest.java
@@ -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 {
@@ -222,13 +211,6 @@ public class AaiResponseUtilTest {
}
@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 = "{}";
VnfEntity actual = aaiResponseUtil.convertJsonToVnfEntity(json);
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
index 92658d6..d701f3d 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java
@@ -16,6 +16,11 @@
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"));
+ }
}