From 8f034106c45d3cd356c2b0a6a404e6bde40d7604 Mon Sep 17 00:00:00 2001 From: yufei_zhou Date: Thu, 15 Mar 2018 14:36:23 +0800 Subject: improve code coverage and update log directory Change-Id: I2790da2509c07033288d1e1b4fd0524daef09dda Issue-ID: VFC-724 Signed-off-by: yufei_zhou --- .../adaptor/Cbam2DriverResponseConverter.java | 18 +- .../svnfm/adaptor/Driver2CbamRequestConverter.java | 44 ++- .../vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java | 22 ++ .../cbam/bo/CBAMCreateSubscriptionRequest.java | 2 +- .../svnfm/cbam/bo/CBAMOperExecutVnfRequest.java | 22 -- .../driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java | 7 +- .../svnfm/init/CbamNofiticationSubscription.java | 93 ------ .../vnfmdriver/bo/CreateSubscriptionRequest.java | 37 +++ .../vnfmdriver/bo/CreateSubscriptionResponse.java | 34 +++ .../controller/VnfmDriverController.java | 79 ++++-- .../svnfm/vnfmdriver/inf/VnfmDriverMgmrInf.java | 4 + .../src/main/resources/application.properties | 2 +- .../vfcadaptor/src/main/resources/logback.xml | 9 +- .../vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java | 31 +- .../vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java | 21 ++ .../svnfm/catalog/impl/CatalogMgmrImplTest.java | 23 ++ .../vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java | 316 ++++++++++++++++++++- .../controller/VnfmDriverControllerTest.java | 28 +- 18 files changed, 616 insertions(+), 176 deletions(-) delete mode 100644 nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMOperExecutVnfRequest.java delete mode 100644 nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java create mode 100644 nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionRequest.java create mode 100644 nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionResponse.java (limited to 'nokia') diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java index 6034b55b..9f39c18b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Cbam2DriverResponseConverter.java @@ -15,6 +15,7 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; @@ -28,6 +29,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.OperStatusVnfResponse; @@ -155,11 +157,11 @@ public class Cbam2DriverResponseConverter { if (OperationType.INSTANTIATE == oper.getOperationType()) { double instantiateProgress = (nowTime - jobInfo.getOperateStartTime()) - / (double)(adaptorEnv.getInstantiateTimeInterval()); + / adaptorEnv.getInstantiateTimeInterval(); initialProgress = (int) (instantiateProgress + initialProgress); } else if (OperationType.TERMINATE == oper.getOperationType()) { double terminateProgress = (nowTime - jobInfo.getOperateStartTime()) - / (double)(adaptorEnv.getTerminateTimeInterval()); + / adaptorEnv.getTerminateTimeInterval(); initialProgress = (int) (terminateProgress + initialProgress); } else { initialProgress = 0; @@ -172,4 +174,16 @@ public class Cbam2DriverResponseConverter { this.adaptorEnv = adaptorEnv; } + public CreateSubscriptionResponse queryRspConvert(CBAMCreateSubscriptionResponse cbamResponse) { + CreateSubscriptionResponse response = new CreateSubscriptionResponse(); + + response.set_links(cbamResponse.get_links()); + response.setId(cbamResponse.getId()); + response.setCallbackUri(cbamResponse.getCallbackUrl()); + response.setCallbackUrl(cbamResponse.getCallbackUrl()); + response.setFilter(cbamResponse.getFilter()); + + return response; + } + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java index 8c60cc67..39b3f7cf 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/Driver2CbamRequestConverter.java @@ -54,11 +54,11 @@ public class Driver2CbamRequestConverter { } public CBAMInstantiateVnfRequest instantiateRequestConvert(InstantiateVnfRequest driverRequest, - NslcmGrantVnfResponse nslc, GrantInfo grant, VimComputeResourceFlavour vimco) throws IOException{ - Gson gson = new Gson(); + NslcmGrantVnfResponse nslc, GrantInfo grant, VimComputeResourceFlavour vimco) throws Exception { + Gson gson = new Gson(); String inputJson = readcbamInputInfoFromJsonFile(); CBAMInstantiateVnfRequest request = gson.fromJson(inputJson, CBAMInstantiateVnfRequest.class); - + return request; } @@ -96,5 +96,41 @@ public class Driver2CbamRequestConverter { request.setAdditionalParams(driverRequest.getAdditionalParam()); return request; } - + +// public static void main(String[] argv) throws IOException { +// Gson gson = new Gson(); +// String filePath = "D:\\cbam_input.json"; +// String inputJson = readcbamInputInfo(filePath); +// CBAMInstantiateVnfRequest request = gson.fromJson(inputJson, CBAMInstantiateVnfRequest.class); +// System.out.println(gson.toJson(request)); +// } +// +// public static String readcbamInputInfo(String filePath) throws IOException { +// InputStream ins = null; +// BufferedInputStream bins = null; +// String fileContent = ""; +// String fileName = filePath; +// +// try { +// ins = new FileInputStream(fileName); +// bins = new BufferedInputStream(ins); +// +// byte[] contentByte = new byte[ins.available()]; +// int num = bins.read(contentByte); +// +// if(num > 0) { +// fileContent = new String(contentByte); +// } +// } catch(FileNotFoundException e) { +// e.printStackTrace();; +// } finally { +// if(ins != null) { +// ins.close(); +// } +// if(bins != null) { +// bins.close(); +// } +// } +// return fileContent; +// } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java index 251c4638..69d36efe 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImpl.java @@ -24,6 +24,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity.EsrSystemInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; @@ -37,8 +38,11 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfcResourceInfoMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; @@ -85,6 +89,9 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf { @Autowired private VnfcResourceInfoMapper vnfcDbMgmr; + + @Autowired + private VnfmSubscriptionsMapper subscriptionsMapper; @Autowired AdaptorEnv adaptorEnv; @@ -345,4 +352,19 @@ public class VnfmDriverMgmrImpl implements VnfmDriverMgmrInf { this.responseConverter = responseConverter; } + @Override + public CreateSubscriptionResponse createSubscription(CreateSubscriptionRequest request) throws VnfmDriverException { + CreateSubscriptionResponse driverResponse; + try { + CBAMCreateSubscriptionResponse cbamResponse = cbamMgmr.createSubscription(request); + driverResponse = responseConverter.queryRspConvert(cbamResponse); + subscriptionsMapper.insert(cbamResponse.getId()); + } catch (Exception e) { + logger.error("error VnfmDriverMgmrImpl --> createSubscripiton. ", e); + throw new VnfmDriverException(HttpStatus.SC_INTERNAL_SERVER_ERROR, CommonConstants.HTTP_ERROR_DESC_500); + } + + return driverResponse; + } + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java index 29085c14..e0069771 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMCreateSubscriptionRequest.java @@ -28,7 +28,7 @@ public class CBAMCreateSubscriptionRequest { @JsonProperty("callbackUrl") private String callbackUrl; - @JsonProperty("description") + @JsonProperty("authentication") private SubscriptionAuthentication authentication; public SubscriptionFilter getFilter() { diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMOperExecutVnfRequest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMOperExecutVnfRequest.java deleted file mode 100644 index 0c748cfd..00000000 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/bo/CBAMOperExecutVnfRequest.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * 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. - */ -package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo; - -public class CBAMOperExecutVnfRequest { - - - -} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java index 4211dee3..3f3ae57b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java @@ -474,15 +474,17 @@ public class CbamMgmrImpl implements CbamMgmrInf { logger.info("CbamMgmrImpl -> createSubscription, requestStr is " + gson.toJson(subscriptionRequest)); HttpResult httpResult = operateCbamHttpTask(subscriptionRequest, httpPath, method); String responseStr = httpResult.getContent(); + + CBAMCreateSubscriptionResponse response = null; logger.info("CbamMgmrImpl -> createSubscription, responseStr is " + responseStr); int code = httpResult.getStatusCode(); if (code == 201) { logger.info("CbamMgmrImpl -> createSubscription success "); + response = gson.fromJson(responseStr, CBAMCreateSubscriptionResponse.class); } else { logger.error("CbamMgmrImpl -> createSubscription error , statusCode = " + code); } - CBAMCreateSubscriptionResponse response = gson.fromJson(responseStr, CBAMCreateSubscriptionResponse.class); return response; } @@ -527,7 +529,4 @@ public class CbamMgmrImpl implements CbamMgmrInf { return response; } - - - } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java deleted file mode 100644 index 32cb2fa0..00000000 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/init/CbamNofiticationSubscription.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * 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. - */ - -package org.onap.vfc.nfvo.driver.vnfm.svnfm.init; - -import java.io.IOException; -import java.util.List; - -import org.apache.http.client.ClientProtocolException; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmSubscriptionInfo; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -//@Order(3) -//@Component -public class CbamNofiticationSubscription implements ApplicationRunner { - private static final Logger logger = LoggerFactory.getLogger(CbamNofiticationSubscription.class); - - @Autowired - AdaptorEnv adaptorEnv; - - @Autowired - private CbamMgmrInf cbamMgmr; - - @Autowired - private VnfmSubscriptionsMapper subscriptionsMapper; - - @Override - public void run(ApplicationArguments args){ - boolean subscribed = false; - List allSubscripions = subscriptionsMapper.getAll(); - if(allSubscripions != null && !allSubscripions.isEmpty()) - { - for(VnfmSubscriptionInfo subscriptionInfo : allSubscripions) - { - try { - Subscription subscription = cbamMgmr.getSubscription(subscriptionInfo.getId()); - if(subscription != null) - { - subscribed = true; - logger.info("CBAM Notification has already been subscribed with id = " + subscriptionInfo.getId()); - } - else - { - subscriptionsMapper.delete(subscriptionInfo.getId()); - } - } catch (Exception e) { - logger.error("Query or delete subscription error.", e); - } - } - } - - if(!subscribed) - { - CBAMCreateSubscriptionRequest subscriptionRequest = new CBAMCreateSubscriptionRequest(); - subscriptionRequest.setCallbackUrl(adaptorEnv.getDriverApiUriFront() + "/api/nokiavnfmdriver/v1/notifications"); - try { - CBAMCreateSubscriptionResponse createSubscription = cbamMgmr.createSubscription(subscriptionRequest); - if(createSubscription != null) - { - subscriptionsMapper.insert(createSubscription.getId()); - logger.info("CBAM Notification is successfully subscribed with id = " + createSubscription.getId()); - } - } catch (Exception e) { - logger.error("Subscribe notification error.", e); - } - } - } -} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionRequest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionRequest.java new file mode 100644 index 00000000..2834cd2c --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionRequest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * 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. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CreateSubscriptionRequest extends CBAMCreateSubscriptionRequest{ + + + //the attribute callbackUri is for SOL003 driver, while callbackUrl is for CBAM + @JsonProperty("callbackUri") + private String callbackUri; + + public String getCallbackUri() { + return callbackUri; + } + + public void setCallbackUri(String callbackUri) { + this.callbackUri = callbackUri; + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionResponse.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionResponse.java new file mode 100644 index 00000000..0f6f563a --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/bo/CreateSubscriptionResponse.java @@ -0,0 +1,34 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * 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. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo; + +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class CreateSubscriptionResponse extends Subscription{ + //the attribute callbackUri is for SOL003 driver, while callbackUrl is for CBAM + @JsonProperty("callbackUri") + private String callbackUri; + + public String getCallbackUri() { + return callbackUri; + } + + public void setCallbackUri(String callbackUri) { + this.callbackUri = callbackUri; + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java index b6bf3eb0..cb429149 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverController.java @@ -18,14 +18,14 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.controller; import java.io.IOException; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.http.HttpStatus; -import org.apache.http.client.ClientProtocolException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; @@ -196,30 +196,30 @@ public class VnfmDriverController { return null; } -// @RequestMapping(value = "/notifications", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) -// public CBAMVnfNotificationResponse notificationVnf(@RequestBody CBAMVnfNotificationRequest request, HttpServletResponse httpResponse) throws ClientProtocolException, Exception - @RequestMapping(value = "/notifications") -// @ResponseBody - public void notificationVnf(HttpServletRequest request, HttpServletResponse httpResponse) throws ClientProtocolException, Exception - { - -// String jsonString = gson.toJson(request); -// logger.info("notificationVnf request: bodyMessage is " + jsonString); - logger.info("notificationVnf request: bodyMessage is " + request.getMethod() + ","); - - try { -// CBAMVnfNotificationResponse response = cbamMgmr.getNotification(request); - httpResponse.setStatus(204); -// logger.info("cbamController --> notificationVnf response is " + gson.toJson(response)); -// return response; - } - catch(VnfmDriverException e) - { - processControllerException(httpResponse, e); - } - -// return null; - } +//// @RequestMapping(value = "/notifications", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) +//// public CBAMVnfNotificationResponse notificationVnf(@RequestBody CBAMVnfNotificationRequest request, HttpServletResponse httpResponse) throws ClientProtocolException, Exception +// @RequestMapping(value = "/notifications") +//// @ResponseBody +// public void notificationVnf(HttpServletRequest request, HttpServletResponse httpResponse) throws ClientProtocolException, Exception +// { +// +//// String jsonString = gson.toJson(request); +//// logger.info("notificationVnf request: bodyMessage is " + jsonString); +// logger.info("notificationVnf request: bodyMessage is " + request.getMethod() + ","); +// +// try { +//// CBAMVnfNotificationResponse response = cbamMgmr.getNotification(request); +// httpResponse.setStatus(204); +//// logger.info("cbamController --> notificationVnf response is " + gson.toJson(response)); +//// return response; +// } +// catch(VnfmDriverException e) +// { +// processControllerException(httpResponse, e); +// } +// +//// return null; +// } private void processControllerException(HttpServletResponse httpResponse, VnfmDriverException e) { try { @@ -230,4 +230,31 @@ public class VnfmDriverController { logger.error("VnfmDriverController --> processControllerException error to sendError ", e1); } } + +// -- The following VNFM Driver APIs are compliant to ETSI SOL003 -- Begin + + @RequestMapping(value = "/createSubscripiton", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) + @ResponseBody + public CreateSubscriptionResponse createSubscripiton(@RequestBody CreateSubscriptionRequest request, HttpServletResponse httpResponse) + { + String jsonString = gson.toJson(request); + logger.info("VnfmDriverController --> createSubscripiton, bodyMessage is " + jsonString); + + try { + request.setCallbackUrl(request.getCallbackUri()); + CreateSubscriptionResponse response = vnfmDriverMgmr.createSubscription(request); + httpResponse.setStatus(HttpStatus.SC_CREATED); + logger.info("VnfmDriverController --> createSubscripiton end "); + return response; + } + catch(VnfmDriverException e) + { + processControllerException(httpResponse, e); + } + + return null; + } + +// -- The following VNFM Driver APIs are compliant to ETSI SOL003 -- End } + diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfmDriverMgmrInf.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfmDriverMgmrInf.java index 01e7155f..1c718978 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfmDriverMgmrInf.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/inf/VnfmDriverMgmrInf.java @@ -17,6 +17,8 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.inf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; @@ -41,4 +43,6 @@ public interface VnfmDriverMgmrInf { public ScaleVnfResponse scaleVnf(ScaleVnfRequest request, String vnfmId, String vnfInstanceId) throws VnfmDriverException; public HealVnfResponse healVnf(HealVnfRequest request, String vnfmId, String vnfInstanceId) throws VnfmDriverException; + + public CreateSubscriptionResponse createSubscription(CreateSubscriptionRequest request) throws VnfmDriverException; } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties index 2b870c0a..de0fa957 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/application.properties @@ -40,7 +40,7 @@ spring.datasource.url=jdbc:mariadb://127.0.0.1:3306/vnfm_db?useUnicode=true&char ## for logging begin ## com.fasterxml.jackson.core=jackson-databind -logging.file=${catalina.base}/logs/vfcadaptor.log +logging.file=/var/log/onap/vfc/svnfm/nokiavnfmdriver.log logging.level.org.springframework.web=DEBUG logging.level.org.hibernate=DEBUG ## for logging end ## diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml index d1be476b..b74b8188 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/resources/logback.xml @@ -7,11 +7,10 @@ UTF-8 - - ${catalina.base}/logs/vfcadaptor.log - - ${catalina.base}/logs/vfcadaptor.%i.log.zip + + /var/log/onap/vfc/svnfm/nokiavnfmdriver.log + + /var/log/onap/vfc/svnfm/nokiavnfmdriver.%i.log.zip 1 9 diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java index 01c256bd..a2eece33 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImplTest.java @@ -53,10 +53,21 @@ public class AaiMgmrInfImplTest { String json = "{" + "\"vnfm-id\":\"vnfm-id_001\"," + + "\"resource-version\" : \"resource-version\"," + "\"vim-id\":\"vim-id_001\"," + "\"certificate-url\":\"certificate-url_001\"," - + "\"resource-version\":\"resource-version_001\"," - + "\"esr-system-info\":[{\"type\" : \"vnfm\"}]" + + "\"esr-system-info\":[{" + + "\"type\" : \"vnfm\"," + + "\"system-name\" : \"system-name\"," + + "\"vendor\" : \"vendor\"," + + "\"esr-system-info-id\" : \"esr-system-info-id\"," + + "\"version\" : \"version\"," + + "\"service-url\" : \"service-url\"," + + "\"user-name\" : \"user-name\"," + + "\"password\" : \"password\"," + + "\"system-type\" : \"system-type\"," + + "\"resource-version\" : \"resource-version\"" + + "}]" + "}" + ""; HttpResult httpResult = new HttpResult(); @@ -69,6 +80,22 @@ public class AaiMgmrInfImplTest { public void testQueryVnfPackage() throws ClientProtocolException, IOException { AaiVnfmInfo vnfmInfo = aaiMgmr.queryVnfm(vnfmId); + vnfmInfo.getEsrSystemInfoList().get(0).setEsrSystemName("system-name"); + vnfmInfo.getEsrSystemInfoList().get(0).setSystemType("system-type"); + vnfmInfo.getEsrSystemInfoList().get(0).setResourceVersion("resource-version"); Assert.assertEquals("vnfm", vnfmInfo.getEsrSystemInfoList().get(0).getType()); + Assert.assertEquals("esr-system-info-id", vnfmInfo.getEsrSystemInfoList().get(0).getEsrSystemId()); + Assert.assertEquals("system-name", vnfmInfo.getEsrSystemInfoList().get(0).getEsrSystemName()); + Assert.assertEquals("vendor", vnfmInfo.getEsrSystemInfoList().get(0).getVendor()); + Assert.assertEquals("version", vnfmInfo.getEsrSystemInfoList().get(0).getVersion()); + Assert.assertEquals("user-name", vnfmInfo.getEsrSystemInfoList().get(0).getUserName()); + Assert.assertEquals("password", vnfmInfo.getEsrSystemInfoList().get(0).getPassword()); + Assert.assertEquals("system-type", vnfmInfo.getEsrSystemInfoList().get(0).getSystemType()); + Assert.assertEquals("resource-version", vnfmInfo.getEsrSystemInfoList().get(0).getResourceVersion()); + + Assert.assertEquals("vnfm-id_001", vnfmInfo.getVnfmId()); + Assert.assertEquals("vim-id_001", vnfmInfo.getVimId()); + Assert.assertEquals("certificate-url_001", vnfmInfo.getCertificateUrl()); + Assert.assertEquals("resource-version", vnfmInfo.getResourceVersion()); } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java index f3fb6f3b..1810820e 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/adaptor/VnfmDriverMgmrImplTest.java @@ -16,6 +16,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.adaptor; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; import java.io.IOException; @@ -36,6 +37,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.entity.EsrSystemInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; @@ -50,8 +53,11 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonEnum; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.ScaleType; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.bean.VnfmJobExecutionInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmJobExecutionMapper; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.mapper.VnfmSubscriptionsMapper; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.inf.NslcmMgmrInf; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; @@ -84,6 +90,9 @@ public class VnfmDriverMgmrImplTest { @Mock private VnfmJobExecutionMapper jobDbManager; + @Mock + private VnfmSubscriptionsMapper subscriptionsMapper; + @Mock private VnfContinueProcessorInf vnfContinueProcessorInf; @@ -215,5 +224,17 @@ public class VnfmDriverMgmrImplTest { // // Assert.assertEquals("executionId_001", response.getJobId()); } + + @Test + public void testCreateSubscription() throws ClientProtocolException, IOException { + CBAMCreateSubscriptionResponse mockCbamResponse = new CBAMCreateSubscriptionResponse(); + mockCbamResponse.setId("subscriptionId_001"); + mockCbamResponse.setCallbackUrl("callbackUrl"); + when(cbamMgmr.createSubscription(Mockito.any(CBAMCreateSubscriptionRequest.class))).thenReturn(mockCbamResponse); + doNothing().when(subscriptionsMapper).insert(Mockito.anyString()); + CreateSubscriptionRequest request = new CreateSubscriptionRequest(); + CreateSubscriptionResponse response = vnfmDriverMgmr.createSubscription(request); + Assert.assertEquals("callbackUrl", response.getCallbackUri()); + } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java index d1df4dbb..f7320998 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImplTest.java @@ -95,6 +95,9 @@ public class CatalogMgmrImplTest { packageInfo.setVnfdProvider("vnfdProvider"); packageInfo.setVnfdVersion("vnfdVersion"); packageInfo.setVnfVersion("vnfVersion"); + packageInfo.setProvider("provider"); + packageInfo.setVnfdProvider("vnfdProvider"); + packageInfo.setVersion("version"); Deletionpending deletionPending = CommonEnum.Deletionpending.fALSE; packageInfo.setDeletionPending(deletionPending ); @@ -108,6 +111,26 @@ public class CatalogMgmrImplTest { when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); VnfPackageInfo packageInfo1 = catalogMgmr.queryVnfPackage(vnfPackageId); Assert.assertEquals("1.3.5.6", packageInfo.getDownloadUri()); + Assert.assertEquals("name", packageInfo.getName()); + Assert.assertEquals("onBoardState", packageInfo.getOnBoardState()); + Assert.assertEquals("vnfdId", packageInfo.getVnfdId()); + Assert.assertEquals("provider", packageInfo.getProvider()); + Assert.assertEquals("vnfdProvider", packageInfo.getVnfdProvider()); + Assert.assertEquals("vnfdVersion", packageInfo.getVnfdVersion()); + Assert.assertEquals("vnfVersion", packageInfo.getVnfVersion()); + Assert.assertEquals("version", packageInfo.getVersion()); + Assert.assertEquals(CommonEnum.Deletionpending.fALSE, packageInfo.getDeletionPending()); + + Assert.assertEquals("csarId", response.getCsarId()); + Assert.assertEquals("fileName", response.getImageInfo().getFileName()); + Assert.assertEquals("imageId", response.getImageInfo().getImageId()); + Assert.assertEquals("index", response.getImageInfo().getIndex()); + Assert.assertEquals("status", response.getImageInfo().getStatus()); + Assert.assertEquals("tenant", response.getImageInfo().getTenant()); + Assert.assertEquals("vimId", response.getImageInfo().getVimId()); + Assert.assertEquals("vimUser", response.getImageInfo().getVimUser()); + Assert.assertEquals("vnfInstanceId", response.getVnfInstanceInfo().get(0).getVnfInstanceId()); + Assert.assertEquals("vnfInstanceName", response.getVnfInstanceInfo().get(0).getVnfInstanceName()); } } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java index aba3d88b..92561966 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImplTest.java @@ -19,10 +19,12 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.impl; import static org.mockito.Mockito.when; import java.io.IOException; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.apache.http.client.ClientProtocolException; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.InjectMocks; @@ -47,8 +49,16 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMVnfNotificationResponse; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ExtManagedVirtualLinkData; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ExtVirtualLinkData; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.NetworkAddress; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.Subscription; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VimComputeResourceFlavour; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VimInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VimSoftwareImage; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfExtCpData; import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.VnfcResourceInfo; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.entity.ZoneInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpResult; @@ -63,76 +73,294 @@ public class CbamMgmrImplTest { private String vnfInstanceId = "vnfInstanceId_001"; + private String json = "{" + + "'access_token':'1234567'," + + "'id':'id'," + + "'name':'name'," + + "'description':'description'," + + "'vnfdId':'vnfdId'," + + "'vnfProvider':'vnfProvider'," + + "'onboardedVnfPkgInfoId':'onboardedVnfPkgInfoId'," + + "'vnfProductName':'vnfProductName'" + + "}"; + + HttpResult httpResult = new HttpResult(); + private int statusCode = 200; + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); AdaptorEnv env = new AdaptorEnv(); cbamMgmr.setAdaptorEnv(env); - String json = "{\"access_token\":\"1234567\"}"; - HttpResult httpResult = new HttpResult(); - httpResult.setStatusCode(200); + httpResult.setStatusCode(statusCode); httpResult.setContent(json); when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); } @Test - public void testCreateVnf() throws ClientProtocolException, IOException + public void testCreateVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(201); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMCreateVnfRequest cbamRequest = new CBAMCreateVnfRequest(); + CBAMCreateVnfResponse response = cbamMgmr.createVnf(cbamRequest); + } + + @Test + public void testCreateVnfError() throws ClientProtocolException, IOException { CBAMCreateVnfRequest cbamRequest = new CBAMCreateVnfRequest(); CBAMCreateVnfResponse response = cbamMgmr.createVnf(cbamRequest); } @Test - public void testInstantiateVnf() throws ClientProtocolException, IOException + public void testInstantiateVnfSucess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMInstantiateVnfRequest cbamRequest = new CBAMInstantiateVnfRequest(); + cbamRequest.setFlavourId("flavourId"); + cbamRequest.setGrantlessMode(false); + + VimInfo vimInfo = new VimInfo(); + vimInfo.setId("id"); + vimInfo.setInterfaceEndpoint("interfaceEndpoint"); + + List vims = new ArrayList<>(); + vims.add(vimInfo); + cbamRequest.setVims(vims); + + cbamRequest.setInstantiationLevelId("instantiationLevelId"); + + ExtVirtualLinkData linkData = new ExtVirtualLinkData(); + linkData.setExtVirtualLinkId("extVirtualLinkId"); + linkData.setResourceId("resourceId"); + linkData.setVimId("vimId"); + + List extCps = new ArrayList<>(); + VnfExtCpData vnfExtCpData = new VnfExtCpData(); + vnfExtCpData.setCpdId("cpdId"); + vnfExtCpData.setNumDynamicAddresses(10000); + List addresses = new ArrayList<>(); + NetworkAddress address = new NetworkAddress(); + address.setIp("ip"); + address.setMac("mac"); + address.setSubnetId("subnetId"); + addresses.add(address); + vnfExtCpData.setAddresses(addresses ); + + extCps.add(vnfExtCpData); + linkData.setExtCps(extCps); + + List extVirtualLinks = new ArrayList<>(); + extVirtualLinks.add(linkData); + cbamRequest.setExtVirtualLinks(extVirtualLinks); + + + List managedVirtualLinks = new ArrayList<>(); + ExtManagedVirtualLinkData managedVirtualLink = new ExtManagedVirtualLinkData(); + managedVirtualLink.setResourceId("resourceId"); + managedVirtualLink.setExtManagedVirtualLinkId("extManagedVirtualLinkId"); + managedVirtualLink.setVimId("vimId"); + managedVirtualLink.setVirtualLinkDescId("virtualLinkDescId"); + managedVirtualLinks.add(managedVirtualLink ); + + cbamRequest.setExtManagedVirtualLinks(managedVirtualLinks); + + + List softwareImages = new ArrayList<>(); + VimSoftwareImage vimSoftwareImage = new VimSoftwareImage(); + vimSoftwareImage.setResourceId("resourceId"); + vimSoftwareImage.setVimId("vimId"); + vimSoftwareImage.setVnfdSoftwareImageId("vnfdSoftwareImageId"); + softwareImages.add(vimSoftwareImage); + cbamRequest.setSoftwareImages(softwareImages); + + + List computeResourceFlavours = new ArrayList<>(); + VimComputeResourceFlavour computeResourceFlavour = new VimComputeResourceFlavour(); + computeResourceFlavour.setResourceId("resourceId"); + computeResourceFlavour.setVimId("vimId"); + computeResourceFlavour.setVnfdVirtualComputeDescId("vnfdVirtualComputeDescId"); + computeResourceFlavours.add(computeResourceFlavour); + cbamRequest.setComputeResourceFlavours(computeResourceFlavours); + + List zoneInfos = new ArrayList<>(); + ZoneInfo zoneInfo = new ZoneInfo(); + zoneInfo.setResourceId("resourceId"); + zoneInfo.setId("id"); + zoneInfos.add(zoneInfo); + cbamRequest.setZones(zoneInfos); + + cbamRequest.setAdditionalParams("additionalParams"); + + CBAMInstantiateVnfResponse response = cbamMgmr.instantiateVnf(cbamRequest, vnfInstanceId); + + Assert.assertEquals("result is ", "instantiationLevelId", cbamRequest.getInstantiationLevelId()); + Assert.assertEquals("result is ", "flavourId", cbamRequest.getFlavourId()); + Assert.assertEquals("result is ", false, cbamRequest.isGrantlessMode()); + Assert.assertEquals("result is ", "id", cbamRequest.getVims().get(0).getId()); + Assert.assertEquals("result is ", "interfaceEndpoint", cbamRequest.getVims().get(0).getInterfaceEndpoint()); + + Assert.assertEquals("result is ", "extVirtualLinkId", cbamRequest.getExtVirtualLinks().get(0).getExtVirtualLinkId()); + Assert.assertEquals("result is ", "resourceId", cbamRequest.getExtVirtualLinks().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getExtVirtualLinks().get(0).getVimId()); + + Assert.assertEquals("result is ", "cpdId", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getCpdId()); + Assert.assertEquals("result is ", "ip", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getAddresses().get(0).getIp()); + Assert.assertEquals("result is ", "mac", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getAddresses().get(0).getMac()); + Assert.assertEquals("result is ", "subnetId", cbamRequest.getExtVirtualLinks().get(0).getExtCps().get(0).getAddresses().get(0).getSubnetId()); + + Assert.assertEquals("result is ", "extManagedVirtualLinkId", cbamRequest.getExtManagedVirtualLinks().get(0).getExtManagedVirtualLinkId()); + Assert.assertEquals("result is ", "resourceId", cbamRequest.getExtManagedVirtualLinks().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getExtManagedVirtualLinks().get(0).getVimId()); + Assert.assertEquals("result is ", "virtualLinkDescId", cbamRequest.getExtManagedVirtualLinks().get(0).getVirtualLinkDescId()); + + Assert.assertEquals("result is ", "resourceId", cbamRequest.getSoftwareImages().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getSoftwareImages().get(0).getVimId()); + Assert.assertEquals("result is ", "vnfdSoftwareImageId", cbamRequest.getSoftwareImages().get(0).getVnfdSoftwareImageId()); + + Assert.assertEquals("result is ", "resourceId", cbamRequest.getComputeResourceFlavours().get(0).getResourceId()); + Assert.assertEquals("result is ", "vimId", cbamRequest.getComputeResourceFlavours().get(0).getVimId()); + Assert.assertEquals("result is ", "vnfdVirtualComputeDescId", cbamRequest.getComputeResourceFlavours().get(0).getVnfdVirtualComputeDescId()); + + Assert.assertEquals("result is ", "id", cbamRequest.getZones().get(0).getId()); + Assert.assertEquals("result is ", "resourceId", cbamRequest.getZones().get(0).getResourceId()); + + Assert.assertEquals("result is ", "additionalParams", cbamRequest.getAdditionalParams()); + } + + @Test + public void testInstantiateVnfError() throws ClientProtocolException, IOException { CBAMInstantiateVnfRequest cbamRequest = new CBAMInstantiateVnfRequest(); CBAMInstantiateVnfResponse response = cbamMgmr.instantiateVnf(cbamRequest, vnfInstanceId); } @Test - public void testModifyVnf() throws ClientProtocolException, IOException + public void testModifyVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + + CBAMModifyVnfRequest cbamRequest = new CBAMModifyVnfRequest(); + CBAMModifyVnfResponse response = cbamMgmr.modifyVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testModifyVnfError() throws ClientProtocolException, IOException { CBAMModifyVnfRequest cbamRequest = new CBAMModifyVnfRequest(); CBAMModifyVnfResponse response = cbamMgmr.modifyVnf(cbamRequest, vnfInstanceId); } @Test - public void testTerminateVnf() throws ClientProtocolException, IOException + public void testTerminateVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest(); + CBAMTerminateVnfResponse response = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testTerminateVnfError() throws ClientProtocolException, IOException { CBAMTerminateVnfRequest cbamRequest = new CBAMTerminateVnfRequest(); CBAMTerminateVnfResponse response = cbamMgmr.terminateVnf(cbamRequest, vnfInstanceId); } @Test - public void testDeleteVnf() throws ClientProtocolException, IOException + public void testDeleteVnfSuccess() throws ClientProtocolException, IOException { + httpResult.setStatusCode(204); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + cbamMgmr.deleteVnf(vnfInstanceId); } @Test - public void testScaleVnf() throws ClientProtocolException, IOException + public void testDeleteVnfError() throws ClientProtocolException, IOException { + cbamMgmr.deleteVnf(vnfInstanceId); + } + + @Test + public void testScaleVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + CBAMScaleVnfRequest cbamRequest = new CBAMScaleVnfRequest(); CBAMScaleVnfResponse response = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId); } @Test - public void testHealVnf() throws ClientProtocolException, IOException + public void testScaleVnfError() throws ClientProtocolException, IOException + { + CBAMScaleVnfRequest cbamRequest = new CBAMScaleVnfRequest(); + CBAMScaleVnfResponse response = cbamMgmr.scaleVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testHealVnfSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMHealVnfRequest cbamRequest = new CBAMHealVnfRequest(); + CBAMHealVnfResponse response = cbamMgmr.healVnf(cbamRequest, vnfInstanceId); + } + + @Test + public void testHealVnfError() throws ClientProtocolException, IOException { CBAMHealVnfRequest cbamRequest = new CBAMHealVnfRequest(); CBAMHealVnfResponse response = cbamMgmr.healVnf(cbamRequest, vnfInstanceId); } + @Test + public void testQueryVnfSuccess() throws ClientProtocolException, IOException + { + CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId); + } + @Test public void testQueryVnf() throws ClientProtocolException, IOException { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + CBAMQueryVnfResponse response = cbamMgmr.queryVnf(vnfInstanceId); } @Test - public void testCreateSubscription() throws ClientProtocolException, IOException + public void testCreateSubscriptionSuccess() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(201); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + CBAMCreateSubscriptionRequest cbamRequest = new CBAMCreateSubscriptionRequest(); + CBAMCreateSubscriptionResponse response = cbamMgmr.createSubscription(cbamRequest); + } + + @Test + public void testCreateSubscriptionError() throws ClientProtocolException, IOException { CBAMCreateSubscriptionRequest cbamRequest = new CBAMCreateSubscriptionRequest(); CBAMCreateSubscriptionResponse response = cbamMgmr.createSubscription(cbamRequest); @@ -146,14 +374,25 @@ public class CbamMgmrImplTest { } @Test - public void testGetSubscription() throws ClientProtocolException, IOException + public void testGetSubscriptionSuccess() throws ClientProtocolException, IOException { String subscriptionId = "subscriptionId_001"; Subscription response = cbamMgmr.getSubscription(subscriptionId); } @Test - public void testQueryVnfcResource() throws ClientProtocolException, IOException + public void testGetSubscriptionError() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + String subscriptionId = "subscriptionId_001"; + Subscription response = cbamMgmr.getSubscription(subscriptionId); + } + + @Test + public void testQueryVnfcResourceSuccess() throws ClientProtocolException, IOException { String json = "[{'id':'id_001'}]"; HttpResult httpResult = new HttpResult(); @@ -165,15 +404,62 @@ public class CbamMgmrImplTest { } @Test - public void testQueryOperExecution() throws ClientProtocolException, IOException + public void testQueryVnfcResourceErrot() throws ClientProtocolException, IOException { + String json = "[{'id':'id_001'}]"; + HttpResult httpResult = new HttpResult(); + httpResult.setStatusCode(400); + httpResult.setContent(json); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + List response = cbamMgmr.queryVnfcResource(vnfInstanceId); + } + + @Test + public void testQueryOperExecutionSuccess() throws ClientProtocolException, IOException + { + String execId = "execId_001"; + CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); + } + + @Test + public void testQueryOperExecutionOngoing() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(202); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + String execId = "execId_001"; CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); } @Test - public void testUploadVnfPackage() throws ClientProtocolException, IOException + public void testQueryOperExecutionError() throws ClientProtocolException, IOException { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + + + String execId = "execId_001"; + CBAMQueryOperExecutionResponse response = cbamMgmr.queryOperExecution(execId); + } + + @Test + public void testUploadVnfPackageSuccess() throws ClientProtocolException, IOException + { + String cbamPackageFilePath = "cbamPackageFilePath_001"; + cbamMgmr.uploadVnfPackage(cbamPackageFilePath); + } + + @Test + public void testUploadVnfPackageError() throws ClientProtocolException, IOException + { + httpResult.setStatusCode(400); + + when(httpClientProcessor.process(Mockito.anyString(), Mockito.any(RequestMethod.class), Mockito.any(HashMap.class), Mockito.anyString())).thenReturn(httpResult); + String cbamPackageFilePath = "cbamPackageFilePath_001"; cbamMgmr.uploadVnfPackage(cbamPackageFilePath); } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java index 82e06dfe..97659a7b 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/vnfmdriver/controller/VnfmDriverControllerTest.java @@ -22,6 +22,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import javax.servlet.http.HttpServletResponse; + import org.apache.http.HttpStatus; import org.json.JSONObject; import org.junit.Assert; @@ -32,8 +34,9 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.db.repository.VnfmJobExecutionRepository; import org.onap.vfc.nfvo.driver.vnfm.svnfm.exception.VnfmDriverException; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionRequest; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.CreateSubscriptionResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfRequest; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.HealVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.vnfmdriver.bo.InstantiateVnfRequest; @@ -239,6 +242,7 @@ public class VnfmDriverControllerTest { Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); } + @Test public void testHealVnf() throws Exception { HealVnfResponse mockResponse = new HealVnfResponse(); @@ -279,5 +283,27 @@ public class VnfmDriverControllerTest { Assert.assertEquals("Error Message is ", exception.getMessage(), erroMsg); } + + @Test + public void testCreateSubscripiton() throws Exception { + CreateSubscriptionResponse mockResponse = new CreateSubscriptionResponse(); + mockResponse.setCallbackUri("callbackUri"); + String jsonString = "{\"callbackUri\":\"callbackUri\",\"callbackUri\":\"callbackUrl\"," + "\"authentication\":{\"userName\":\"userName\",\"password\":\"password\",\"clientName\":\"clientName\"}}"; + + when(vnfmDriverMgmr.createSubscription(Mockito.any(CreateSubscriptionRequest.class))).thenReturn(mockResponse); + + String responseString = mockMvc.perform( + post("/api/nokiavnfmdriver/v1/createSubscripiton"). + characterEncoding("UTF-8"). + accept(MediaType.APPLICATION_JSON). + contentType(MediaType.APPLICATION_JSON). + content(jsonString)) + .andDo(print()) + .andExpect(status().isCreated()) + .andReturn().getResponse().getContentAsString(); + + JSONObject jsonObj = new JSONObject(responseString); + Assert.assertEquals("jobId is ", mockResponse.getCallbackUri(), jsonObj.get("callbackUri")); + } } -- cgit 1.2.3-korg