aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authormalar <malarvizhi.44@wipro.com>2022-09-01 11:00:01 +0000
committermalar <malarvizhi.44@wipro.com>2022-09-08 15:23:57 +0000
commiteeafff5620de42cf115b2694d5eb67a7ddc48165 (patch)
tree53a41ad3c38ebe5f258f9f2412a3f284cc1074bd /src/test/java/org/onap
parent56fb6de5e2bf9bf21ddafbdb40a8b67536392356 (diff)
Modify payload for ANR closedloop to align with A1 based action
Issue-ID: DCAEGEN2-3148 Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com> Change-Id: I41264a68b3dd40306c59a1c39fc1fd47213a3b13
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java315
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java22
2 files changed, 179 insertions, 158 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java
index ba3d4c0..aff431b 100644
--- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java
@@ -2,21 +2,21 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019-2021 Wipro Limited.
+ * Copyright (C) 2019-2022 Wipro Limited.
* ==============================================================================
* 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.
* ============LICENSE_END=========================================================
- *
+ *
*******************************************************************************/
package org.onap.dcaegen2.services.sonhms.child;
@@ -80,179 +80,178 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest(classes = TestChildThreadUtils.class)
public class TestChildThreadUtils {
- ChildThreadUtils childThreadUtils;
- @Mock
- private SonRequestsRepository repository;
+ ChildThreadUtils childThreadUtils;
+ @Mock
+ private SonRequestsRepository repository;
- @Mock
- private PnfUtils pnfUtils;
- @Mock
- private PolicyDmaapClient policyDmaapClient;
-
- @Mock
- private HandOverMetricsRepository hoMetricRepository;
-
- @Mock
- private HoMetricsComponent hoMetricsComponent;
-
- @InjectMocks
- private ChildThreadUtils childThreadUtils2;
+ @Mock
+ private PnfUtils pnfUtils;
+ @Mock
+ private PolicyDmaapClient policyDmaapClient;
+
+ @Mock
+ private HandOverMetricsRepository hoMetricRepository;
+
+ @Mock
+ private HoMetricsComponent hoMetricsComponent;
+
+ @InjectMocks
+ private ChildThreadUtils childThreadUtils2;
- @Before
- public void setup() {
+ @Before
+ public void setup() {
- ConfigPolicy configPolicy = ConfigPolicy.getInstance();
- Configuration config = Configuration.getInstance();
- config.setConfigClientType("ConfigDB");
- config.setMinCollision(5);
- config.setMinConfusion(5);
- Map<String, Object> configPolicyMap = new HashMap<>();
- configPolicyMap.put("PCI_MODCONFIG_POLICY_NAME", "ControlLoop-vPCI-fb41f388-a5f2-11e8-98d0-529269fb1459");
- configPolicy.setConfig(configPolicyMap);
- childThreadUtils = new ChildThreadUtils(configPolicy, pnfUtils, policyDmaapClient, hoMetricsComponent);
- MockitoAnnotations.initMocks(this);
-
- }
+ ConfigPolicy configPolicy = ConfigPolicy.getInstance();
+ Configuration config = Configuration.getInstance();
+ config.setConfigClientType("ConfigDB");
+ config.setMinCollision(5);
+ config.setMinConfusion(5);
+ Map<String, Object> configPolicyMap = new HashMap<>();
+ configPolicyMap.put("PCI_MODCONFIG_POLICY_NAME", "ControlLoop-SONO1-fb41f388-a5f2-11e8-98d0-529269fb1459");
+ configPolicy.setConfig(configPolicyMap);
+ childThreadUtils = new ChildThreadUtils(configPolicy, pnfUtils, policyDmaapClient, hoMetricsComponent);
+ MockitoAnnotations.initMocks(this);
+
+ }
- @Test
- public void savePciRequestTest() {
- SonRequests sonRequest = new SonRequests();
- sonRequest.setTransactionId("transactionId");
- sonRequest.setChildThreadId(1L);
- PowerMockito.mockStatic(BeanUtil.class);
- PowerMockito.when(BeanUtil.getBean(SonRequestsRepository.class))
- .thenReturn(repository);
- when(repository.save(sonRequest)).thenReturn(sonRequest);
- childThreadUtils2.saveRequest("transactionId",1L);;
- assertEquals(sonRequest, repository.save(sonRequest));
- }
+ @Test
+ public void savePciRequestTest() {
+ SonRequests sonRequest = new SonRequests();
+ sonRequest.setTransactionId("transactionId");
+ sonRequest.setChildThreadId(1L);
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.when(BeanUtil.getBean(SonRequestsRepository.class))
+ .thenReturn(repository);
+ when(repository.save(sonRequest)).thenReturn(sonRequest);
+ childThreadUtils2.saveRequest("transactionId",1L);;
+ assertEquals(sonRequest, repository.save(sonRequest));
+ }
- @Test
- public void triggerOrWaitTest() {
- Map<String, ArrayList<Integer>> collisionConfusionResult = new HashMap<String, ArrayList<Integer>>();
- ArrayList<Integer> list = new ArrayList<Integer>();
- list.add(6);
- list.add(7);
- collisionConfusionResult.put("cellId", list);
+ @Test
+ public void triggerOrWaitTest() {
+ Map<String, ArrayList<Integer>> collisionConfusionResult = new HashMap<String, ArrayList<Integer>>();
+ ArrayList<Integer> list = new ArrayList<Integer>();
+ list.add(6);
+ list.add(7);
+ collisionConfusionResult.put("cellId", list);
- Boolean result = childThreadUtils.triggerOrWait(collisionConfusionResult);
- assertTrue(result);
- Map<String, ArrayList<Integer>> collisionConfusionResult1 = new HashMap<String, ArrayList<Integer>>();
+ Boolean result = childThreadUtils.triggerOrWait(collisionConfusionResult);
+ assertTrue(result);
+ Map<String, ArrayList<Integer>> collisionConfusionResult1 = new HashMap<String, ArrayList<Integer>>();
- ArrayList<Integer> list1 = new ArrayList<Integer>();
- list1.add(1);
- list1.add(2);
- collisionConfusionResult1.put("cell1", list1);
- result = childThreadUtils.triggerOrWait(collisionConfusionResult1);
- assertFalse(result);
+ ArrayList<Integer> list1 = new ArrayList<Integer>();
+ list1.add(1);
+ list1.add(2);
+ collisionConfusionResult1.put("cell1", list1);
+ result = childThreadUtils.triggerOrWait(collisionConfusionResult1);
+ assertFalse(result);
- }
+ }
- @Test
- public void getNotificationStringTest() {
+ @Test
+ public void getNotificationStringTest() {
- String policy_notif = readFromFile("/policy_notification.json");
- PolicyNotification expected = new PolicyNotification();
- ObjectMapper mapper = new ObjectMapper();
+ String policy_notif = readFromFile("/policy_notification.json");
+ PolicyNotification expected = new PolicyNotification();
+ ObjectMapper mapper = new ObjectMapper();
- try {
- expected = mapper.readValue(policy_notif, PolicyNotification.class);
- } catch (IOException e) {
- e.printStackTrace();
- }
+ try {
+ expected = mapper.readValue(policy_notif, PolicyNotification.class);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- String pnfName = "ncserver23";
- List<CellPciPair> cellPciPairs = new ArrayList<>();
+ String pnfName = "ncserver23";
+ List<CellPciPair> cellPciPairs = new ArrayList<>();
- cellPciPairs.add(new CellPciPair("Chn0330", 6));
- cellPciPairs.add(new CellPciPair("Chn0331", 7));
- String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731";
- Long alarmStart = Long.parseLong("1542445563201");
+ cellPciPairs.add(new CellPciPair("Chn0330", 6));
+ cellPciPairs.add(new CellPciPair("Chn0331", 7));
+ String requestId = "a4130fd5-2291-4a83-8992-04e4c9f32731";
+ Long alarmStart = Long.parseLong("1542445563201");
- String result = childThreadUtils.getNotificationString(pnfName, requestId, "payloadString", alarmStart, "ModifyConfig");
- PolicyNotification actual = new PolicyNotification();
- try {
- actual = mapper.readValue(result, PolicyNotification.class);
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println("actual :; "+result+"\nexp "+policy_notif);
- Assert.assertEquals(expected.hashCode(), actual.hashCode());
- }
-
- @Test
- public void sendToPolicyTest() throws Exception {
-
- PowerMockito.mockStatic(SdnrRestClient.class);
- PowerMockito.mockStatic(BeanUtil.class);
- PowerMockito.mockStatic(SdnrRestClient.class);
- PowerMockito.mockStatic(ConfigurationClient.class);
+ String result = childThreadUtils.getNotificationString(pnfName, requestId, "payloadString", alarmStart, "ModifyO1Config");
+ PolicyNotification actual = new PolicyNotification();
+ try {
+ actual = mapper.readValue(result, PolicyNotification.class);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ System.out.println("actual :; "+result+"\nexp "+policy_notif);
+ Assert.assertEquals(expected.hashCode(), actual.hashCode());
+ }
+
+ @Test
+ public void sendToPolicyTest() throws Exception {
- SdnrRestClient sdnr = PowerMockito.spy(new SdnrRestClient());
- Configuration config = Configuration.getInstance();
+ PowerMockito.mockStatic(SdnrRestClient.class);
+ PowerMockito.mockStatic(BeanUtil.class);
+ PowerMockito.mockStatic(SdnrRestClient.class);
+ PowerMockito.mockStatic(ConfigurationClient.class);
- String asyncRspBodyString = readFromFile("/AsyncRespBody.json");
- ObjectMapper mapper = new ObjectMapper();
- AsyncResponseBody async = new AsyncResponseBody();
- try {
+ SdnrRestClient sdnr = PowerMockito.spy(new SdnrRestClient());
+ Configuration config = Configuration.getInstance();
+
+ String asyncRspBodyString = readFromFile("/AsyncRespBody.json");
+ ObjectMapper mapper = new ObjectMapper();
+ AsyncResponseBody async = new AsyncResponseBody();
+ try {
async = mapper.readValue(asyncRspBodyString, AsyncResponseBody.class);
- } catch (Exception e) {
+ } catch (Exception e) {
e.printStackTrace();
- }
+ }
- PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr);
- PowerMockito.when(config.getConfigurationClient()).thenReturn(sdnr);
- PowerMockito.doReturn(3).when(sdnr, "getPci", Mockito.anyString());
- PowerMockito.doReturn("pnfName").when(sdnr, "getPnfName", Mockito.anyString());
- when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true);
- Map<String,List<CellPciPair>> pnfsMap = new HashMap<String,List<CellPciPair>>();
- CellPciPair cell1 = new CellPciPair("cell0", 1);
- CellPciPair cell2 = new CellPciPair("cell1", 2);
- CellPciPair cell3 = new CellPciPair("cell2", 3);
- List<CellPciPair> pciPairList = new ArrayList<>();
- pciPairList.add(cell1);
- pciPairList.add(cell2);
- pciPairList.add(cell3);
- pnfsMap.put("pnf1", pciPairList);
- when(policyDmaapClient.handlePolicyResponse(Mockito.anyString())).thenReturn(true);
- when(pnfUtils.getPnfs(async.getSolutions())).thenReturn(pnfsMap);
- List<String> remNeighbors = new ArrayList<>();
- remNeighbors.add("EXP006");
- Map<String,List<String>> cellRemNeighborsPair = new HashMap<>();
- cellRemNeighborsPair.put("EXP003", remNeighbors);
- List<Map<String,List<String>>> list = new ArrayList<>();
- list.add(cellRemNeighborsPair);
- Map<String, List<Map<String,List<String>>>> expected = new HashMap<>();
- expected.put("pnfName", list);
- when(pnfUtils.getPnfsForAnrSolutions(async.getSolutions().getAnrSolutions())).thenReturn(expected);
- HoDetails hoDetails = new HoDetails();
- hoDetails.setDstCellId("EXP006");
- List<HoDetails> hoDetailsList = new ArrayList<>();
- hoDetailsList.add(hoDetails);
- Either<List<HoDetails>, Integer> hoMetrics = Either.left(hoDetailsList);
- when(hoMetricsComponent.getHoMetrics(Mockito.anyString())).thenReturn(hoMetrics);
- when(hoMetricsComponent.update(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
- assertTrue(childThreadUtils2.sendToPolicy(async));
-
- }
+ PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr);
+ PowerMockito.when(config.getConfigurationClient()).thenReturn(sdnr);
+ PowerMockito.doReturn(3).when(sdnr, "getPci", Mockito.anyString());
+ PowerMockito.doReturn("pnfName").when(sdnr, "getPnfName", Mockito.anyString());
+ when(policyDmaapClient.sendNotificationToPolicy(Mockito.anyString())).thenReturn(true);
+ Map<String,List<CellPciPair>> pnfsMap = new HashMap<String,List<CellPciPair>>();
+ CellPciPair cell1 = new CellPciPair("cell0", 1);
+ CellPciPair cell2 = new CellPciPair("cell1", 2);
+ CellPciPair cell3 = new CellPciPair("cell2", 3);
+ List<CellPciPair> pciPairList = new ArrayList<>();
+ pciPairList.add(cell1);
+ pciPairList.add(cell2);
+ pciPairList.add(cell3);
+ pnfsMap.put("pnf1", pciPairList);
+ when(policyDmaapClient.handlePolicyResponse(Mockito.anyString())).thenReturn(true);
+ when(pnfUtils.getPnfs(async.getSolutions())).thenReturn(pnfsMap);
+ List<String> remNeighbors = new ArrayList<>();
+ remNeighbors.add("EXP006");
+ Map<String,List<String>> cellRemNeighborsPair = new HashMap<>();
+ cellRemNeighborsPair.put("EXP003", remNeighbors);
+ List<Map<String,List<String>>> list = new ArrayList<>();
+ list.add(cellRemNeighborsPair);
+ Map<String, List<Map<String,List<String>>>> expected = new HashMap<>();
+ expected.put("pnfName", list);
+ when(pnfUtils.getPnfsForAnrSolutions(async.getSolutions().getAnrSolutions())).thenReturn(expected);
+ HoDetails hoDetails = new HoDetails();
+ hoDetails.setDstCellId("EXP006");
+ List<HoDetails> hoDetailsList = new ArrayList<>();
+ hoDetailsList.add(hoDetails);
+ Either<List<HoDetails>, Integer> hoMetrics = Either.left(hoDetailsList);
+ when(hoMetricsComponent.getHoMetrics(Mockito.anyString())).thenReturn(hoMetrics);
+ when(hoMetricsComponent.update(Mockito.anyString(), Mockito.anyString())).thenReturn(true);
+ assertTrue(childThreadUtils2.sendToPolicy(async));
+ }
- private static String readFromFile(String file) {
- String content = new String();
- try {
+ private static String readFromFile(String file) {
+ String content = new String();
+ try {
- InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
- BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
- content = bufferedReader.readLine();
- String temp;
- while ((temp = bufferedReader.readLine()) != null) {
- content = content.concat(temp);
- }
- content = content.trim();
- bufferedReader.close();
- } catch (Exception e) {
- e.printStackTrace();
- content = null;
- }
- return content;
- }
+ InputStream is = ClusterUtilsTest.class.getResourceAsStream(file);
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
+ content = bufferedReader.readLine();
+ String temp;
+ while ((temp = bufferedReader.readLine()) != null) {
+ content = content.concat(temp);
+ }
+ content = content.trim();
+ bufferedReader.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ content = null;
+ }
+ return content;
+ }
}
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java
index 5b7050a..4d8713a 100644
--- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java
+++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java
@@ -152,6 +152,28 @@ public class CpsClientTest {
}
@Test
+ public void getRicIdTest() {
+ String responseBody = "{\"idNearRTRIC\":\"22\"}";
+ PowerMockito.mockStatic(SonHandlerRestTemplate.class);
+ PowerMockito.mockStatic(Configuration.class);
+ PowerMockito.when(Configuration.getInstance()).thenReturn(configuration);
+ PowerMockito
+ .when(SonHandlerRestTemplate.sendPostRequest(Mockito.anyString(), Mockito.anyString(),
+ Matchers.<ParameterizedTypeReference<String>>any()))
+ .thenReturn(ResponseEntity.ok(responseBody));
+ try {
+ String result = cps.getRicId("1");
+ String response = ResponseEntity.ok(responseBody).getBody();
+ JSONObject respObj = new JSONObject(response);
+ assertEquals(respObj.get("idNearRTRIC"), result);
+ } catch (CpsNotFoundException e) {
+ log.debug("CpsNotFoundException {}", e.toString());
+ }
+ }
+
+
+
+ @Test
public void getCellData() {
String responseBody = "{\"networkId\":\"netw1000\"}";
PowerMockito.mockStatic(SonHandlerRestTemplate.class);