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/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java | |
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/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java')
-rw-r--r-- | src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java | 50 |
1 files changed, 38 insertions, 12 deletions
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"); |