summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormalar <malarvizhi.44@wipro.com>2021-08-29 17:17:21 +0000
committermalar <malarvizhi.44@wipro.com>2021-08-29 17:17:21 +0000
commitafb7bc0c146474e2492d29a70fa1c82689e8e3ed (patch)
tree7e5b536066e189e51e38a5fa81adb4dbe2479389
parentd9b2a6fef81bf657eac6224dba75254db49c926b (diff)
Implement CPS Client in SON Handler
Issue-ID: DCAEGEN2-2883 Signed-off-by: Malarvizhi Paramasivam <malarvizhi.44@wipro.com> Change-Id: Ife63f6eeb9e277c472a4773fe78345e18b753511
-rw-r--r--Changelog.md1
-rw-r--r--dpo/spec/sonhandler-componentspec.json64
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java100
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java19
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java8
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java8
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java14
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java41
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java73
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java52
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java149
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java27
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java18
-rw-r--r--src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java3
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/EventHandlerTest.java15
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/TestChildThreadUtils.java27
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/child/TestPnfUtils.java50
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClientTest.java171
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClientTest.java12
-rw-r--r--src/test/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtilsTest.java20
20 files changed, 797 insertions, 75 deletions
diff --git a/Changelog.md b/Changelog.md
index 9f695ba..d2e3f47 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [DCAEGEN2-2711](https://jira.onap.org/browse/DCAEGEN2-2711) - Update sdk version to load policies from a file mounted by policy sidecar container
- [DCAEGEN2-2809](https://jira.onap.org/browse/DCAEGEN2-2809) - Remove security vulnerabilities
- [DCAEGEN2-2884](https://jira.onap.org/browse/DCAEGEN2-2884) - Update FM message spec to VES 7.2
+ - [DCAEGEN2-2883](https://jira.onap.org/browse/DCAEGEN2-2883) - Implement CPS Client in SON Handler
## [2.1.3] - 03/02/2021
- [DCAEGEN2-2599](https://jira.onap.org/browse/DCAEGEN2-2599) - Remove security vulnerabilities
diff --git a/dpo/spec/sonhandler-componentspec.json b/dpo/spec/sonhandler-componentspec.json
index 2d23fb8..8899dfc 100644
--- a/dpo/spec/sonhandler-componentspec.json
+++ b/dpo/spec/sonhandler-componentspec.json
@@ -141,6 +141,22 @@
"designer_editable": false
},
{
+ "name": "cps.username",
+ "value": "cpsuser",
+ "description": "cps configuration",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
+ "name": "cps.password",
+ "value": "cpsr0cks!",
+ "description": "cps configuration",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
"name": "sonhandler.optimizers",
"value": [
"pci"
@@ -191,6 +207,14 @@
"designer_editable": false
},
{
+ "name": "sonhandler.clientType",
+ "value": "ConfigDB",
+ "description": "Client type",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
"name": "sonhandler.dmaap.servers",
"value": [
"message-router:3904"
@@ -241,6 +265,46 @@
"designer_editable": false
},
{
+ "name": "sonhandler.cps.service.url",
+ "value": "http://cps-tbdmt:8080",
+ "description": "Cps service url",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
+ "name": "sonhandler.get.cell.data.url",
+ "value": "execute/cps-ran-schema/get-cell-data",
+ "description": "Cps get cell data url",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
+ "name": "sonhandler.get.nbr.list.url",
+ "value": "execute/cps-ran-schema/get-nbr-list",
+ "description": "Cps get nbr list url",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
+ "name": "sonhandler.get.pci.url",
+ "value": "execute/cps-ran-schema/get-pci",
+ "description": "Cps get pci url",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
+ "name": "sonhandler.get.pnf.url",
+ "value": "execute/cps-ran-schema/get-pnf",
+ "description": "Cps get pnf url",
+ "sourced_at_deployment": false,
+ "policy_editable": false,
+ "designer_editable": false
+ },
+ {
"name": "sonhandler.oof.service",
"value": "http://oof:8080",
"description": "oof service url",
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java
index 563491c..8b05f8c 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/Configuration.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.
@@ -45,6 +45,11 @@ public class Configuration {
private String pgPassword;
private List<String> dmaapServers;
private String configDbService;
+ private String cpsServiceUrl;
+ private String getCellDataUrl;
+ private String getNbrListUrl;
+ private String getPciUrl;
+ private String getPnfUrl;
private String oofService;
private String oofEndpoint;
private String cg;
@@ -74,6 +79,35 @@ public class Configuration {
private int policyNegativeAckThreshold;
private long policyFixedPciTimeInterval;
private String nfNamingCode;
+ private String ConfigClientType;
+ private String CpsUsername;
+ private String CpsPassword;
+
+ public String getCpsUsername()
+ {
+ return CpsUsername;
+ }
+ public void setCpsUsername(String CpsUsername)
+ {
+ this.CpsUsername = CpsUsername;
+ }
+ public String getCpsPassword()
+ {
+ return CpsPassword;
+ }
+ public void setCpsPassword(String CpsPassword)
+ {
+ this.CpsPassword = CpsPassword;
+ }
+
+ public String getConfigClientType()
+ {
+ return ConfigClientType;
+ }
+ public void setConfigClientType(String ConfigClientType)
+ {
+ this.ConfigClientType = ConfigClientType;
+ }
public int getPoorCountThreshold() {
return poorCountThreshold;
@@ -377,11 +411,64 @@ public class Configuration {
this.nfNamingCode = nfNamingCode;
}
- @Override
+ public static Logger getLog() {
+ return log;
+ }
+
+ public static void setLog(Logger log) {
+ Configuration.log = log;
+ }
+
+ public String getCpsServiceUrl() {
+ return cpsServiceUrl;
+ }
+
+ public void setCpsServiceUrl(String cpsServiceUrl) {
+ this.cpsServiceUrl = cpsServiceUrl;
+ }
+
+ public String getGetCellDataUrl() {
+ return getCellDataUrl;
+ }
+
+ public void setGetCellDataUrl(String getCellDataUrl) {
+ this.getCellDataUrl = getCellDataUrl;
+ }
+
+ public String getGetNbrListUrl() {
+ return getNbrListUrl;
+ }
+
+ public void setGetNbrListUrl(String getNbrListUrl) {
+ this.getNbrListUrl = getNbrListUrl;
+ }
+
+ public String getGetPciUrl() {
+ return getPciUrl;
+ }
+
+ public void setGetPciUrl(String getPciUrl) {
+ this.getPciUrl = getPciUrl;
+ }
+
+ public String getGetPnfUrl() {
+ return getPnfUrl;
+ }
+
+ public void setGetPnfUrl(String getPnfUrl) {
+ this.getPnfUrl = getPnfUrl;
+ }
+
+ public static void setInstance(Configuration instance) {
+ Configuration.instance = instance;
+ }
+
+ @Override
public String toString() {
return "Configuration [pgHost=" + pgHost + ", pgPort=" + pgPort + ", pgUsername=" + pgUsername + ", pgPassword="
+ pgPassword + ", dmaapServers=" + dmaapServers + ", configDbService=" + configDbService
- + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
+ + ", cpsServiceUrl=" + cpsServiceUrl + ", CpsUsername=" + CpsUsername + ",CpsPassword=" + CpsPassword + ",ConfigClientType=" + ConfigClientType + ", getCellDataUrl=" + getCellDataUrl + ", getNbrListUrl="
+ + getNbrListUrl + ", getPciUrl=" + getPciUrl + ", getPnfUrl=" + getPnfUrl + ", oofService=" + oofService + ", oofEndpoint=" + oofEndpoint + ", cg=" + cg + ", cid=" + cid
+ ", pollingInterval=" + pollingInterval + ", pollingTimeout=" + pollingTimeout + ", minCollision="
+ minCollision + ", minConfusion=" + minConfusion + ", sourceId=" + sourceId + ", callbackUrl="
+ callbackUrl + ", pciOptimizer=" + pciOptimizer + ", pciAnrOptimizer=" + pciAnrOptimizer
@@ -410,6 +497,8 @@ public class Configuration {
JsonObject publishes = jsonObject.getAsJsonObject("streams_publishes");
streamsPublishes = new Gson().fromJson(publishes, mapType);
+ CpsUsername = jsonObject.get("cps.username").getAsString();
+ CpsPassword = jsonObject.get("cps.password").getAsString();
pgPort = jsonObject.get("postgres.port").getAsInt();
pollingInterval = jsonObject.get("sonhandler.pollingInterval").getAsInt();
pgPassword = jsonObject.get("postgres.password").getAsString();
@@ -451,6 +540,11 @@ public class Configuration {
policyNegativeAckThreshold = jsonObject.get("sonhandler.policyNegativeAckThreshold").getAsInt();
policyFixedPciTimeInterval = jsonObject.get("sonhandler.policyFixedPciTimeInterval").getAsLong();
nfNamingCode = jsonObject.get("sonhandler.nfNamingCode").getAsString();
+ cpsServiceUrl = jsonObject.get("cps.service.url").getAsString();
+ getCellDataUrl = jsonObject.get("cps.get.celldata").getAsString();
+ getPnfUrl = jsonObject.get("cps.get.pnf.url").getAsString();
+ getPciUrl = jsonObject.get("cps.get.pci.url").getAsString();
+ ConfigClientType = jsonObject.get("sonhandler.clientType").getAsString();
log.info("configuration from CBS {}", this);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java
index 325de6f..64d8593 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/EventHandler.java
@@ -42,6 +42,7 @@ import org.onap.dcaegen2.services.sonhms.entity.ClusterDetails;
import org.onap.dcaegen2.services.sonhms.exceptions.ConfigDbNotFoundException;
import org.onap.dcaegen2.services.sonhms.model.CellPciPair;
import org.onap.dcaegen2.services.sonhms.model.ClusterMap;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
import org.onap.dcaegen2.services.sonhms.model.FapServiceList;
import org.onap.dcaegen2.services.sonhms.model.LteNeighborListInUseLteCell;
import org.onap.dcaegen2.services.sonhms.model.Notification;
@@ -110,8 +111,8 @@ public class EventHandler {
&& !faultNotificationtoClusterMapping.getCellsinCluster().isEmpty()) {
try {
handleMatchedFmCells(faultNotificationtoClusterMapping, clusterDetails);
- } catch (ConfigDbNotFoundException e) {
- log.error("Config DB Exception {}", e);
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
+ log.error("Config DB Exception {} or Cps Exception {} ", e);
}
}
// unmatched new cells
@@ -128,7 +129,7 @@ public class EventHandler {
*
*/
private void handleMatchedFmCells(FaultNotificationtoClusterMapping faultNotificationtoClusterMapping,
- List<ClusterDetails> clusterDetails) throws ConfigDbNotFoundException {
+ List<ClusterDetails> clusterDetails) throws ConfigDbNotFoundException, CpsNotFoundException {
Map<String, String> cellsinCluster = faultNotificationtoClusterMapping.getCellsinCluster();
log.info("Handling Matching cells for FM notification");
@@ -184,7 +185,7 @@ public class EventHandler {
cluster.setCollisionConfusionMap(collisionConfusionMap);
newClusters.add(cluster);
- } catch (ConfigDbNotFoundException e) {
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
log.error("Error connecting with configDB {}", e);
}
}
@@ -198,8 +199,8 @@ public class EventHandler {
Map<String, ArrayList<Integer>> collisionConfusionMap = cluster.getCollisionConfusionMap();
collisionConfusionMap.put(cellId, collisionConfusionCount);
cluster.setCollisionConfusionMap(collisionConfusionMap);
- } catch (ConfigDbNotFoundException e) {
- log.error("Config DB not found {}", e);
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
+ log.error("Config DB or CPS not found {}", e);
}
newClusters.remove(cluster);
newClusters.add(modifiedCluster);
@@ -244,7 +245,7 @@ public class EventHandler {
}
- private void handleUnMatchingCells(List<FapServiceList> newCells) throws ConfigDbNotFoundException {
+ private void handleUnMatchingCells(List<FapServiceList> newCells) throws ConfigDbNotFoundException, CpsNotFoundException {
log.info("handling unmatched cells");
@@ -261,8 +262,8 @@ public class EventHandler {
.getLteNeighborListInUseLteCell().get(0).getPlmnid());
cluster.setCollisionConfusionMap(new HashMap<>());
newClusters.add(cluster);
- } catch (ConfigDbNotFoundException e) {
- log.error("Error connecting with configDB {}", e);
+ } catch (ConfigDbNotFoundException | CpsNotFoundException e) {
+ log.error("Error connecting with configDB {} or CPS {}", e);
}
}
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java
index fd2de30..3964927 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThread.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.
@@ -61,8 +61,8 @@ import org.onap.dcaegen2.services.sonhms.model.Flag;
import org.onap.dcaegen2.services.sonhms.model.HoDetails;
import org.onap.dcaegen2.services.sonhms.model.ThreadId;
import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody;
+import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
import org.onap.dcaegen2.services.sonhms.restclient.PciSolutions;
-import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
import org.onap.dcaegen2.services.sonhms.utils.ClusterUtils;
import org.onap.dcaegen2.services.sonhms.utils.DmaapUtils;
@@ -176,7 +176,7 @@ public class ChildThread implements Runnable {
FixedPciCellsRepository fixedPciCellsRepository = BeanUtil.getBean(FixedPciCellsRepository.class);
List<String> fixedPciCells = fixedPciCellsRepository.getFixedPciCells();
String cellId = fixedPciCells.get(0);
- JSONObject cellData = SdnrRestClient.getCellData(cellId);
+ JSONObject cellData = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getCellData(cellId);
networkId = cellData.getJSONObject("Cell").getString("networkId");
}
@@ -320,7 +320,7 @@ public class ChildThread implements Runnable {
for (PciSolutions pcisolutions : pciSolutionsList) {
String cellId = pcisolutions.getCellId();
- int oldPci = SdnrRestClient.getPci(cellId);
+ int oldPci = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId);
int newPci = pcisolutions.getPci();
PciUpdate pciUpdate = new PciUpdate();
pciUpdate.setCellId(cellId);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java
index d04e6cb..5876d2b 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/ChildThreadUtils.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.
@@ -34,6 +34,7 @@ import java.util.UUID;
import org.onap.dcaegen2.services.sonhms.ConfigPolicy;
import org.onap.dcaegen2.services.sonhms.Configuration;
+import org.onap.dcaegen2.services.sonhms.exceptions.CpsNotFoundException;
import org.onap.dcaegen2.services.sonhms.HoMetricsComponent;
import org.onap.dcaegen2.services.sonhms.dao.SonRequestsRepository;
import org.onap.dcaegen2.services.sonhms.dmaap.PolicyDmaapClient;
@@ -55,6 +56,7 @@ import org.onap.dcaegen2.services.sonhms.model.Ran;
import org.onap.dcaegen2.services.sonhms.model.X0005b9Lte;
import org.onap.dcaegen2.services.sonhms.restclient.AsyncResponseBody;
import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
+import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
import org.slf4j.Logger;
@@ -162,7 +164,7 @@ public class ChildThreadUtils {
* @throws ConfigDbNotFoundException
* when config db is unreachable
*/
- public Boolean sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException {
+ public Boolean sendToPolicy(AsyncResponseBody async) throws ConfigDbNotFoundException, CpsNotFoundException {
if (log.isDebugEnabled()) {
log.debug(async.toString());
@@ -224,7 +226,7 @@ public class ChildThreadUtils {
lteCell.setBlacklisted("true");
lteCell.setPlmnId(solutions.getNetworkId());
lteCell.setCid(removeableNeighbor);
- int pci = SdnrRestClient.getPci(cellId);
+ int pci = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId);
lteCell.setPhyCellId(pci);
lteCell.setPnfName(pnfName);
lteCellList.add(lteCell);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java
index 66f8221..1787b3f 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/child/PnfUtils.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019 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.
@@ -27,12 +27,16 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
+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.PciSolutions;
+import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
+import org.onap.dcaegen2.services.sonhms.restclient.CpsClient;
import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
import org.onap.dcaegen2.services.sonhms.restclient.Solutions;
import org.onap.dcaegen2.services.sonhms.utils.BeanUtil;
@@ -46,7 +50,7 @@ public class PnfUtils {
* get pnfs.
*
*/
- public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException {
+ public Map<String, List<CellPciPair>> getPnfs(Solutions solutions) throws ConfigDbNotFoundException, CpsNotFoundException {
Map<String, List<CellPciPair>> pnfs = new HashMap<>();
List<PciSolutions> pciSolutions = solutions.getPciSolutions();
@@ -60,7 +64,7 @@ public class PnfUtils {
if (cellInfo.isPresent()) {
pnfName = cellInfo.get().getPnfName();
} else {
- pnfName = SdnrRestClient.getPnfName(cellId);
+ pnfName = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPnfName(cellId);
cellInfoRepository.save(new CellInfo(cellId, pnfName));
}
if (pnfs.containsKey(pnfName)) {
@@ -80,14 +84,14 @@ public class PnfUtils {
*
*/
public Map<String, List<Map<String, List<String>>>> getPnfsForAnrSolutions(List<AnrSolutions> anrSolutions)
- throws ConfigDbNotFoundException {
+ throws ConfigDbNotFoundException, CpsNotFoundException {
Map<String, List<Map<String, List<String>>>> anrPnfs = new HashMap<>();
List<String> removeableNeighbors;
for (AnrSolutions anrSolution : anrSolutions) {
String cellId = anrSolution.getCellId();
- String pnfName = SdnrRestClient.getPnfName(cellId);
+ String pnfName = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPnfName(cellId);
removeableNeighbors = anrSolution.getRemoveableNeighbors();
Map<String, List<String>> cellRemNeighborsPair = new HashMap<>();
cellRemNeighborsPair.put(cellId, removeableNeighbors);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java
new file mode 100644
index 0000000..f62c9ba
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/exceptions/CpsNotFoundException.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * ============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.exceptions;
+
+/**
+ * Exception class for CPS when CPS client is not found
+ * and information cannot be retrieved
+ *
+ * @see org.onap.dcaegen2.services.sonhms.restclient.CpsClient
+ */
+
+public class CpsNotFoundException extends Exception {
+
+ /**
+ * serial version.
+ */
+ private static final long serialVersionUID = 1L;
+
+ public CpsNotFoundException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java
new file mode 100644
index 0000000..ff34cbf
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigInterface.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * ============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 org.json.JSONObject;
+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 java.util.List;
+
+/**
+ * An abstract base class which contains the methods for CpsClient and SdnrRestClient classes
+ *
+ * @see CpsClient,SdnrRestClient
+ */
+
+public abstract class ConfigInterface
+{
+ /**
+ * Abstract method to get neighbour list from SDNR or CPS based on the client
+ * mentioned in configuration.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract List<CellPciPair> getNbrList(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+
+ /**
+ * Abstract method to get PCI from SDNR or CPS based on the client mentioned.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract int getPci(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+
+ /**
+ * Abstract method to get PNF name from SDNR or CPS based on the client mentioned.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException
+ * when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract String getPnfName(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+
+ /**
+ * Abstract method to get CellData name from SDNR or CPS based on the client mentioned.
+ *
+ * @throws ConfigDbNotFoundException,CpsNotFoundException
+ * when request to configDB or CPS fails
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+ public abstract JSONObject getCellData(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException;
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java
new file mode 100644
index 0000000..3430469
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/ConfigurationClient.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ * ============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;
+
+/**
+ * Class with method to get the Client type depending on the
+ * configuration client specified.
+ *
+ * @see org.onap.dcaegen2.services.sonhms.Configuration
+ */
+
+public class ConfigurationClient
+{
+ /**
+ * Method to get the Client type.
+ *
+ * @param config_name client name(CPS or ConfigDB)
+ * @return configuration client type
+ *
+ */
+ public static ConfigInterface configClient(String config_name)
+ {
+ if (config_name == null || config_name.isEmpty())
+ return null;
+ if ("ConfigDB".equals(config_name)) {
+ return new SdnrRestClient();
+ }
+ else if ("CPS".equals(config_name)) {
+ return new CpsClient();
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java
new file mode 100644
index 0000000..20b95c7
--- /dev/null
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/CpsClient.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * ============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 java.util.ArrayList;
+import java.util.List;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * A subclass which contains the methods
+ * to get required information from the CPS Client
+ *
+ */
+
+public class CpsClient extends ConfigInterface {
+
+ private static Logger log = LoggerFactory.getLogger(CpsClient.class);
+
+ public CpsClient() {
+
+ }
+
+ /**
+ * Method to get neighbour list from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public List<CellPciPair> getNbrList(String cellId) throws CpsNotFoundException {
+
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetNbrListUrl();
+ JSONObject inputparam = new JSONObject();
+ JSONObject reqbody = new JSONObject();
+ inputparam.put("cellId", cellId);
+ reqbody.put("inputParameters", inputparam);
+ log.debug("request url: {}", requestUrl);
+ String response = sendRequest(requestUrl, reqbody);
+ List<CellPciPair> nbrList = new ArrayList<>();
+
+ JSONArray nbrListObj = new JSONArray(response);
+ 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);
+ }
+ }
+
+ return nbrList;
+ }
+
+ /**
+ * Method to get PCI from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public int getPci(String cellId) throws CpsNotFoundException {
+
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetPciUrl();
+ JSONObject inputparam = new JSONObject();
+ JSONObject reqbody = new JSONObject();
+ inputparam.put("cellId", cellId);
+ reqbody.put("inputParameters", inputparam);
+ String response = sendRequest(requestUrl, reqbody);
+ JSONObject respObj = new JSONObject(response);
+ return respObj.getInt("value");
+ }
+
+ /**
+ * Method to get PNF name from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public String getPnfName(String cellId) throws CpsNotFoundException {
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetPnfUrl();
+ JSONObject inputparam = new JSONObject();
+ JSONObject reqbody = new JSONObject();
+ inputparam.put("cellId", cellId);
+ reqbody.put("inputParameters", inputparam);
+ String response = sendRequest(requestUrl, reqbody);
+ JSONObject responseObject = new JSONObject(response);
+ return responseObject.getString("value");
+ }
+
+ /**
+ * Method to get CellData name from CPS.
+ *
+ * @throws CpsNotFoundException when request to CPS fails
+ */
+ @Override
+ public JSONObject getCellData(String cellId) throws CpsNotFoundException {
+
+ Configuration configuration = Configuration.getInstance();
+ String requestUrl = configuration.getCpsServiceUrl() + "/" + configuration.getGetCellDataUrl();
+ JSONObject inputparam = new JSONObject();
+ JSONObject reqbody = new JSONObject();
+ inputparam.put("cellId", cellId);
+ reqbody.put("inputParameters", inputparam);
+ String response = sendRequest(requestUrl, reqbody);
+ JSONObject responseObject = new JSONObject(response);
+ return responseObject;
+ }
+
+ private String sendRequest(String url, JSONObject reqbody) throws CpsNotFoundException {
+ ResponseEntity<String> response = SonHandlerRestTemplate.sendPostRequest(url, reqbody.toString(),
+ new ParameterizedTypeReference<String>() {
+ });
+ if (response == null) {
+ throw new CpsNotFoundException("Cannot reach Config DB");
+ }
+ return response.getBody();
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java
index a390bbe..9a05b88 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/restclient/SdnrRestClient.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.
@@ -37,12 +37,18 @@ import org.slf4j.LoggerFactory;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.ResponseEntity;
-public class SdnrRestClient {
+/**
+ * A subclass which contains the methods
+ * to get required information from the SDNR Client
+ *
+ */
+
+public class SdnrRestClient extends ConfigInterface {
private static final String DATETIMEFORMAT = "yyyy-MM-dd HH:mm:ss";
private static Logger log = LoggerFactory.getLogger(SdnrRestClient.class);
- private SdnrRestClient() {
+ public SdnrRestClient() {
}
@@ -52,7 +58,8 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static List<CellPciPair> getNbrList(String cellId) throws ConfigDbNotFoundException {
+ @Override
+ public List<CellPciPair> getNbrList(String cellId) throws ConfigDbNotFoundException {
Configuration configuration = Configuration.getInstance();
String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis()));
String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getNbrList" + "/" + cellId
@@ -79,7 +86,9 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static int getPci(String cellId) throws ConfigDbNotFoundException {
+
+ @Override
+ public int getPci(String cellId) throws ConfigDbNotFoundException {
Configuration configuration = Configuration.getInstance();
String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis()));
String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPCI" + "/" + cellId + "/"
@@ -95,7 +104,9 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static String getPnfName(String cellId) throws ConfigDbNotFoundException {
+
+ @Override
+ public String getPnfName(String cellId) throws ConfigDbNotFoundException {
Configuration configuration = Configuration.getInstance();
String ts = new SimpleDateFormat(DATETIMEFORMAT).format(new Time(System.currentTimeMillis()));
String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getPnfId" + "/" + cellId + "/"
@@ -111,7 +122,9 @@ public class SdnrRestClient {
* @throws ConfigDbNotFoundException
* when request to configDB fails
*/
- public static JSONObject getCellData(String cellId) throws ConfigDbNotFoundException {
+
+ @Override
+ public JSONObject getCellData(String cellId) throws ConfigDbNotFoundException {
Configuration configuration = Configuration.getInstance();
String requestUrl = configuration.getConfigDbService() + "/api/sdnc-config-db/v3/getCell" + "/" + cellId;
String response = sendRequest(requestUrl);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java
index 7228f78..7198fce 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/ClusterUtils.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019 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.
@@ -33,16 +33,20 @@ import java.util.Set;
import java.util.UUID;
import org.onap.dcaegen2.services.sonhms.ClusterDetailsComponent;
+import org.onap.dcaegen2.services.sonhms.Configuration;
import org.onap.dcaegen2.services.sonhms.FaultNotificationtoClusterMapping;
import org.onap.dcaegen2.services.sonhms.NotificationToClusterMapping;
import org.onap.dcaegen2.services.sonhms.child.Graph;
import org.onap.dcaegen2.services.sonhms.dao.ClusterDetailsRepository;
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;
import org.onap.dcaegen2.services.sonhms.model.Notification;
+import org.onap.dcaegen2.services.sonhms.restclient.ConfigurationClient;
+import org.onap.dcaegen2.services.sonhms.restclient.CpsClient;
import org.onap.dcaegen2.services.sonhms.restclient.SdnrRestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -226,8 +230,8 @@ public class ClusterUtils {
/**
* Create cluster.
*/
- public Graph createCluster(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) throws ConfigDbNotFoundException {
-
+ public Graph createCluster(Map<CellPciPair, ArrayList<CellPciPair>> clusterMap) throws ConfigDbNotFoundException, CpsNotFoundException
+ {
Graph cluster = new Graph();
log.debug("cluster formation started");
@@ -246,7 +250,7 @@ public class ClusterUtils {
val1.setPhysicalCellId(phy);
cluster.addEdge(val, val1);
- List<CellPciPair> nbrList = SdnrRestClient.getNbrList(cell);
+ List<CellPciPair> nbrList = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cell);
for (CellPciPair nbr : nbrList) {
String cid = nbr.getCellId();
@@ -297,14 +301,14 @@ public class ClusterUtils {
/**
* Find cluster Map.
*/
- public Map<CellPciPair, ArrayList<CellPciPair>> findClusterMap(String cellId) throws ConfigDbNotFoundException {
+ public Map<CellPciPair, ArrayList<CellPciPair>> findClusterMap(String cellId) throws ConfigDbNotFoundException, CpsNotFoundException {
log.info("indide clusterMap");
- int phyCellId = SdnrRestClient.getPci(cellId);
+ int phyCellId = ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getPci(cellId);
CellPciPair main = new CellPciPair();
main.setCellId(cellId);
main.setPhysicalCellId(phyCellId);
ArrayList<CellPciPair> cellPciPairs;
- cellPciPairs = (ArrayList<CellPciPair>) SdnrRestClient.getNbrList(cellId);
+ cellPciPairs = (ArrayList<CellPciPair>) ConfigurationClient.configClient(Configuration.getInstance().getConfigClientType()).getNbrList(cellId);
Map<CellPciPair, ArrayList<CellPciPair>> clusterMap = new HashMap<>();
clusterMap.put(main, cellPciPairs);
log.info("clusterMap{}", clusterMap);
diff --git a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java
index d32a78c..e3eb8a7 100644
--- a/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java
+++ b/src/main/java/org/onap/dcaegen2/services/sonhms/utils/SonHandlerRestTemplate.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* son-handler
* ================================================================================
- * Copyright (C) 2019 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.
@@ -39,6 +39,7 @@ import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
+import org.onap.dcaegen2.services.sonhms.Configuration;
import org.slf4j.Logger;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
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);