summaryrefslogtreecommitdiffstats
path: root/esr-mgr
diff options
context:
space:
mode:
authorZi Li <li.zi30@zte.com.cn>2018-08-21 02:39:58 +0000
committerZi Li <li.zi30@zte.com.cn>2018-08-21 02:40:09 +0000
commitd5eb2430bf0013b8be832eb02813c3844c0cef91 (patch)
treee975c22a8998b1514e165d7848bb6a664a240d73 /esr-mgr
parent2af1528498f33d0f60fcce157a9d6b0472b9b956 (diff)
Realize the query PNF list API.
Issue-ID: AAI-1497 Change-Id: I3765fbd3313bdb16ed75fd9ce072cc707399ad43 Signed-off-by: Zi Li <li.zi30@zte.com.cn>
Diffstat (limited to 'esr-mgr')
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java8
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java33
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java39
3 files changed, 78 insertions, 2 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java
index 075c959..42ee079 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java
@@ -51,4 +51,12 @@ public class NetworkProxy {
throw new ExtsysException("Query PNF from A&AI failed.", e);
}
}
+
+ public String queryPnfList() throws ExtsysException {
+ try {
+ return network.queryPNFList(transactionId, fromAppId, authorization);
+ } catch (Exception e) {
+ throw new ExtsysException("Query PNF List from A&AI failed.", e);
+ }
+ }
}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
index 5efa743..c017eba 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
@@ -15,9 +15,14 @@
*/
package org.onap.aai.esr.wrapper;
+import java.util.ArrayList;
+import java.util.List;
import javax.ws.rs.core.Response;
+import org.onap.aai.esr.entity.aai.EsrVnfmList;
import org.onap.aai.esr.entity.aai.Pnf;
+import org.onap.aai.esr.entity.aai.PnfList;
import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
+import org.onap.aai.esr.entity.rest.VnfmRegisterInfo;
import org.onap.aai.esr.exception.ExceptionUtil;
import org.onap.aai.esr.exception.ExtsysException;
import org.onap.aai.esr.externalservice.aai.NetworkProxy;
@@ -53,8 +58,32 @@ public class PnfManagerWrapper {
* @return
*/
public Response queryPnfList() {
- // TODO Auto-generated method stub
- return null;
+ List<PnfRegisterInfo> esrPnfList = new ArrayList<>();
+ PnfList pnfList = new PnfList();
+ try {
+ String pnflistStr = networkProxy.queryPnfList();
+ pnfList = new Gson().fromJson(pnflistStr, PnfList.class);
+ LOG.info("Response from AAI by query PNF list: " + pnflistStr);
+ esrPnfList = getEsrPnfList(pnfList);
+ return Response.ok(esrPnfList).build();
+ } catch (ExtsysException e) {
+ LOG.error("Query VNFM list failed !", e);
+ return Response.ok(esrPnfList).build();
+ }
+ }
+
+ /**
+ * @param pnfList
+ * @return
+ */
+ private List<PnfRegisterInfo> getEsrPnfList(PnfList pnfList) {
+ List<PnfRegisterInfo> esrPnfList = new ArrayList<>();
+ for (int i = 0; i < pnfList.getPnf().size(); i++) {
+ Pnf pnf = pnfList.getPnf().get(i);
+ PnfRegisterInfo pnfRegisterInfo = pnfManagerUtil.pnf2PnfRegisterInfo(pnf);
+ esrPnfList.add(pnfRegisterInfo);
+ }
+ return esrPnfList;
}
/**
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java
index a408fdf..038e275 100644
--- a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java
@@ -16,6 +16,8 @@
package org.onap.aai.esr.wrapper;
import static org.junit.Assert.assertEquals;
+import java.util.ArrayList;
+import java.util.List;
import javax.ws.rs.core.Response;
import org.junit.Assert;
import org.junit.Test;
@@ -23,7 +25,9 @@ import org.mockito.Mockito;
import org.onap.aai.esr.common.MsbConfig;
import org.onap.aai.esr.entity.aai.Pnf;
import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
+import org.onap.aai.esr.entity.rest.VnfmRegisterInfo;
import org.onap.aai.esr.exception.ExtsysException;
+import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
import org.onap.aai.esr.externalservice.aai.NetworkProxy;
import org.onap.aai.esr.util.ExtsysUtil;
@@ -87,4 +91,39 @@ public class PnfManagerWrapperTest {
assertEquals(extsysUtil.objectToString(pnfRegisterInfo), extsysUtil.objectToString(response.getEntity()));
}
}
+
+ @Test
+ public void test_queryPnfList() throws ExtsysException {
+ ExtsysUtil extsysUtil = new ExtsysUtil();
+ List<PnfRegisterInfo> esrPnfList = new ArrayList<>();
+ PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo();
+ pnfRegisterInfo.setPnfId("pnf1");
+ pnfRegisterInfo.setUserLabel("PNF test");
+ pnfRegisterInfo.setSubnetId("subnetId1");
+ pnfRegisterInfo.setNeId("neId1");
+ pnfRegisterInfo.setManagementType("Test");
+ pnfRegisterInfo.setVendor("ZTE");
+ pnfRegisterInfo.setPnfdId("pnfdId1");
+ pnfRegisterInfo.setEmsId("emsId1");
+ pnfRegisterInfo.setLattitude("121.546");
+ pnfRegisterInfo.setLongitude("14.22");
+ esrPnfList.add(pnfRegisterInfo);
+ String pnfListStr = "{\"pnf\": [{\"pnf-name\": \"pnf1\","
+ + "\"pnf-name2\": \"PNF test\","
+ + "\"pnf-id\": \"subnetId1-neId1\","
+ + "\"equip-type\": \"Test\","
+ + "\"equip-vendor\": \"ZTE\","
+ + "\"equip-model\": \"pnfdId1\","
+ + "\"management-option\": \"emsId1\","
+ + "\"in-maint\": false,"
+ + "\"frame-id\": \"121.546-14.22\"}]}";
+ NetworkProxy mockNetworkProxy = Mockito.mock(NetworkProxy.class);
+ Mockito.when(mockNetworkProxy.queryPnfList()).thenReturn(pnfListStr);
+ PnfManagerWrapper pnfManagerWrapper = new PnfManagerWrapper(mockNetworkProxy);
+ Response response = pnfManagerWrapper.queryPnfList();
+ if (response != null) {
+ Assert.assertTrue(response.getStatus() == 200);
+ assertEquals(extsysUtil.objectToString(esrPnfList), extsysUtil.objectToString(response.getEntity()));
+ }
+ }
}