Add unit test for vnfm manage API.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / wrapper / ThirdpatySdncWrapper.java
index 4ecc5c9..fd7dc43 100644 (file)
@@ -22,12 +22,12 @@ import javax.ws.rs.core.Response;
 import org.onap.aai.esr.entity.aai.EsrSystemInfo;
 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
 import org.onap.aai.esr.entity.aai.EsrThirdpartySdncList;
-import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
 import org.onap.aai.esr.entity.rest.CommonRegisterResponse;
 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
+import org.onap.aai.esr.exception.ExceptionUtil;
+import org.onap.aai.esr.exception.ExtsysException;
 import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
 import org.onap.aai.esr.util.ThirdpartySdncManagerUtil;
-import org.onap.aai.esr.util.VnfmManagerUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,6 +37,7 @@ public class ThirdpatySdncWrapper {
 
   private static ThirdpatySdncWrapper thirdpatySdncWrapper;
   private static final Logger LOG = LoggerFactory.getLogger(ThirdpatySdncWrapper.class);
+  private static ThirdpartySdncManagerUtil thirdpartySdncManagerUtil = new ThirdpartySdncManagerUtil();
 
   /**
    * get ThirdpatySdncWrapper instance.
@@ -52,16 +53,15 @@ public class ThirdpatySdncWrapper {
   public Response registerThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
     CommonRegisterResponse result = new CommonRegisterResponse();
     EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
-    esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
+    esrSdncDetail = thirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
     String sdncId = esrSdncDetail.getThirdpartySdncId();
     try {
       ExternalSystemProxy.registerSdnc(sdncId, esrSdncDetail);
       result.setId(sdncId);
       return Response.ok(result).build();
-    } catch (Exception e) {
-      e.printStackTrace();
-      LOG.error("Register thirdParty SDNC failed !" + e.getMessage());
-      return Response.serverError().build();
+    } catch (ExtsysException e) {
+      LOG.error("Register thirdParty SDNC failed !" , e);
+      throw ExceptionUtil.buildExceptionResponse(e.getMessage());
     }
     
   }
@@ -72,7 +72,7 @@ public class ThirdpatySdncWrapper {
     EsrThirdpartySdncDetail originalEsrSdncDetail = new EsrThirdpartySdncDetail();
     EsrSystemInfo originalEsrSystemInfo = new EsrSystemInfo();
     originalEsrSdncDetail = queryEsrThirdpartySdncDetail(sdncId);
-    esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
+    esrSdncDetail = thirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
     String resourceVersion = originalEsrSdncDetail.getResourceVersion();
     esrSdncDetail.setResourceVersion(resourceVersion);
     esrSdncDetail.setThirdpartySdncId(sdncId);
@@ -85,10 +85,9 @@ public class ThirdpatySdncWrapper {
       ExternalSystemProxy.registerSdnc(sdncId, esrSdncDetail);
       result.setId(sdncId);
       return Response.ok(result).build();
-    } catch (Exception e) {
-      e.printStackTrace();
-      LOG.error("Update VNFM failed !" + e.getMessage());
-      return Response.serverError().build();
+    } catch (ExtsysException e) {
+      LOG.error("Update VNFM failed !" , e);
+      throw ExceptionUtil.buildExceptionResponse(e.getMessage());
     }
   }
   
@@ -100,41 +99,29 @@ public class ThirdpatySdncWrapper {
       esrSdnc = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncList.class);
       LOG.info("Response from AAI by query thirdparty SDNC list: " + esrSdnc);
       sdncList = getSdncDetailList(esrSdnc);
-      return Response.ok(sdncList).build();
-    } catch (Exception e) {
-      e.printStackTrace();
-      LOG.error("Query thirdparty SDNC list failed !");
-      return Response.serverError().build();
+    } catch (ExtsysException e) {
+      LOG.error("Query thirdparty SDNC list failed !", e);
     }
+    return Response.ok(sdncList).build();
   }
   
   public Response queryThirdpartySdncById(String thirdpartySdncId) {
     ThirdpartySdncRegisterInfo thirdpartySdnc = new ThirdpartySdncRegisterInfo();
     thirdpartySdnc = querySdncDetail(thirdpartySdncId);
-    if(thirdpartySdnc != null) {
-      return Response.ok(thirdpartySdnc).build();
-    } else {
-      return Response.ok().build();
-    }
+    return Response.ok(thirdpartySdnc).build();
   }
   
   public Response delThirdpartySdnc(String thirdpartySdncId) {
     EsrThirdpartySdncDetail thirdpartySdncDetail = new EsrThirdpartySdncDetail();
     thirdpartySdncDetail = queryEsrThirdpartySdncDetail(thirdpartySdncId);
     String resourceVersion = thirdpartySdncDetail.getResourceVersion();
-    if (resourceVersion != null) {
-      try {
-        ExternalSystemProxy.deleteThirdpartySdnc(thirdpartySdncId, resourceVersion);
-        return Response.ok().build();
-      } catch (Exception e) {
-        e.printStackTrace();
-        LOG.error("Delete VNFM from A&AI failed! thirdparty SDNC ID: " + thirdpartySdncId + "resouce-version:"
-            + resourceVersion, e.getMessage());
-        return Response.noContent().build();
-      }
-    } else {
-      LOG.error("resouce-version is null ! Can not delete resouce from A&AI. ");
-      return Response.serverError().build();
+    try {
+      ExternalSystemProxy.deleteThirdpartySdnc(thirdpartySdncId, resourceVersion);
+      return Response.noContent().build();
+    } catch (ExtsysException e) {
+      LOG.error("Delete VNFM from A&AI failed! thirdparty SDNC ID: " + thirdpartySdncId
+          + "resouce-version:" + resourceVersion, e);
+      throw ExceptionUtil.buildExceptionResponse(e.getMessage());
     }
   }
   
@@ -145,12 +132,11 @@ public class ThirdpatySdncWrapper {
       String esrSdncStr = ExternalSystemProxy.queryThirdpartySdncDetail(sdncId);
       LOG.info("Response from AAI by query thirdparty SDNC: " + esrSdncStr);
       esrSdncDetail = new Gson().fromJson(esrSdncStr, EsrThirdpartySdncDetail.class);
-      sdncRegisterInfo = ThirdpartySdncManagerUtil.esrSdnc2SdncRegisterInfo(esrSdncDetail);
+      sdncRegisterInfo = thirdpartySdncManagerUtil.esrSdnc2SdncRegisterInfo(esrSdncDetail);
       return sdncRegisterInfo;
-    } catch (Exception e) {
-      e.printStackTrace();
-      LOG.error("Query VNFM detail failed! thirdpaty SDNC ID: " + sdncId, e.getMessage());
-      return null;
+    } catch (ExtsysException e) {
+      LOG.error("Query VNFM detail failed! thirdpaty SDNC ID: " + sdncId, e);
+      throw ExceptionUtil.buildExceptionResponse(e.getMessage());
     }
   }
   
@@ -173,9 +159,9 @@ public class ThirdpatySdncWrapper {
       String esrThirdpartySdncStr = ExternalSystemProxy.queryThirdpartySdncDetail(sdncId);
       LOG.info("Response from AAI by query thirdparty SDNC: " + esrThirdpartySdncStr);
       esrSdncDetail = new Gson().fromJson(esrThirdpartySdncStr, EsrThirdpartySdncDetail.class);
-    } catch (Exception e) {
-      e.printStackTrace();
-      LOG.error("Query VNFM detail failed! VNFM ID: " + sdncId, e.getMessage());
+    } catch (ExtsysException e) {
+      LOG.error("Query VNFM detail failed! VNFM ID: " + sdncId, e);
+      throw ExceptionUtil.buildExceptionResponse(e.getMessage());
     }
     return esrSdncDetail;
   }