Realize the query PNF list API. 27/61427/1
authorZi Li <li.zi30@zte.com.cn>
Tue, 21 Aug 2018 02:39:58 +0000 (02:39 +0000)
committerZi Li <li.zi30@zte.com.cn>
Tue, 21 Aug 2018 02:40:09 +0000 (02:40 +0000)
Issue-ID: AAI-1497

Change-Id: I3765fbd3313bdb16ed75fd9ce072cc707399ad43
Signed-off-by: Zi Li <li.zi30@zte.com.cn>
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java
esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java

index 075c959..42ee079 100644 (file)
@@ -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);
+        }
+    }
 }
index 5efa743..c017eba 100644 (file)
  */
 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;
     }
 
     /**
index a408fdf..038e275 100644 (file)
@@ -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()));
+        }
+    }
 }