diff options
author | malar <malarvizhi.44@wipro.com> | 2021-08-29 17:17:21 +0000 |
---|---|---|
committer | malar <malarvizhi.44@wipro.com> | 2021-08-29 17:17:21 +0000 |
commit | afb7bc0c146474e2492d29a70fa1c82689e8e3ed (patch) | |
tree | 7e5b536066e189e51e38a5fa81adb4dbe2479389 /src/test | |
parent | d9b2a6fef81bf657eac6224dba75254db49c926b (diff) |
Implement CPS Client in SON Handler
Issue-ID: DCAEGEN2-2883
Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com>
Change-Id: Ife63f6eeb9e277c472a4773fe78345e18b753511
Diffstat (limited to 'src/test')
6 files changed, 259 insertions, 36 deletions
diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java index 83fd795..372483a 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019-2020 Wipro Limited. + * Copyright (C) 2019-2021 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,7 @@ import org.mockito.runners.MockitoJUnitRunner; import org.onap.dcaegen2.services.sonhms.child.Graph; import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.FapServiceList; import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell; @@ -130,7 +131,7 @@ public class EventHandlerTest { try { Mockito.when(clusterutilsMock.createCluster(Mockito.any())).thenReturn(cluster); - } catch (ConfigDbNotFoundException e1) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } @@ -166,7 +167,7 @@ public class EventHandlerTest { try { Mockito.when(clusterutilsMock.createCluster(Mockito.any())).thenReturn(cluster); - } catch (ConfigDbNotFoundException e1) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e1) { e1.printStackTrace(); } Assert.assertEquals(true, eventHandler.handleSdnrNotification(notification)); @@ -198,7 +199,7 @@ public class EventHandlerTest { try { Mockito.when(clusterutilsMock.findClusterMap(Mockito.any())).thenReturn(clusterMap); - } catch (ConfigDbNotFoundException e) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e) { e.printStackTrace(); } @@ -223,7 +224,7 @@ public class EventHandlerTest { Mockito.when(clusterutilsMock.findClusterMap(Mockito.any())).thenReturn(clusterMap); Mockito.when(clusterutilsMock.modifyCluster(Mockito.any(), Mockito.any())).thenReturn(graph); - } catch (ConfigDbNotFoundException e) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e) { e.printStackTrace(); } @@ -257,7 +258,7 @@ public class EventHandlerTest { try { Mockito.when(clusterutilsMock.findClusterMap(Mockito.any())).thenReturn(clusterMap); - } catch (ConfigDbNotFoundException e) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e) { e.printStackTrace(); } @@ -281,7 +282,7 @@ public class EventHandlerTest { Mockito.when(clusterutilsMock.findClusterMap(Mockito.any())).thenReturn(clusterMap); Mockito.when(clusterutilsMock.createCluster(Mockito.any())).thenReturn(graph); - } catch (ConfigDbNotFoundException e) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e) { e.printStackTrace(); } 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 5f2e5b5..8baed64 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,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019-2020 Wipro Limited. + * Copyright (C) 2019-2021 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,9 @@ import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository; import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient; import org.onap.dcaegen2.services.sonhms.entity.SonRequests; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigInterface; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.HoDetails; import org.onap.dcaegen2.services.sonhms.model.PolicyNotification; @@ -73,7 +76,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ BeanUtil.class, SdnrRestClient.class }) +@PrepareForTest({ BeanUtil.class, SdnrRestClient.class, ConfigurationClient.class }) @SpringBootTest(classes = TestChildThreadUtils.class) public class TestChildThreadUtils { @@ -100,6 +103,7 @@ public class TestChildThreadUtils { ConfigPolicy configPolicy = ConfigPolicy.getInstance(); Configuration config = Configuration.getInstance(); + config.setConfigClientType("ConfigDB"); config.setMinCollision(5); config.setMinConfusion(5); Map<String, Object> configPolicyMap = new HashMap<>(); @@ -177,21 +181,30 @@ public class TestChildThreadUtils { } @Test - public void sendToPolicyTest() throws ConfigDbNotFoundException { + public void sendToPolicyTest() throws Exception { PowerMockito.mockStatic(SdnrRestClient.class); PowerMockito.mockStatic(BeanUtil.class); + PowerMockito.mockStatic(SdnrRestClient.class); + PowerMockito.mockStatic(ConfigurationClient.class); - String asyncRspBodyString = readFromFile("/AsyncRespBody.json"); + SdnrRestClient sdnr = PowerMockito.spy(new SdnrRestClient()); + Configuration config = Configuration.getInstance(); + + String asyncRspBodyString = readFromFile("/AsyncRespBody.json"); ObjectMapper mapper = new ObjectMapper(); - AsyncResponseBody async = new AsyncResponseBody (); + AsyncResponseBody async = new AsyncResponseBody(); try { async = mapper.readValue(asyncRspBodyString, AsyncResponseBody.class); } catch (Exception e) { e.printStackTrace(); } - PowerMockito.when(SdnrRestClient.getPci(Mockito.anyString())).thenReturn(3); - PowerMockito.when(SdnrRestClient.getPnfName(Mockito.anyString())).thenReturn("pnfName"); + + PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr); + PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType())) + .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); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java index 683d4f2..e54748b 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019-2020 Wipro Limited. + * Copyright (C) 2019-2021 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,11 +43,14 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.Configuration; import org.onap.dcaegen2.services.sonhms.dao.CellInfoRepository; import org.onap.dcaegen2.services.sonhms.entity.CellInfo; import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; +import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.restclient.AnrSolutions; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; import org.onap.dcaegen2.services.sonhms.restclient.Solutions; import org.onap.dcaegen2.services.sonhms.utils.BeanUtil; @@ -64,7 +67,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({BeanUtil.class, SdnrRestClient.class }) +@PrepareForTest({BeanUtil.class, SdnrRestClient.class, ConfigurationClient.class }) @SpringBootTest(classes = PnfUtils.class) public class TestPnfUtils { @@ -83,8 +86,9 @@ public class TestPnfUtils { @BeforeClass public static void setup() { - - + + Configuration config = Configuration.getInstance(); + config.setConfigClientType("ConfigDB"); String solutionsString=readFromFile("/solutions.json"); String anrSolutionsString = readFromFile("/anrSolutions.json"); ObjectMapper mapper = new ObjectMapper(); @@ -118,6 +122,11 @@ public class TestPnfUtils { PowerMockito.mockStatic(BeanUtil.class); PowerMockito.mockStatic(SdnrRestClient.class); + PowerMockito.mockStatic(ConfigurationClient.class); + + SdnrRestClient sdnr = PowerMockito.spy(new SdnrRestClient()); + Configuration config = Configuration.getInstance(); + PowerMockito.when(BeanUtil.getBean(CellInfoRepository.class)) .thenReturn(cellInfoRepositoryMock); @@ -126,18 +135,22 @@ public class TestPnfUtils { Mockito.when(cellInfoRepositoryMock.findById(cellId)) .thenReturn(cellInfoNull); try { - PowerMockito.when(SdnrRestClient.getPnfName(cellId)) - .thenReturn(pnfName); + PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr); + PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType())) + .thenReturn(sdnr); + PowerMockito.doReturn(pnfName).when(sdnr, "getPnfName", Mockito.anyString()); PowerMockito.when(cellInfoRepositoryMock.save(new CellInfo(cellId, pnfName))).thenReturn(new CellInfo()); } catch (ConfigDbNotFoundException e) { e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); } - pnfs.put(pnfName, cellpciPairList2); + pnfs.put(pnfName, cellpciPairList2); pnfs.put("ncserver1", cellpciPairList1); System.out.println(solutions); try { assertEquals(pnfs,pnfUtils.getPnfs(solutions)); - } catch (ConfigDbNotFoundException e) { + } catch (ConfigDbNotFoundException | CpsNotFoundException e) { log.debug("exception in stateOof test {}", e); e.printStackTrace(); } @@ -147,14 +160,27 @@ public class TestPnfUtils { public void testGetPnfsForAnrSolutions() { Map<String, List<Map<String,List<String>>>> actual = null ; Map<String, List<Map<String,List<String>>>> expected = new HashMap<>(); + + PowerMockito.mockStatic(SdnrRestClient.class); + PowerMockito.mockStatic(ConfigurationClient.class); + + SdnrRestClient sdnr = PowerMockito.spy(new SdnrRestClient()); + Configuration config = Configuration.getInstance(); + try { - PowerMockito.mockStatic(SdnrRestClient.class); - PowerMockito.when(SdnrRestClient.getPnfName(Mockito.anyString())).thenReturn("ncServer1"); + PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr); + PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType())) + .thenReturn(sdnr); + PowerMockito.doReturn("ncServer1").when(sdnr, "getPnfName", Mockito.anyString()); actual = pnfUtils.getPnfsForAnrSolutions(anrSolutions); } catch (ConfigDbNotFoundException e) { e.printStackTrace(); - } - List<String> remNeighbors1 = new ArrayList<>(); + } catch (CpsNotFoundException e) { + e.printStackTrace(); + } catch (Exception e) { + e.printStackTrace(); + } + List<String> remNeighbors1 = new ArrayList<>(); List<String> remNeighbors2 = new ArrayList<>(); remNeighbors1.add("cell2"); remNeighbors1.add("cell3"); 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 new file mode 100644 index 0000000..a531b4d --- /dev/null +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java @@ -0,0 +1,171 @@ +/******************************************************************************* + * ============LICENSE_START======================================================= + * son-handler + * ================================================================================ + * Copyright (C) 2021 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.restclient; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException; +import org.onap.dcaegen2.services.sonhms.model.CellPciPair; +import org.onap.dcaegen2.services.sonhms.utils.SonHandlerRestTemplate; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.powermock.modules.junit4.PowerMockRunnerDelegate; +import org.slf4j.Logger; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(PowerMockRunner.class) +@PowerMockIgnore({ "com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*" }) +@PowerMockRunnerDelegate(SpringRunner.class) +@PrepareForTest({ SonHandlerRestTemplate.class, Configuration.class }) +@SpringBootTest(classes = CpsClientTest.class) +public class CpsClientTest { + + CpsClient cps = new CpsClient(); + Configuration configuration = Configuration.getInstance(); + private static final Logger log = org.slf4j.LoggerFactory.getLogger(CpsClient.class); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void getNbrListTest() { + + String responseBody = "[{\"idNRCellRelation\":\"cell1\",\"attributes\":{\"nRTCI\":\"cell1\",\"nRPCI\":1,\"isHOAllowed\":true}},{\"idNRCellRelation\":\"cell2\",\"attributes\":{\"nRTCI\":\"cell2\",\"nRPCI\":2,\"isHOAllowed\":true}}]"; + + System.out.println(responseBody); + 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 { + List<CellPciPair> result = cps.getNbrList("1"); + List<CellPciPair> nbrList = new ArrayList<>(); + String response = ResponseEntity.ok(responseBody).getBody(); + System.out.println("response" + response); + JSONArray nbrListObj = new JSONArray(response); + System.out.println(nbrListObj); + for (int i = 0; i < nbrListObj.length(); i++) { + JSONObject cellObj = nbrListObj.getJSONObject(i); + JSONObject obj = cellObj.getJSONObject("attributes"); + if (obj.getBoolean("isHOAllowed")) { + CellPciPair cell = new CellPciPair(obj.getString("nRTCI"), obj.getInt("nRPCI")); + nbrList.add(cell); + } + } + assertEquals(nbrList, result); + } catch (Exception e) { + log.debug("CpsNotFoundException {}", e.toString()); + ; + } + + } + + @Test + public void getPciTest() { + + String responseBody = "{\n" + " \"attribute-name\": \"string\",\n" + " \"value\": 0\n" + "}"; + 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 { + int result = cps.getPci("1"); + String response = ResponseEntity.ok(responseBody).getBody(); + JSONObject respObj = new JSONObject(response); + assertEquals(respObj.getInt("value"), result); + } catch (CpsNotFoundException e) { + log.debug("CpsNotFoundException {}", e.toString()); + ; + } + + } + + @Test + public void getPnfNameTest() { + + String responseBody = "{\n" + " \"attribute-name\": \"string\",\n" + " \"value\": \"string\"\n" + "}"; + 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.getPnfName("1"); + String response = ResponseEntity.ok(responseBody).getBody(); + JSONObject respObj = new JSONObject(response); + assertEquals(respObj.getString("value"), result); + } catch (CpsNotFoundException e) { + log.debug("CpsNotFoundException {}", e.toString()); + ; + } + } + + @Test + public void getCellData() { + String responseBody = "{\"networkId\":\"netw1000\"}"; + 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 { + JSONObject result = cps.getCellData("1"); + String response = ResponseEntity.ok(responseBody).getBody(); + JSONObject respObj = new JSONObject(response); + assertEquals(respObj.get("networkId"), result.get("networkId")); + } catch (CpsNotFoundException e) { + log.debug("CpsNotFoundException {}", e.toString()); + + } + + } + +}
\ No newline at end of file diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java index 6ce12df..28d9b8e 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019-2020 Wipro Limited. + * Copyright (C) 2019-2021 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,8 +55,8 @@ import org.springframework.test.context.junit4.SpringRunner; @PrepareForTest({ SonHandlerRestTemplate.class,Configuration.class }) @SpringBootTest(classes = SdnrRestClientTest.class) public class SdnrRestClientTest { - - + + SdnrRestClient sdnr = new SdnrRestClient(); Configuration configuration = Configuration.getInstance(); private static final Logger log = org.slf4j.LoggerFactory.getLogger(SdnrRestClient.class); @@ -85,7 +85,7 @@ public class SdnrRestClientTest { PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) .thenReturn(ResponseEntity.ok(responseBody)); try { - List<CellPciPair> result=SdnrRestClient.getNbrList("1"); + List<CellPciPair> result=sdnr.getNbrList("1"); List<CellPciPair> nbrList = new ArrayList<>(); String response=ResponseEntity.ok(responseBody).getBody(); JSONObject responseJson = new JSONObject(response); @@ -116,7 +116,7 @@ public class SdnrRestClientTest { PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) .thenReturn(ResponseEntity.ok(responseBody)); try { - int result=SdnrRestClient.getPci("1"); + int result=sdnr.getPci("1"); String response=ResponseEntity.ok(responseBody).getBody(); JSONObject respObj = new JSONObject(response); assertEquals(respObj.getInt("value"),result); @@ -138,7 +138,7 @@ public class SdnrRestClientTest { PowerMockito.when(SonHandlerRestTemplate.sendGetRequest(Mockito.anyString(),Matchers.<ParameterizedTypeReference<String>>any())) .thenReturn(ResponseEntity.ok(responseBody)); try { - String result=SdnrRestClient.getPnfName("1"); + String result=sdnr.getPnfName("1"); String response=ResponseEntity.ok(responseBody).getBody(); JSONObject respObj = new JSONObject(response); assertEquals(respObj.getString("value"),result); diff --git a/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java index 53539c5..32d2a47 100644 --- a/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java +++ b/src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * son-handler * ================================================================================ - * Copyright (C) 2019-2020 Wipro Limited. + * Copyright (C) 2019-2021 Wipro Limited. * ============================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +55,9 @@ import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException; import org.onap.dcaegen2.services.sonhms.model.CellPciPair; import org.onap.dcaegen2.services.sonhms.model.FapServiceList; import org.onap.dcaegen2.services.sonhms.model.Notification; +import org.onap.dcaegen2.services.sonhms.Configuration; +import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException; +import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient; import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; @@ -67,7 +70,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(PowerMockRunner.class) @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PowerMockRunnerDelegate(SpringRunner.class) -@PrepareForTest({ SdnrRestClient.class, BeanUtil.class }) +@PrepareForTest({ SdnrRestClient.class, BeanUtil.class, ConfigurationClient.class }) @SpringBootTest(classes = ClusterUtils.class) public class ClusterUtilsTest { @@ -86,6 +89,8 @@ public class ClusterUtilsTest { @BeforeClass public static void setup() { + Configuration config = Configuration.getInstance(); + config.setConfigClientType("ConfigDB"); notification1 = new Notification(); notification2 = new Notification(); clusterDetailsForGetClusterDetailsFromClusterIdTest = new ArrayList<ClusterDetails>(); @@ -150,7 +155,7 @@ public class ClusterUtilsTest { } @Test - public void createClusterTest() throws ConfigDbNotFoundException { + public void createClusterTest() throws Exception { Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<CellPciPair, ArrayList<CellPciPair>>(); @@ -161,8 +166,15 @@ public class ClusterUtilsTest { nbrList.add(new CellPciPair("44", 3)); PowerMockito.mockStatic(SdnrRestClient.class); + PowerMockito.mockStatic(ConfigurationClient.class); - PowerMockito.when(SdnrRestClient.getNbrList(Mockito.anyString())).thenReturn(nbrList); + SdnrRestClient sdnr = PowerMockito.spy(new SdnrRestClient()); + Configuration config = Configuration.getInstance(); + + PowerMockito.whenNew(SdnrRestClient.class).withAnyArguments().thenReturn(sdnr); + PowerMockito.when(ConfigurationClient.configClient(config.getConfigClientType())) + .thenReturn(sdnr); + PowerMockito.doReturn(nbrList).when(sdnr, "getNbrList", Mockito.anyString()); clusterMap.put(new CellPciPair("45", 310), (ArrayList<CellPciPair>) firstNbrList); |