summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/test
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2020-07-16 16:11:50 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2020-07-17 08:57:08 +0800
commit490fc3c1fafe50d5fb0e23db5cfd10730be96866 (patch)
tree7c6aa468714460bc584666956d7fb8ff2df0edc9 /holmes-actions/src/test
parent3e5ddaee6984869b67dda89b7f8e1932a2b27045 (diff)
Fixed the CLM Issues
Change-Id: I8e6703078c400e94eec6eaa9a65a7e7dc3f0218e Issue-ID: HOLMES-331 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/test')
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2Test.java37
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java79
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQueryTest.java12
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/api/stat/AlarmTest.java70
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java45
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCacheTest.java47
-rw-r--r--holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCacheTest.java46
7 files changed, 190 insertions, 146 deletions
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2Test.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2Test.java
index cd1d505..804df1f 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2Test.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4Ccvpn2Test.java
@@ -20,13 +20,10 @@
package org.onap.holmes.common.aai;
-import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import org.easymock.EasyMock;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.aai.config.AaiConfig;
@@ -43,11 +40,7 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
+import java.io.*;
import static org.onap.holmes.common.config.MicroServiceConfig.MSB_ADDR;
@@ -59,7 +52,7 @@ public class AaiQuery4Ccvpn2Test {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private static JSONObject data;
+ private static JsonObject data;
private static AaiQuery4Ccvpn2 aai = AaiQuery4Ccvpn2.newInstance();
@@ -79,7 +72,7 @@ public class AaiQuery4Ccvpn2Test {
reader = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
reader.lines().forEach(l -> sb.append(l));
- data = JSONObject.parseObject(sb.toString());
+ data = JsonParser.parseString(sb.toString()).getAsJsonObject();
} catch (FileNotFoundException e) {
// Do nothing
} catch (IOException e) {
@@ -119,18 +112,15 @@ public class AaiQuery4Ccvpn2Test {
@Test
public void test_getServiceInstances_exception() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("site-resources").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("site-resources").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("499hkg9933NNN").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("499hkg9933NNN").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
PowerMock.replayAll();
@@ -143,18 +133,15 @@ public class AaiQuery4Ccvpn2Test {
@Test
public void test_getServiceInstancesNull_exception() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("site-resources1").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("site-resources1").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("499hkg9933NNN").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("499hkg9933NNN").toJSONString
- ());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("499hkg9933NNN").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
PowerMock.replayAll();
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java
index b75e61d..f1855f9 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/aai/AaiQuery4CcvpnTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2018 ZTE Corporation.
+ * Copyright 2018-2020 ZTE Corporation.
* <p>
* 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
@@ -14,14 +14,11 @@
package org.onap.holmes.common.aai;
-import com.alibaba.fastjson.JSONObject;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
import org.easymock.EasyMock;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
+import org.junit.*;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.onap.holmes.common.aai.config.AaiConfig;
@@ -31,20 +28,12 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.*;
import javax.ws.rs.client.Invocation.Builder;
-import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
+import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
@@ -61,7 +50,7 @@ public class AaiQuery4CcvpnTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- private static JSONObject data;
+ private static JsonObject data;
private static AaiQuery4Ccvpn aai = AaiQuery4Ccvpn.newInstance();
@@ -81,7 +70,7 @@ public class AaiQuery4CcvpnTest {
reader = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
reader.lines().forEach(l -> sb.append(l));
- data = JSONObject.parseObject(sb.toString());
+ data = JsonParser.parseString(sb.toString()).getAsJsonObject();
} catch (FileNotFoundException e) {
// Do nothing
} catch (IOException e) {
@@ -152,7 +141,7 @@ public class AaiQuery4CcvpnTest {
@Test
public void test_getLogicLink() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("logic-link").toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("logic-link").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
PowerMock.replayAll();
@@ -168,32 +157,32 @@ public class AaiQuery4CcvpnTest {
@Test
public void test_getServiceInstances_exception() {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("vpn-binding").toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("vpn-binding").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("connectivity").toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("connectivity").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
EasyMock.expect(response.readEntity(String.class))
- .andReturn(data.getJSONObject("service-instance-by-connectivity").toJSONString());
+ .andReturn(data.get("service-instance-by-connectivity").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
EasyMock.expect(response.readEntity(String.class))
- .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString());
+ .andReturn(data.get("service-instances-by-service-type").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("service-instance").toString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("service-instance").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.NOT_FOUND).times(2);
thrown.expect(RuntimeException.class);
PowerMock.replayAll();
- JSONObject instance = aai.getServiceInstance("network-1", "pnf-1", "interface-1", "DOWN");
+ JsonObject instance = aai.getServiceInstance("network-1", "pnf-1", "interface-1", "DOWN");
PowerMock.verifyAll();
@@ -204,49 +193,49 @@ public class AaiQuery4CcvpnTest {
@Test
public void test_getServiceInstance() {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("vpn-binding").toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("vpn-binding").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.getJSONObject("connectivity").toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.get("connectivity").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
EasyMock.expect(response.readEntity(String.class))
- .andReturn(data.getJSONObject("service-instance-by-connectivity").toJSONString());
+ .andReturn(data.get("service-instance-by-connectivity").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockGetMethod();
EasyMock.expect(response.readEntity(String.class))
- .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString());
+ .andReturn(data.get("service-instances-by-service-type").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
PowerMock.replayAll();
- JSONObject instance = aai.getServiceInstance("network-1", "pnf-1", "interface-1", "DOWN");
+ JsonObject instance = aai.getServiceInstance("network-1", "pnf-1", "interface-1", "DOWN");
PowerMock.verifyAll();
- assertThat(instance.getString("service-instance-id"), equalTo("some id 1"));
- assertThat(instance.getString("globalSubscriberId"), equalTo("e151059a-d924-4629-845f-264db19e50b4"));
- assertThat(instance.getString("serviceType"), equalTo("volte"));
+ assertThat(instance.get("service-instance-id").getAsString(), equalTo("some id 1"));
+ assertThat(instance.get("globalSubscriberId").getAsString(), equalTo("e151059a-d924-4629-845f-264db19e50b4"));
+ assertThat(instance.get("serviceType").getAsString(), equalTo("volte"));
}
@Test
public void test_getServiceInstance_1() throws Exception {
mockGetMethod();
EasyMock.expect(response.readEntity(String.class))
- .andReturn(data.getJSONObject("service-instances-by-service-type").toJSONString());
+ .andReturn(data.get("service-instances-by-service-type").toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
PowerMock.replayAll();
- JSONObject instance = Whitebox.invokeMethod(aai, "getServiceInstance",
+ JsonObject instance = Whitebox.invokeMethod(aai, "getServiceInstance",
"custom-1", "service-type-1");
PowerMock.verifyAll();
- assertThat(instance.getString("service-instance-id"), equalTo("some id 1"));
+ assertThat(instance.get("service-instance-id").getAsString(), equalTo("some id 1"));
}
@Test
@@ -259,20 +248,20 @@ public class AaiQuery4CcvpnTest {
PowerMock.replayAll();
- JSONObject instance = Whitebox.invokeMethod(aai, "getServiceInstance",
+ JsonObject instance = Whitebox.invokeMethod(aai, "getServiceInstance",
"custom-1", "service-type-1");
PowerMock.verifyAll();
- assertThat(instance.getString("service-instance-id"), equalTo("some id 1"));
- assertThat(instance.getString("service-instance-id"), equalTo("some id 2"));
- assertThat(instance.getString("service-instance-id"), equalTo("some id 3"));
+ assertThat(instance.get("service-instance-id").getAsString(), equalTo("some id 1"));
+ assertThat(instance.get("service-instance-id").getAsString(), equalTo("some id 2"));
+ assertThat(instance.get("service-instance-id").getAsString(), equalTo("some id 3"));
}
@Test
public void test_updateTerminalPointStatus() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockPatchMethod();
@@ -288,7 +277,7 @@ public class AaiQuery4CcvpnTest {
@Test
public void test_updateTerminalPointStatus_exception() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockPatchMethod();
@@ -307,7 +296,7 @@ public class AaiQuery4CcvpnTest {
@Test
public void test_updateLogicLinkStatus() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockPatchMethod();
@@ -323,7 +312,7 @@ public class AaiQuery4CcvpnTest {
@Test
public void test_updateLogicLinkStatus_exception() throws CorrelationException {
mockGetMethod();
- EasyMock.expect(response.readEntity(String.class)).andReturn(data.toJSONString());
+ EasyMock.expect(response.readEntity(String.class)).andReturn(data.toString());
EasyMock.expect(response.getStatusInfo()).andReturn(Response.Status.OK);
mockPatchMethod();
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 15904d5..0340e04 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
@@ -295,16 +295,4 @@ public class AaiQueryTest {
assertThat(actual, equalTo("https://aai.onap:8443/url"));
}
-
- @Test
- public void testAaiQuery_getMsbSuffixAddr_Ok() throws Exception {
- PowerMock.resetAll();
- String url = "/aai/v11/network/generic-vnfs/generic-vnf?";
- String expect = "/api/aai-network/v11/generic-vnfs/generic-vnf?";
- aaiQuery = new AaiQuery();
- PowerMock.replayAll();
- String actual = Whitebox.invokeMethod(aaiQuery, "getMsbSuffixAddr", url);
- PowerMock.verifyAll();
- assertThat(actual, equalTo(expect));
- }
}
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 6cf62d6..0063b08 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,24 +16,16 @@
package org.onap.holmes.common.api.stat;
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-
-import java.util.Date;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-import java.util.HashMap;
-import java.util.Map;
import org.junit.After;
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;
+
+import java.util.Date;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
public class AlarmTest {
@@ -43,39 +35,39 @@ public class AlarmTest {
private Alarm alarm;
@Before
- public void before() throws Exception {
+ public void before() {
alarm = new Alarm();
}
@After
- public void after() throws Exception {
+ public void after() {
}
@Test
- public void testContainNode_NoContainLink() throws Exception {
+ public void testContainNode_NoContainLink() {
alarm.addLinkIdNodeIdx(1, 2);
assertThat(false, equalTo(alarm.containNode(2, 2)));
}
@Test
- public void testContainNode_ContainLinkNoIdx() throws Exception {
+ public void testContainNode_ContainLinkNoIdx() {
alarm.addLinkIdNodeIdx(1, 2);
assertFalse(alarm.containNode(1, 3));
}
@Test
- public void testContainNode_ContainLinkAndIdx() throws Exception {
+ public void testContainNode_ContainLinkAndIdx() {
alarm.addLinkIdNodeIdx(1, 2);
assertTrue(alarm.containNode(1, 2));
}
@Test
- public void testGetDataType() throws Exception {
+ public void testGetDataType() {
assertThat(Alarm.APLUS_EVENT, equalTo(alarm.getDataType()));
}
@Test
- public void testToString() throws Exception {
+ public void testToString() {
Alarm alarmTempA = new Alarm();
Alarm alarmTempB = new Alarm();
Date date = new Date();
@@ -89,7 +81,7 @@ public class AlarmTest {
}
@Test
- public void testHashCode() throws Exception {
+ public void testHashCode() {
final Alarm alarmTemp = new Alarm();
final String alarmKey = "alarmKey";
alarm.setAlarmKey(alarmKey);
@@ -98,7 +90,7 @@ public class AlarmTest {
}
@Test
- public void testEqualsAnd_NotNull() throws Exception {
+ public void testEqualsAnd_NotNull() {
final Alarm alarmTemp = new Alarm();
final String alarmKey = "alarmKey";
alarm.setAlarmKey(alarmKey);
@@ -107,12 +99,12 @@ public class AlarmTest {
}
@Test
- public void testEqualsAndH_isNull() throws Exception {
+ public void testEqualsAndH_isNull() {
assertFalse(alarm.equals(null));
}
@Test
- public void testClone() throws Exception {
+ public void testClone() throws CloneNotSupportedException {
alarm.setAlarmKey("alarmKey");
Alarm alarmTemp = (Alarm) alarm.clone();
assertTrue(alarm.equals(alarmTemp));
@@ -120,40 +112,40 @@ public class AlarmTest {
}
@Test
- public void testGetObjectId() throws Exception {
+ public void testGetObjectId() {
alarm.setId(11);
assertThat("11", equalTo(alarm.getObjectId()));
}
@Test
- public void testAddLinkIds() throws Exception {
+ public void testAddLinkIds() {
final int linkId = 11;
alarm.addLinkIds(linkId);
assertTrue(alarm.getLinkIds().contains(linkId));
}
@Test
- public void testContainsPriority_true() throws Exception {
+ public void testContainsPriority_true() {
String ruleId = "ruleId";
alarm.getPriorityMap().put(ruleId, 2);
assertTrue(alarm.containsPriority(ruleId));
}
@Test
- public void testContainsPriority_false() throws Exception {
+ public void testContainsPriority_false() {
final String ruleId = "ruleId";
assertFalse(alarm.containsPriority(ruleId));
}
@Test
- public void testGetPriority_isNull() throws Exception {
+ public void testGetPriority_isNull() {
final String ruleId = "ruleId";
alarm.getPriorityMap().put(ruleId, null);
assertThat(0, equalTo(alarm.getPriority(ruleId)));
}
@Test
- public void testGetPriority_notNull() throws Exception {
+ public void testGetPriority_notNull() {
final String ruleId = "ruleId";
final int priority = 2;
alarm.getPriorityMap().put(ruleId, priority);
@@ -161,14 +153,14 @@ public class AlarmTest {
}
@Test
- public void testGetAlarmTypeRuleId_isNull() throws Exception {
+ public void testGetAlarmTypeRuleId_isNull() {
final String ruleId = "ruleId";
alarm.getRootAlarmTypeMap().put(ruleId, null);
assertThat(-1, equalTo(alarm.getRootAlarmType(ruleId)));
}
@Test
- public void testGetAlarmTypeRuleId_notNull() throws Exception {
+ public void testGetAlarmTypeRuleId_notNull() {
final String ruleId = "ruleId";
final int rootAlarmType = 2;
alarm.getRootAlarmTypeMap().put(ruleId, rootAlarmType);
@@ -176,21 +168,9 @@ public class AlarmTest {
}
@Test
- public void getterAndSetter4CenterType() throws Exception {
+ public void getterAndSetter4CenterType() {
final int centerType = 1;
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"));
- }
}
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
index 6494cd8..76c4a45 100644
--- a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/DmaapServiceTest.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017-2020 ZTE Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,20 +15,6 @@
*/
package org.onap.holmes.common.dmaap;
-import static org.easymock.EasyMock.anyObject;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertThat;
-
-import java.io.*;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Rule;
@@ -45,12 +31,26 @@ import org.onap.holmes.common.dcae.DcaeConfigurationsCache;
import org.onap.holmes.common.dcae.utils.DcaeConfigurationParser;
import org.onap.holmes.common.dmaap.entity.PolicyMsg;
import org.onap.holmes.common.dmaap.entity.PolicyMsg.EVENT_STATUS;
+import org.onap.holmes.common.dmaap.store.ClosedLoopControlNameCache;
+import org.onap.holmes.common.dmaap.store.UniqueRequestIdCache;
import org.onap.holmes.common.exception.CorrelationException;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
+import java.io.*;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
@PrepareForTest({DmaapService.class, Publisher.class, AaiQuery.class})
@RunWith(PowerMockRunner.class)
public class DmaapServiceTest {
@@ -62,17 +62,24 @@ public class DmaapServiceTest {
private DmaapService dmaapService;
+ private ClosedLoopControlNameCache closedLoopControlNameCache = new ClosedLoopControlNameCache();
+
+ private UniqueRequestIdCache uniqueRequestIdCache = new UniqueRequestIdCache();
+
@Before
public void setUp() {
- dmaapService = new DmaapService();
aaiQuery = PowerMock.createMock(AaiQuery.class);
- Whitebox.setInternalState(dmaapService, "aaiQuery", aaiQuery);
+
+ dmaapService = new DmaapService();
+ dmaapService.setClosedLoopControlNameCache(closedLoopControlNameCache);
+ dmaapService.setUniqueRequestIdCache(uniqueRequestIdCache);
+ dmaapService.setAaiQuery(aaiQuery);
}
@Test
public void testDmaapService_getDefaultPolicyMsg_ok() throws Exception {
String packageName = "org.onap.holmes.rule";
- DmaapService.loopControlNames.put(packageName, "Control-loop-VoLTE");
+ closedLoopControlNameCache.put(packageName, "Control-loop-VoLTE");
long startTime = System.currentTimeMillis();
long endTime = System.currentTimeMillis() + 1000000;
VesAlarm vesAlarm = new VesAlarm();
@@ -274,7 +281,7 @@ public class DmaapServiceTest {
PolicyMsg policyMsg = new PolicyMsg();
policyMsg.setClosedLoopEventStatus(EVENT_STATUS.ABATED);
policyMsg.setRequestID("testRequestid");
- DmaapService.alarmUniqueRequestID.put("testAlarmId", "testRequestid");
+ uniqueRequestIdCache.put("testAlarmId", "testRequestid");
PowerMock.expectNew(Publisher.class).andReturn(publisher);
EasyMock.expect(publisher.publish(policyMsg)).andReturn(true);
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCacheTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCacheTest.java
new file mode 100644
index 0000000..038f634
--- /dev/null
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/ClosedLoopControlNameCacheTest.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2020 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.holmes.common.dmaap.store;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class ClosedLoopControlNameCacheTest {
+
+ private ClosedLoopControlNameCache cache = new ClosedLoopControlNameCache();
+
+ @Before
+ public void setUp() {
+ cache.clear();
+ }
+
+ @Test
+ public void put() {
+ cache.put("org.onap.holmes.test", "control-loop-1");
+ assertThat(cache.get("org.onap.holmes.test"), equalTo("control-loop-1"));
+ }
+
+ @Test
+ public void remove() {
+ cache.put("org.onap.holmes.test", "control-loop-1");
+ assertThat(cache.get("org.onap.holmes.test"), equalTo("control-loop-1"));
+ cache.remove("org.onap.holmes.test");
+ assertThat(cache.get("org.onap.holmes.test"), nullValue());
+ }
+} \ No newline at end of file
diff --git a/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCacheTest.java b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCacheTest.java
new file mode 100644
index 0000000..c341d7a
--- /dev/null
+++ b/holmes-actions/src/test/java/org/onap/holmes/common/dmaap/store/UniqueRequestIdCacheTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.holmes.common.dmaap.store;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+public class UniqueRequestIdCacheTest {
+ private UniqueRequestIdCache cache = new UniqueRequestIdCache();
+
+ @Before
+ public void setUp() {
+ cache.clear();
+ }
+
+ @Test
+ public void put() {
+ cache.put("alarmId-1", "requestId-1");
+ assertThat(cache.get("alarmId-1"), equalTo("requestId-1"));
+ }
+
+ @Test
+ public void remove() {
+ cache.put("alarmId-1", "requestId-1");
+ assertThat(cache.get("alarmId-1"), equalTo("requestId-1"));
+ cache.remove("alarmId-1");
+ assertThat(cache.get("alarmId-1"), nullValue());
+ }
+} \ No newline at end of file