summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java19
-rw-r--r--src/main/java/org/onap/so/adapters/nssmf/rest/NssmfAdapterRest.java145
-rw-r--r--src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java549
-rw-r--r--src/main/java/org/onap/so/adapters/nssmf/rest/TrustAllHostNameVerifier.java33
-rw-r--r--src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java400
-rw-r--r--src/test/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterControllerTest.java132
-rw-r--r--src/test/java/org/onap/so/adapters/nssmf/entity/RestResponseTest.java59
-rw-r--r--src/test/java/org/onap/so/adapters/nssmf/exceptions/ApplicationExceptionTest.java40
-rw-r--r--src/test/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImplTest.java271
-rw-r--r--src/test/java/org/onap/so/adapters/nssmf/util/RestUtilTest.java161
10 files changed, 646 insertions, 1163 deletions
diff --git a/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java b/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
index 20ad3d1..0f4352d 100644
--- a/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
+++ b/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java
@@ -124,8 +124,23 @@ public class ExternalAnNssmfManager extends ExternalNssmfManager {
@Override
public RestResponse activateNssi(NssmfAdapterNBIRequest nbiRequest, String snssai) throws ApplicationException {
- // TODO
- return null;
+ NssiResponse resp = new NssiResponse();
+ String nssiId = nbiRequest.getActDeActNssi().getNssiId();
+ resp.setJobId(UUID.randomUUID().toString());
+ resp.setNssiId(nssiId);
+
+ RestResponse returnRsp = new RestResponse();
+
+ returnRsp.setStatus(202);
+ returnRsp.setResponseContent(marshal(resp));
+
+ ResourceOperationStatus status =
+ new ResourceOperationStatus(serviceInfo.getNsiId(), resp.getJobId(), serviceInfo.getServiceUuid());
+ status.setResourceInstanceID(nssiId);
+ status.setOperType(actionType.toString());
+
+ updateDbStatus(status, returnRsp.getStatus(), JobStatus.FINISHED, NssmfAdapterUtil.getStatusDesc(actionType));
+ return returnRsp;
}
@Override
diff --git a/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfAdapterRest.java b/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfAdapterRest.java
deleted file mode 100644
index 4fdcbf1..0000000
--- a/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfAdapterRest.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * 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.so.adapters.nssmf.rest;
-
-import org.onap.so.adapters.nssmf.entity.RestResponse;
-import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
-import org.onap.so.beans.nsmf.JobStatusRequest;
-import org.onap.so.beans.nsmf.NssiActDeActRequest;
-import org.onap.so.beans.nsmf.NssiAllocateRequest;
-import org.onap.so.beans.nsmf.NssiCreateRequest;
-import org.onap.so.beans.nsmf.NssiDeAllocateRequest;
-import org.onap.so.beans.nsmf.NssiTerminateRequest;
-import org.onap.so.beans.nsmf.NssiUpdateRequest;
-import org.onap.so.beans.nsmf.NssiUpdateRequestById;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.assertObjectNotNull;
-
-@Deprecated
-@Controller
-@RequestMapping(value = "/api/rest/provMns/v1", produces = {APPLICATION_JSON}, consumes = {APPLICATION_JSON})
-public class NssmfAdapterRest {
-
- private static final Logger logger = LoggerFactory.getLogger(NssmfAdapterRest.class);
-
- @Autowired
- private NssmfManager nssmfMgr;
-
-
- @PostMapping(value = "/NSS/nssi")
- public ResponseEntity createNssi(@RequestBody NssiCreateRequest create) {
- try {
- logger.info("Nssmf create request is invoked");
- assertObjectNotNull(create);
- RestResponse rsp = getNssmfMgr().createNssi(create);
- return buildResponse(rsp);
- } catch (ApplicationException e) {
- return e.buildErrorResponse();
- }
- }
-
- @PostMapping(value = "/NSS/nssi/{nssiId}")
- public ResponseEntity terminateNssi(@RequestBody NssiTerminateRequest terminate,
- @PathVariable("nssiId") String nssiId) {
- try {
- logger.info("Nssmf terminate request is invoked");
- assertObjectNotNull(terminate);
- RestResponse rsp = getNssmfMgr().terminateNssi(terminate, nssiId);
- return buildResponse(rsp);
- } catch (ApplicationException e) {
- return e.buildErrorResponse();
- }
- }
-
- @PutMapping(value = "/NSS/SliceProfiles/{sliceProfileId}")
- public ResponseEntity modifyNssi(@RequestBody NssiUpdateRequest update,
- @PathVariable("sliceProfileId") String sliceId) {
- try {
- logger.info("Nssmf modify request is invoked");
- assertObjectNotNull(update);
- RestResponse rsp = getNssmfMgr().updateNssi(update, sliceId);
- return buildResponse(rsp);
- } catch (ApplicationException e) {
- return e.buildErrorResponse();
- }
- }
-
- @PutMapping(value = "/NSS/nssi/{nssiId}")
- public ResponseEntity modifyNssiById(@RequestBody NssiUpdateRequestById updateById,
- @PathVariable("nssiId") String nssiId) {
- try {
- logger.info("Nssmf modify by ID request is invoked");
- assertObjectNotNull(updateById);
- RestResponse rsp = getNssmfMgr().updateNssiById(updateById, nssiId);
- return buildResponse(rsp);
- } catch (ApplicationException e) {
- return e.buildErrorResponse();
- }
- }
-
-
- @GetMapping(value = "/vendor/{vendorName}/type/{networkType}/NSS" + "/SliceProfiles/{sliceProfileId}")
- public ResponseEntity queryNssi(@PathVariable("vendorName") String vendorName,
- @PathVariable("networktype") String networkType, @PathVariable("sliceProfileId") String sliceId) {
- try {
- logger.info("Nssmf query nssi request is invoked");
- RestResponse rsp = getNssmfMgr().queryNssi(vendorName, networkType, sliceId);
- return buildResponse(rsp);
- } catch (ApplicationException e) {
- return e.buildErrorResponse();
- }
- }
-
- @GetMapping(value = "/vendor/{vendorName}/type/{networkType}/NSS/nssi" + "/{nssiId}")
- public ResponseEntity queryNssiById(@PathVariable("vendorName") String vendorName,
- @PathVariable("networkTtype") String networkType, @PathVariable("nssiId") String nssiId) {
- try {
- logger.info("Nssmf query nssi by ID request is invoked");
- RestResponse rsp = getNssmfMgr().queryNssiById(vendorName, networkType, nssiId);
- return buildResponse(rsp);
- } catch (ApplicationException e) {
- return e.buildErrorResponse();
- }
- }
-
- public void setNssmfMgr(NssmfManager nssmfMgr) {
- this.nssmfMgr = nssmfMgr;
- }
-
- public NssmfManager getNssmfMgr() {
- return nssmfMgr;
- }
-
- private ResponseEntity buildResponse(RestResponse rsp) {
- return ResponseEntity.status(rsp.getStatus()).body(rsp.getResponseContent());
- }
-}
diff --git a/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java b/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java
deleted file mode 100644
index 2d0980f..0000000
--- a/src/main/java/org/onap/so/adapters/nssmf/rest/NssmfManager.java
+++ /dev/null
@@ -1,549 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * 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.so.adapters.nssmf.rest;
-
-import org.onap.so.adapters.nssmf.entity.RestResponse;
-import org.onap.so.adapters.nssmf.enums.JobStatus;
-import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
-import org.onap.so.adapters.nssmf.util.RestUtil;
-import org.onap.so.beans.nsmf.ActDeActNssi;
-import org.onap.so.beans.nsmf.AllocateAnNssi;
-import org.onap.so.beans.nsmf.AllocateCnNssi;
-import org.onap.so.beans.nsmf.AllocateTnNssi;
-import org.onap.so.beans.nsmf.CreateCnNssi;
-import org.onap.so.beans.nsmf.DeAllocateNssi;
-import org.onap.so.beans.nsmf.EsrInfo;
-import org.onap.so.beans.nsmf.JobStatusRequest;
-import org.onap.so.beans.nsmf.JobStatusResponse;
-import org.onap.so.beans.nsmf.NetworkType;
-import org.onap.so.beans.nsmf.NssiActDeActRequest;
-import org.onap.so.beans.nsmf.NssiAllocateRequest;
-import org.onap.so.beans.nsmf.NssiCreateRequest;
-import org.onap.so.beans.nsmf.NssiDeAllocateRequest;
-import org.onap.so.beans.nsmf.NssiResponse;
-import org.onap.so.beans.nsmf.NssiTerminateRequest;
-import org.onap.so.beans.nsmf.NssiUpdateRequest;
-import org.onap.so.beans.nsmf.NssiUpdateRequestById;
-import org.onap.so.beans.nsmf.ResponseDescriptor;
-import org.onap.so.beans.nsmf.TerminateNssi;
-import org.onap.so.beans.nsmf.UpdateCnNssi;
-import org.onap.so.beans.nsmf.UpdateCnNssiById;
-import org.onap.so.db.request.beans.ResourceOperationStatus;
-import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Primary;
-import org.springframework.data.domain.Example;
-import org.springframework.stereotype.Component;
-import static java.lang.String.valueOf;
-import static org.onap.so.adapters.nssmf.enums.HttpMethod.DELETE;
-import static org.onap.so.adapters.nssmf.enums.HttpMethod.GET;
-import static org.onap.so.adapters.nssmf.enums.HttpMethod.POST;
-import static org.onap.so.adapters.nssmf.enums.HttpMethod.PUT;
-import static org.onap.so.adapters.nssmf.enums.JobStatus.ERROR;
-import static org.onap.so.adapters.nssmf.enums.JobStatus.FINISHED;
-import static org.onap.so.adapters.nssmf.enums.JobStatus.PROCESSING;
-import static org.onap.so.adapters.nssmf.enums.JobStatus.STARTED;
-import static org.onap.so.adapters.nssmf.enums.JobStatus.fromString;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.ACTIVATE_NSS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.ALLOCATE_NSS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.CREATE_NSS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.DEACTIVATE_NSS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.DEALLOCATE_NSS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.QUERY_JOB_STATUS_FAILED;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.StatusDesc.QUERY_JOB_STATUS_SUCCESS;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.assertObjectNotNull;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
-import static org.onap.so.beans.nsmf.ActDeActNssi.ACT_URL;
-import static org.onap.so.beans.nsmf.ActDeActNssi.DE_ACT_URL;
-
-@Component
-@Primary
-@Deprecated
-public class NssmfManager {
-
- private static final Logger logger = LoggerFactory.getLogger(NssmfManager.class);
-
- public final static String QUERY = "/api/rest/provMns/v1/NSS" + "/SliceProfiles/{sliceProfileId}";
-
- public final static String QUERY_BY_ID = "/api/rest/provMns/v1/NSS/nssi" + "/{nssiId}";
-
- @Autowired
- private ResourceOperationStatusRepository rscOperStatusRepo;
-
- @Autowired
- private RestUtil restUtil;
-
-
- public RestResponse allocateNssi(NssiAllocateRequest nssmiAllocate) throws ApplicationException {
-
- assertObjectNotNull(nssmiAllocate.getEsrInfo());
- assertObjectNotNull(nssmiAllocate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssmiAllocate.getEsrInfo().getVendor());
-
- String nsiId = null;
- String allocateReq = null;
- String allocateUrl = null;
- logger.info("Allocate Nssi for " + nssmiAllocate.getEsrInfo().getNetworkType() + " Network has begun");
-
- switch (nssmiAllocate.getEsrInfo().getNetworkType()) {
-
- case CORE:
- AllocateCnNssi cn = nssmiAllocate.getAllocateCnNssi();
- assertObjectNotNull(cn);
- assertObjectNotNull(cn.getNsiInfo());
- assertObjectNotNull(cn.getNsiInfo().getNsiId());
- nsiId = cn.getNsiInfo().getNsiId();
- assertObjectNotNull(nsiId);
- allocateReq = marshal(cn);
- allocateUrl = AllocateCnNssi.URL;
- break;
-
- case ACCESS:
- AllocateAnNssi an = nssmiAllocate.getAllocateAnNssi();
- assertObjectNotNull(an);
- assertObjectNotNull(an.getNsiInfo());
- assertObjectNotNull(an.getNsiInfo().getNsiId());
- nsiId = an.getNsiInfo().getNsiId();
- assertObjectNotNull(nsiId);
- allocateReq = marshal(an);
- allocateUrl = AllocateAnNssi.URL;
- break;
-
- case TRANSPORT:
- AllocateTnNssi tn = nssmiAllocate.getAllocateTnNssi();
- assertObjectNotNull(tn);
- // assertObjectNotNull(tn.getNsiInfo());
- // assertObjectNotNull(tn.getNsiInfo().getNsiId());
- // nsiId = tn.getNsiInfo().getNsiId();
- allocateReq = marshal(tn);
- // allocateUrl = AllocateTnNssi.URL;
- break;
-
- }
-
- RestResponse rsp = restUtil.sendRequest(allocateUrl, POST, allocateReq, nssmiAllocate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse allocateRes = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status =
- new ResourceOperationStatus(allocateRes.getNssiId(), allocateRes.getJobId(), nsiId);
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, ALLOCATE_NSS_SUCCESS);
- logger.info("save segment and operation info -> end");
- }
- return rsp;
- }
-
-
-
- public RestResponse createNssi(NssiCreateRequest nssiCreate) throws ApplicationException {
-
- assertObjectNotNull(nssiCreate.getEsrInfo());
- assertObjectNotNull(nssiCreate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiCreate.getEsrInfo().getVendor());
-
- String nsiId = null;
- String createReq = null;
- String createUrl = null;
- logger.info("Create Nssi for " + nssiCreate.getEsrInfo().getNetworkType() + " Network has begun");
-
- switch (nssiCreate.getEsrInfo().getNetworkType()) {
- case CORE:
- CreateCnNssi cn = nssiCreate.getCreateCnNssi();
- nsiId = cn.getNsiInfo().getNsiId();
- assertObjectNotNull(nsiId);
- createReq = marshal(cn);
- createUrl = AllocateCnNssi.URL;
- break;
-
- case ACCESS:
- case TRANSPORT:
- throw new ApplicationException(1, "Create Nssi doesn't " + "support the Network type:"
- + nssiCreate.getEsrInfo().getNetworkType());
- }
- RestResponse rsp = restUtil.sendRequest(createUrl, POST, createReq, nssiCreate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse allocateRes = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status =
- new ResourceOperationStatus(allocateRes.getNssiId(), allocateRes.getJobId(), nsiId);
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, CREATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- @Deprecated
- public RestResponse deAllocateNssi(NssiDeAllocateRequest nssiDeallocate, String sliceId)
- throws ApplicationException {
-
- assertObjectNotNull(nssiDeallocate.getEsrInfo());
- assertObjectNotNull(nssiDeallocate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiDeallocate.getEsrInfo().getVendor());
-
- DeAllocateNssi deAllocate = nssiDeallocate.getDeAllocateNssi();
-
- assertObjectNotNull(sliceId);
- assertObjectNotNull(deAllocate.getNssiId());
- assertObjectNotNull(deAllocate.getNsiId());
-
- String deallocateUrl = formTnAndAnUrl(nssiDeallocate.getEsrInfo(), DeAllocateNssi.URL, sliceId);
- String deAllocateReq = marshal(deAllocate);
-
- logger.info("Deallocate Nssi has begun");
-
- RestResponse rsp = restUtil.sendRequest(deallocateUrl, DELETE, deAllocateReq, nssiDeallocate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse res = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status =
- new ResourceOperationStatus(deAllocate.getNssiId(), res.getJobId(), deAllocate.getNsiId());
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, DEALLOCATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- private String formTnAndAnUrl(EsrInfo esrInfo, String origUrl, String variable) {
-
- origUrl = formatUrl(origUrl, variable);
- String[] val;
-
- switch (esrInfo.getNetworkType()) {
-
- case TRANSPORT:
- val = origUrl.split("v1");
- return val[0] + "v1/tn" + val[1];
-
- case ACCESS:
- val = origUrl.split("v1");
- return val[0] + "v1/an" + val[1];
-
- case CORE:
- return origUrl;
- }
- return origUrl;
- }
-
- private String formatUrl(String origUrl, String variable) {
-
- if (variable != null) {
- origUrl = String.format(origUrl, variable);
- }
- return origUrl;
- }
-
-
- public RestResponse terminateNssi(NssiTerminateRequest nssiTerminate, String nssiId) throws ApplicationException {
-
- assertObjectNotNull(nssiTerminate.getEsrInfo());
- assertObjectNotNull(nssiTerminate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiTerminate.getEsrInfo().getVendor());
-
- TerminateNssi terminate = nssiTerminate.getTerminateNssi();
-
- assertObjectNotNull(nssiId);
- assertObjectNotNull(terminate.getNsiId());
-
- logger.info("Terminate Nssi has begun");
-
- String terminateUrl = formTnAndAnUrl(nssiTerminate.getEsrInfo(), TerminateNssi.URL, nssiId);
- String terminateReq = marshal(terminate);
-
- RestResponse rsp = restUtil.sendRequest(terminateUrl, DELETE, terminateReq, nssiTerminate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse res = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status = new ResourceOperationStatus(nssiId, res.getJobId(), terminate.getNsiId());
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, DEALLOCATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- public RestResponse activateNssi(NssiActDeActRequest nssiActivate, String snssai) throws ApplicationException {
-
- assertObjectNotNull(nssiActivate.getEsrInfo());
- assertObjectNotNull(nssiActivate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiActivate.getEsrInfo().getVendor());
-
- ActDeActNssi activate = nssiActivate.getActDeActNssi();
-
- assertObjectNotNull(snssai);
- assertObjectNotNull(activate.getNssiId());
- assertObjectNotNull(activate.getNsiId());
-
- logger.info("Activate Nssi has begun");
-
- String activateUrl = formTnAndAnUrl(nssiActivate.getEsrInfo(), ACT_URL, snssai);
- String activateReq = marshal(activate);
-
- RestResponse rsp = restUtil.sendRequest(activateUrl, PUT, activateReq, nssiActivate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse activateRes = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status =
- new ResourceOperationStatus(activate.getNssiId(), activateRes.getJobId(), activate.getNsiId());
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, ACTIVATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- public RestResponse deActivateNssi(NssiActDeActRequest nssiDeActivate, String snssai) throws ApplicationException {
-
- assertObjectNotNull(nssiDeActivate.getEsrInfo());
- assertObjectNotNull(nssiDeActivate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiDeActivate.getEsrInfo().getVendor());
-
- logger.info("Deactivate Nssi has begun");
-
- ActDeActNssi deActivate = nssiDeActivate.getActDeActNssi();
-
- assertObjectNotNull(snssai);
- assertObjectNotNull(deActivate.getNssiId());
- assertObjectNotNull(deActivate.getNsiId());
-
- String deActivateUrl = formTnAndAnUrl(nssiDeActivate.getEsrInfo(), DE_ACT_URL, snssai);
- String deActivateReq = marshal(deActivate);
-
- RestResponse rsp = restUtil.sendRequest(deActivateUrl, PUT, deActivateReq, nssiDeActivate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse deActivateRes = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status = new ResourceOperationStatus(deActivate.getNssiId(),
- deActivateRes.getJobId(), deActivate.getNsiId());
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, DEACTIVATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- public RestResponse queryJobStatus(JobStatusRequest jobReq, String jobId) throws ApplicationException {
-
- assertObjectNotNull(jobReq.getEsrInfo());
- assertObjectNotNull(jobReq.getEsrInfo().getNetworkType());
- assertObjectNotNull(jobReq.getEsrInfo().getVendor());
- assertObjectNotNull(jobId);
- assertObjectNotNull(jobReq.getNssiId());
- assertObjectNotNull(jobReq.getNsiId());
-
- logger.info("Query job status has begun");
-
- ResourceOperationStatus status = new ResourceOperationStatus(jobReq.getNssiId(), jobId, jobReq.getNsiId());
- status = rscOperStatusRepo.findOne(Example.of(status))
- .orElseThrow(() -> new ApplicationException(404, "Cannot Find Operation Status"));
-
- String statusUrl = formatUrl(JobStatusRequest.URL, jobId);
- if (jobReq.getResponseId() != null) {
- statusUrl = statusUrl + "?responseId=" + jobReq.getResponseId();
- }
-
- RestResponse rsp = restUtil.sendRequest(statusUrl, GET, "", jobReq.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (!valueOf(rsp.getStatus()).startsWith("2")) {
- updateDbStatus(status, rsp.getStatus(), ERROR, QUERY_JOB_STATUS_FAILED);
- throw new ApplicationException(500, QUERY_JOB_STATUS_FAILED);
- }
-
- ResponseDescriptor rspDesc =
- unMarshal(rsp.getResponseContent(), JobStatusResponse.class).getResponseDescriptor();
- logger.info("save segment and operaton info -> begin");
- updateRequestDbJobStatus(rspDesc, status, rsp);
- logger.info("save segment and operaton info -> end");
- return rsp;
- }
-
-
- public RestResponse updateNssi(NssiUpdateRequest nssiUpdate, String sliceId) throws ApplicationException {
-
- assertObjectNotNull(nssiUpdate.getEsrInfo());
- assertObjectNotNull(nssiUpdate.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiUpdate.getEsrInfo().getVendor());
- assertObjectNotNull(sliceId);
-
- String nsiId = null;
- String nssiId = null;
- String updateReq = null;
- String updateUrl = null;
- logger.info("Update Nssi for " + nssiUpdate.getEsrInfo().getNetworkType() + " Network has begun");
-
- switch (nssiUpdate.getEsrInfo().getNetworkType()) {
- case CORE:
- UpdateCnNssi cn = nssiUpdate.getUpdateCnNssi();
- nsiId = cn.getNsiInfo().getNsiId();
- nssiId = cn.getNssiId();
- assertObjectNotNull(nsiId);
- assertObjectNotNull(nssiId);
- updateReq = marshal(cn);
- updateUrl = formatUrl(UpdateCnNssi.URL, sliceId);
- break;
-
- case ACCESS:
- case TRANSPORT:
- throw new ApplicationException(1, "Update Nssi doesn't " + "support the Network type:"
- + nssiUpdate.getEsrInfo().getNetworkType());
- }
-
- RestResponse rsp = restUtil.sendRequest(updateUrl, PUT, updateReq, nssiUpdate.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse allocateRes = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status = new ResourceOperationStatus(nssiId, allocateRes.getJobId(), nsiId);
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, ALLOCATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- public RestResponse updateNssiById(NssiUpdateRequestById nssiUpdateById, String nssiId)
- throws ApplicationException {
-
- assertObjectNotNull(nssiUpdateById.getEsrInfo());
- assertObjectNotNull(nssiUpdateById.getEsrInfo().getNetworkType());
- assertObjectNotNull(nssiUpdateById.getEsrInfo().getVendor());
- assertObjectNotNull(nssiId);
-
- String nsiId = null;
- String updateReq = null;
- String updateUrl = null;
- logger.info("Update Nssi by ID for " + nssiUpdateById.getEsrInfo().getNetworkType() + " Network has begun");
-
- switch (nssiUpdateById.getEsrInfo().getNetworkType()) {
- case CORE:
- UpdateCnNssiById cn = nssiUpdateById.getUpdateCnNssiById();
- nsiId = cn.getNsiInfo().getNsiId();
- assertObjectNotNull(nsiId);
- updateReq = marshal(cn);
- updateUrl = formatUrl(UpdateCnNssiById.URL, nssiId);
- break;
-
- case ACCESS:
- case TRANSPORT:
- throw new ApplicationException(1, "Update Nssi doesn't " + "support the Network type:"
- + nssiUpdateById.getEsrInfo().getNetworkType());
- }
-
- RestResponse rsp = restUtil.sendRequest(updateUrl, PUT, updateReq, nssiUpdateById.getEsrInfo());
- assertObjectNotNull(rsp);
-
- if (valueOf(rsp.getStatus()).startsWith("2")) {
- NssiResponse allocateRes = unMarshal(rsp.getResponseContent(), NssiResponse.class);
-
- ResourceOperationStatus status = new ResourceOperationStatus(nssiId, allocateRes.getJobId(), nsiId);
- logger.info("save segment and operaton info -> begin");
- updateDbStatus(status, rsp.getStatus(), STARTED, ALLOCATE_NSS_SUCCESS);
- logger.info("save segment and operaton info -> end");
- }
- return rsp;
- }
-
- public RestResponse queryNssi(String vendor, String type, String sliceId) throws ApplicationException {
-
- logger.info("Query Nssi has begun");
- String getUrl = formatUrl(QUERY, sliceId);
- EsrInfo esr = new EsrInfo();
- esr.setVendor(vendor);
- esr.setNetworkType(NetworkType.valueOf(type));
- RestResponse rsp = restUtil.sendRequest(getUrl, GET, "", esr);
- assertObjectNotNull(rsp);
- return rsp;
- }
-
- public RestResponse queryNssiById(String vendor, String type, String nssiId) throws ApplicationException {
-
- logger.info("Query Nssi by ID has begun");
- String getUrl = formatUrl(QUERY_BY_ID, nssiId);
- EsrInfo esr = new EsrInfo();
- esr.setVendor(vendor);
- esr.setNetworkType(NetworkType.valueOf(type));
- RestResponse rsp = restUtil.sendRequest(getUrl, GET, "", esr);
- assertObjectNotNull(rsp);
- return rsp;
- }
-
- private void updateRequestDbJobStatus(ResponseDescriptor rspDesc, ResourceOperationStatus status, RestResponse rsp)
- throws ApplicationException {
-
- switch (fromString(rspDesc.getStatus())) {
-
- case STARTED:
- updateDbStatus(status, rsp.getStatus(), STARTED, QUERY_JOB_STATUS_SUCCESS);
- break;
-
- case ERROR:
- updateDbStatus(status, rsp.getStatus(), ERROR, QUERY_JOB_STATUS_FAILED);
- throw new ApplicationException(500, QUERY_JOB_STATUS_FAILED);
-
- case FINISHED:
- if (rspDesc.getProgress() == 100) {
- updateDbStatus(status, rsp.getStatus(), FINISHED, QUERY_JOB_STATUS_SUCCESS);
- }
- break;
-
- case PROCESSING:
- updateDbStatus(status, rsp.getStatus(), PROCESSING, QUERY_JOB_STATUS_SUCCESS);
- break;
- }
- }
-
- private void updateDbStatus(ResourceOperationStatus status, int rspStatus, JobStatus jobStatus,
- String description) {
- status.setErrorCode(valueOf(rspStatus));
- status.setStatus(jobStatus.toString());
- status.setStatusDescription(description);
- logger.info("Updating DB status");
- rscOperStatusRepo.save(status);
- logger.info("Updating successful");
- }
-
- public void setRscOperStatusRepo(ResourceOperationStatusRepository rscOperStatusRepo) {
- this.rscOperStatusRepo = rscOperStatusRepo;
- }
-
- public void setRestUtil(RestUtil restUtil) {
- this.restUtil = restUtil;
- }
-}
diff --git a/src/main/java/org/onap/so/adapters/nssmf/rest/TrustAllHostNameVerifier.java b/src/main/java/org/onap/so/adapters/nssmf/rest/TrustAllHostNameVerifier.java
deleted file mode 100644
index fc0f3dd..0000000
--- a/src/main/java/org/onap/so/adapters/nssmf/rest/TrustAllHostNameVerifier.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * 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.so.adapters.nssmf.rest;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLSession;
-
-@Deprecated
-public class TrustAllHostNameVerifier implements HostnameVerifier {
-
- public boolean verify(String hostname, SSLSession session) {
- return true;
- }
-
-}
diff --git a/src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java b/src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java
deleted file mode 100644
index f78bfd2..0000000
--- a/src/test/java/org/onap/so/adapters/nssmf/NssmfAdapterRestTest.java
+++ /dev/null
@@ -1,400 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.
- * ================================================================================
- * 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.so.adapters.nssmf;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.when;
-import static org.mockito.MockitoAnnotations.initMocks;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
-import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
-import static org.onap.so.beans.nsmf.NetworkType.CORE;
-import static org.onap.so.beans.nsmf.ResourceSharingLevel.NON_SHARED;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.List;
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.StatusLine;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpRequestBase;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.onap.so.adapters.nssmf.entity.TokenResponse;
-import org.onap.so.adapters.nssmf.enums.HttpMethod;
-import org.onap.so.adapters.nssmf.rest.NssmfAdapterRest;
-import org.onap.so.adapters.nssmf.entity.NssmfInfo;
-import org.onap.so.adapters.nssmf.rest.NssmfManager;
-import org.onap.so.adapters.nssmf.util.RestUtil;
-import org.onap.so.beans.nsmf.ActDeActNssi;
-import org.onap.so.beans.nsmf.AllocateCnNssi;
-import org.onap.so.beans.nsmf.CnSliceProfile;
-import org.onap.so.beans.nsmf.DeAllocateNssi;
-import org.onap.so.beans.nsmf.EsrInfo;
-import org.onap.so.beans.nsmf.JobStatusRequest;
-import org.onap.so.beans.nsmf.NsiInfo;
-import org.onap.so.beans.nsmf.NssiActDeActRequest;
-import org.onap.so.beans.nsmf.NssiAllocateRequest;
-import org.onap.so.beans.nsmf.NssiDeAllocateRequest;
-import org.onap.so.beans.nsmf.NssiResponse;
-import org.onap.so.beans.nsmf.PerfReq;
-import org.onap.so.beans.nsmf.PerfReqEmbb;
-import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
-import org.skyscreamer.jsonassert.JSONAssert;
-import org.springframework.http.ResponseEntity;
-import org.springframework.test.context.junit4.SpringRunner;
-
-@RunWith(SpringRunner.class)
-public class NssmfAdapterRestTest {
-
- private final static String ALLOCATE = "{\n" + " \"esrInfo\" : {\n" + " \"vendor\" : \"huawei\",\n"
- + " \"networkType\" : \"cn\"\n" + " },\n" + " \"allocateCnNssi\" : {\n"
- + " \"nssiId\" : \"NSST-C-001-HDBNJ-NSSMF-01-A-ZX\",\n" + " \"nssiName\" : \"eMBB-001\",\n"
- + " \"sliceProfile\" : {\n" + " \"snssaiList\" : [ \"001-100001\" ],\n"
- + " \"maxNumberofPDUSession\" : 10,\n"
- + " \"sliceProfileId\" : \"ab9af40f13f721b5f13539d87484098\",\n"
- + " \"plmnIdList\" : [ \"460-00\", \"460-01\" ],\n" + " \"perfReq\" : {\n"
- + " \"perfReqEmbbList\" : [ {\n" + " \"activityFactor\" : 50\n" + " } ]\n"
- + " },\n" + " \"maxNumberofUEs\" : 200,\n"
- + " \"coverageAreaTAList\" : [ \"1\", \"2\", \"3\" ],\n" + " \"latency\" : 6,\n"
- + " \"resourceSharingLevel\" : \"non-shared\"\n" + " },\n" + " \"scriptName\" : \"CN1\",\n"
- + " \"nsiInfo\" : {\n" + " \"nsiName\" : \"eMBB-001\",\n"
- + " \"nsiId\" : \"NSI-M-001-HDBNJ-NSMF-01-A-ZX\"\n" + " }\n" + " }\n" + "}";
-
- private NssmfManager nssmfMgr;
-
- @Mock
- private ResourceOperationStatusRepository rscOperStatusRepo;
-
- @Mock
- private RestUtil restUtil;
-
- @Mock
- private NssmfAdapterRest nssmfRest;
-
- @Mock
- private HttpResponse tokenResponse;
-
- @Mock
- private HttpEntity tokenEntity;
-
- @Mock
- private HttpResponse commonResponse;
-
- @Mock
- private HttpEntity commonEntity;
-
- @Mock
- private StatusLine statusLine;
-
- @Mock
- private HttpClient httpClient;
-
- private InputStream postStream;
-
- private InputStream tokenStream;
-
- @Before
- public void setUp() {
- initMocks(this);
- nssmfMgr = new NssmfManager();
- nssmfMgr.setRestUtil(restUtil);
- nssmfMgr.setRscOperStatusRepo(rscOperStatusRepo);
- }
-
- private void createCommonMock(int statusCode, NssmfInfo nssmf) throws Exception {
- when(this.restUtil.send(any(String.class), any(HttpMethod.class), any(String.class), any(Header.class)))
- .thenCallRealMethod();
- when(this.restUtil.createResponse(any(Integer.class), any(String.class))).thenCallRealMethod();
- when(nssmfRest.getNssmfMgr()).thenReturn(nssmfMgr);
- // when(nssmfRest.createAllocateNssi(any(NssiAllocateRequest.class))).thenCallRealMethod();
- // when(nssmfRest.deAllocateNssi(any(NssiDeAllocateRequest.class), any(String.class))).thenCallRealMethod();
- // when(nssmfRest.activateNssi(any(NssiActDeActRequest.class), any(String.class))).thenCallRealMethod();
- // when(nssmfRest.deactivateNssi(any(NssiActDeActRequest.class), any(String.class))).thenCallRealMethod();
- //
- // when(nssmfRest.queryJobStatus(any(JobStatusRequest.class), any(String.class))).thenCallRealMethod();
- when(restUtil.sendRequest(any(String.class), any(HttpMethod.class), any(String.class), any(EsrInfo.class)))
- .thenCallRealMethod();
- when(restUtil.getHttpsClient()).thenReturn(httpClient);
-
- when(statusLine.getStatusCode()).thenReturn(200);
- when(restUtil.getNssmfHost(any(EsrInfo.class))).thenReturn(nssmf);
-
- when(tokenResponse.getEntity()).thenReturn(tokenEntity);
- when(tokenResponse.getStatusLine()).thenReturn(statusLine);
- when(tokenEntity.getContent()).thenReturn(tokenStream);
-
- when(commonResponse.getEntity()).thenReturn(commonEntity);
- when(commonResponse.getStatusLine()).thenReturn(statusLine);
- when(commonEntity.getContent()).thenReturn(postStream);
-
- Answer<HttpResponse> answer = new Answer<HttpResponse>() {
-
- public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
- Object[] arguments = invocation.getArguments();
- if (arguments != null && arguments.length == 1 && arguments[0] != null) {
-
- HttpRequestBase base = (HttpRequestBase) arguments[0];
- if (base.getURI().toString().endsWith("/oauth/token")) {
- return tokenResponse;
- } else {
- return commonResponse;
- }
- }
- return commonResponse;
- }
- };
- doAnswer(answer).when(httpClient).execute(any(HttpRequestBase.class));
- }
-
- // @Test
- // public void testNssiAllocate() throws Exception {
- // NssmfInfo nssmf = new NssmfInfo();
- // nssmf.setUserName("nssmf-user");
- // nssmf.setPassword("nssmf-pass");
- // nssmf.setPort("8080");
- // nssmf.setIpAddress("127.0.0.1");
- //
- // NssiResponse nssiRes = new NssiResponse();
- // nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067");
- // nssiRes.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- //
- // TokenResponse token = new TokenResponse();
- // token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39");
- // token.setExpires(1800);
- //
- // postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8));
- // tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8));
- //
- // createCommonMock(200, nssmf);
- // // assertEquals(prettyPrint(createAllocateNssi()), ALLOCATE);
- // ResponseEntity res = nssmfRest.createAllocateNssi(createAllocateNssi());
- // assertNotNull(res);
- // assertNotNull(res.getBody());
- // NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- // assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
- // assertEquals(allRes.getNssiId(), "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- // }
- //
- // @Test
- // public void testNssiDeAllocate() throws Exception {
- // NssmfInfo nssmf = new NssmfInfo();
- // nssmf.setUserName("nssmf-user");
- // nssmf.setPassword("nssmf-pass");
- // nssmf.setPort("8080");
- // nssmf.setIpAddress("127.0.0.1");
- //
- // NssiResponse nssiRes = new NssiResponse();
- // nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067");
- //
- // TokenResponse token = new TokenResponse();
- // token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39");
- // token.setExpires(1800);
- //
- // postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8));
- // tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8));
- //
- // createCommonMock(200, nssmf);
- // ResponseEntity res = nssmfRest.deAllocateNssi(deAllocateNssi(), "ab9af40f13f721b5f13539d87484098");
- // assertNotNull(res);
- // assertNotNull(res.getBody());
- // NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- // assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
- // }
- //
- // @Test
- // public void testNssiActivate() throws Exception {
- // NssmfInfo nssmf = new NssmfInfo();
- // nssmf.setUserName("nssmf-user");
- // nssmf.setPassword("nssmf-pass");
- // nssmf.setPort("8080");
- // nssmf.setIpAddress("127.0.0.1");
- //
- // NssiResponse nssiRes = new NssiResponse();
- // nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067");
- //
- // TokenResponse token = new TokenResponse();
- // token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39");
- // token.setExpires(1800);
- //
- // postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8));
- // tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8));
- //
- // createCommonMock(200, nssmf);
- // ResponseEntity res = nssmfRest.activateNssi(activateNssi(), "001-100001");
- // assertNotNull(res);
- // assertNotNull(res.getBody());
- // NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- // assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
- // }
- //
- // @Test
- // public void testNssiDeActivate() throws Exception {
- // NssmfInfo nssmf = new NssmfInfo();
- // nssmf.setUserName("nssmf-user");
- // nssmf.setPassword("nssmf-pass");
- // nssmf.setPort("8080");
- // nssmf.setIpAddress("127.0.0.1");
- //
- // NssiResponse nssiRes = new NssiResponse();
- // nssiRes.setJobId("4b45d919816ccaa2b762df5120f72067");
- //
- // TokenResponse token = new TokenResponse();
- // token.setAccessToken("7512eb3feb5249eca5ddd742fedddd39");
- // token.setExpires(1800);
- //
- // postStream = new ByteArrayInputStream(marshal(nssiRes).getBytes(UTF_8));
- // tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8));
- //
- // createCommonMock(200, nssmf);
- // ResponseEntity res = nssmfRest.deactivateNssi(deActivateNssi(), "001-100001");
- // assertNotNull(res);
- // assertNotNull(res.getBody());
- // NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- // assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
- // }
- //
- @Test
- public void testAllocateJsonSerDeSer() throws Exception {
- JSONAssert.assertEquals(marshal(allocateNssi()), ALLOCATE, false);
- NssiAllocateRequest all = unMarshal(ALLOCATE, NssiAllocateRequest.class);
- assertNotNull(all);
- assertNotNull(all.getAllocateCnNssi());
- assertNotNull(all.getAllocateCnNssi().getSliceProfile());
- assertEquals(all.getAllocateCnNssi().getSliceProfile().getResourceSharingLevel(), NON_SHARED);
- assertNotNull(all.getAllocateCnNssi().getSliceProfile().getPerfReq());
- assertNotNull(all.getAllocateCnNssi().getSliceProfile().getPerfReq().getPerfReqEmbbList());
- PerfReqEmbb embb =
- all.getAllocateCnNssi().getSliceProfile().getPerfReq().getPerfReqEmbbList().iterator().next();
- assertNotNull(embb);
- assertEquals(embb.getActivityFactor(), 50);
- }
-
- public NssiAllocateRequest allocateNssi() throws Exception {
- CnSliceProfile sP = new CnSliceProfile();
- List<String> sns = new LinkedList<>();
- sns.add("001-100001");
- List<String> plmn = new LinkedList<>();
- plmn.add("460-00");
- plmn.add("460-01");
- PerfReqEmbb embb = new PerfReqEmbb();
- embb.setActivityFactor(50);
- List<PerfReqEmbb> embbList = new LinkedList<>();
- embbList.add(embb);
- PerfReq perfReq = new PerfReq();
- perfReq.setPerfReqEmbbList(embbList);
- List<String> taList = new LinkedList<>();
- taList.add("1");
- taList.add("2");
- taList.add("3");
- sP.setSnssaiList(sns);
- sP.setSliceProfileId("ab9af40f13f721b5f13539d87484098");
- sP.setPLMNIdList(plmn);
- sP.setPerfReq(perfReq);
- sP.setMaxNumberOfUEs(200);
- sP.setCoverageAreaTAList(taList);
- sP.setLatency(6);
- sP.setResourceSharingLevel(NON_SHARED);
- sP.setMaxNumberOfPDUSession(10);
- NsiInfo nsiInfo = new NsiInfo();
- nsiInfo.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
- nsiInfo.setNsiName("eMBB-001");
- AllocateCnNssi cnNssi = new AllocateCnNssi();
- cnNssi.setNssiId("NSST-C-001-HDBNJ-NSSMF-01-A-ZX");
- cnNssi.setNssiName("eMBB-001");
- cnNssi.setScriptName("CN1");
- cnNssi.setSliceProfile(sP);
- cnNssi.setNsiInfo(nsiInfo);
- EsrInfo esrInfo = new EsrInfo();
- esrInfo.setVendor("huawei");
- esrInfo.setNetworkType(CORE);
- NssiAllocateRequest allocate = new NssiAllocateRequest();
- allocate.setAllocateCnNssi(cnNssi);
- allocate.setEsrInfo(esrInfo);
- return allocate;
- }
-
- //
- // public NssiDeAllocateRequest deAllocateNssi() throws Exception {
- // DeAllocateNssi deAllocateNssi = new DeAllocateNssi();
- // deAllocateNssi.setTerminateNssiOption(0);
- // List<String> snssai = new LinkedList<>();
- // snssai.add("001-100001");
- // deAllocateNssi.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
- // deAllocateNssi.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- // deAllocateNssi.setScriptName("CN1");
- // deAllocateNssi.setSnssaiList(snssai);
- // EsrInfo esrInfo = new EsrInfo();
- // esrInfo.setVendor("huawei");
- // esrInfo.setNetworkType(CORE);
- // NssiDeAllocateRequest deAllocate = new NssiDeAllocateRequest();
- // deAllocate.setDeAllocateNssi(deAllocateNssi);
- // deAllocate.setEsrInfo(esrInfo);
- // return deAllocate;
- // }
- //
- // public NssiActDeActRequest activateNssi() throws Exception {
- // EsrInfo esrInfo = new EsrInfo();
- // esrInfo.setVendor("huawei");
- // esrInfo.setNetworkType(CORE);
- // ActDeActNssi act = new ActDeActNssi();
- // act.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
- // act.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- // NssiActDeActRequest actReq = new NssiActDeActRequest();
- // actReq.setActDeActNssi(act);
- // actReq.setEsrInfo(esrInfo);
- // return actReq;
- // }
- //
- // public NssiActDeActRequest deActivateNssi() throws Exception {
- // EsrInfo esrInfo = new EsrInfo();
- // esrInfo.setVendor("huawei");
- // esrInfo.setNetworkType(CORE);
- // ActDeActNssi deAct = new ActDeActNssi();
- // deAct.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
- // deAct.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- // NssiActDeActRequest deActReq = new NssiActDeActRequest();
- // deActReq.setActDeActNssi(deAct);
- // deActReq.setEsrInfo(esrInfo);
- // return deActReq;
- // }
- //
- public String queryJobStatusNssi() throws Exception {
- EsrInfo esrInfo = new EsrInfo();
- esrInfo.setVendor("huawei");
- esrInfo.setNetworkType(CORE);
-
- JobStatusRequest jobStatus = new JobStatusRequest();
- jobStatus.setEsrInfo(esrInfo);
- jobStatus.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
- jobStatus.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- return marshal(jobStatus);
- }
-}
diff --git a/src/test/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterControllerTest.java b/src/test/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterControllerTest.java
new file mode 100644
index 0000000..20f4c95
--- /dev/null
+++ b/src/test/java/org/onap/so/adapters/nssmf/controller/NssmfAdapterControllerTest.java
@@ -0,0 +1,132 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.so.adapters.nssmf.controller;
+
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.so.adapters.nssmf.controller.NssmfAdapterController;
+import org.onap.so.adapters.nssmf.service.NssmfManagerService;
+import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.junit.Test;
+import java.lang.reflect.Field;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.onap.so.beans.nsmf.NetworkType.CORE;
+
+@RunWith(SpringRunner.class)
+public class NssmfAdapterControllerTest {
+
+ @Mock
+ private NssmfManagerService nssmfManagerService;
+
+ private NssmfAdapterController controller;
+
+ @Mock
+ private ResponseEntity entity;
+
+ @Before
+ public void setUp() throws Exception {
+ initMocks(this);
+ controller = new NssmfAdapterController();
+
+ Field nssmfManagerService = controller.getClass().getDeclaredField("nssmfManagerService");
+ nssmfManagerService.setAccessible(true);
+ nssmfManagerService.set(controller, this.nssmfManagerService);
+ }
+
+
+ @Test
+ public void allocateNssiTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ ResponseEntity entity = controller.allocateNssi(request);
+ assertNotNull(entity);
+ }
+
+ @Test
+ public void deAllocateNssiTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ String profileId = "7516eb33-e8d3-4805-b91a-96de1bb6d8bb";
+ ResponseEntity entity = controller.deAllocateNssi(request, profileId);
+ assertNotNull(entity);
+
+ }
+
+ @Test
+ public void activateNssiTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ String snssai = "01-772523CD";
+ ResponseEntity entity = controller.activateNssi(request, snssai);
+ assertNotNull(entity);
+ }
+
+ @Test
+ public void deactivateNssiTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ String snssai = "01-772523CD";
+ ResponseEntity entity = controller.deactivateNssi(request, snssai);
+ assertNotNull(entity);
+ }
+
+ @Test
+ public void queryJobStatusTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ String jobId = "b86aa515-b285-487b-8a1e-01f3cc871b88";
+ ResponseEntity entity = controller.queryJobStatus(request, jobId);
+ assertNotNull(entity);
+ }
+
+ @Test
+ public void queryNSSISelectionCapabilityTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ ResponseEntity entity = controller.queryNSSISelectionCapability(request);
+ assertNotNull(entity);
+ }
+
+ @Test
+ public void querySubnetCapabilityTest() throws Exception {
+ commonMock();
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ ResponseEntity entity = controller.querySubnetCapability(request);
+ assertNotNull(entity);
+ }
+
+ private void commonMock() {
+ NssmfAdapterNBIRequest request = new NssmfAdapterNBIRequest();
+ when(nssmfManagerService.allocateNssi(any())).thenReturn(entity);
+ when(nssmfManagerService.deAllocateNssi(any(), anyString())).thenReturn(entity);
+ when(nssmfManagerService.deActivateNssi(any(), anyString())).thenReturn(entity);
+ when(nssmfManagerService.activateNssi(any(), anyString())).thenReturn(entity);
+ when(nssmfManagerService.queryJobStatus(any(), anyString())).thenReturn(entity);
+ when(nssmfManagerService.querySubnetCapability(any())).thenReturn(entity);
+ when(nssmfManagerService.queryNSSISelectionCapability(any())).thenReturn(entity);
+ }
+}
diff --git a/src/test/java/org/onap/so/adapters/nssmf/entity/RestResponseTest.java b/src/test/java/org/onap/so/adapters/nssmf/entity/RestResponseTest.java
new file mode 100644
index 0000000..ab2c212
--- /dev/null
+++ b/src/test/java/org/onap/so/adapters/nssmf/entity/RestResponseTest.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.so.adapters.nssmf.entity;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.junit4.SpringRunner;
+import java.util.HashMap;
+import java.util.Map;
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+public class RestResponseTest {
+
+ @Test
+ public void testRestResponse() {
+ RestResponse restResponse = new RestResponse();
+ Map<String, String> header = new HashMap<>();
+ header.put("X-RequestID", "05a63ae2-249a-49b9-bc52-0c70a3bca487");
+ header.put("X-InvocationID", "bb7f7fc5-52ba-4937-a7af-55036694fe19");
+ header.put("testlong", "55036694");
+ header.put("testint", "55");
+ restResponse.setRespHeaderMap(header);
+
+ String headerStr = restResponse.getRespHeaderStr("X-RequestID");
+ assertEquals(headerStr, "05a63ae2-249a-49b9-bc52-0c70a3bca487");
+
+ long headerLong = restResponse.getRespHeaderLong("testlong");
+ long headerLongNull = restResponse.getRespHeaderLong("testlong1");
+ assertNotNull(headerLong);
+ assertEquals(headerLongNull, -1L);
+
+ int headerInt = restResponse.getRespHeaderInt("testint");
+ int headerIntNull = restResponse.getRespHeaderInt("testint1");
+ assertNotNull(headerInt);
+ assertEquals(headerIntNull, -1);
+
+ Map headerMap = restResponse.getRespHeaderMap();
+ assertNotNull(headerMap);
+ }
+
+}
diff --git a/src/test/java/org/onap/so/adapters/nssmf/exceptions/ApplicationExceptionTest.java b/src/test/java/org/onap/so/adapters/nssmf/exceptions/ApplicationExceptionTest.java
new file mode 100644
index 0000000..e4b1cc9
--- /dev/null
+++ b/src/test/java/org/onap/so/adapters/nssmf/exceptions/ApplicationExceptionTest.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.so.adapters.nssmf.exceptions;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import static org.junit.Assert.*;
+
+@RunWith(SpringRunner.class)
+public class ApplicationExceptionTest {
+
+ @Test
+ public void buildErrorResponseTest() {
+ ApplicationException appException = new ApplicationException(500, "system internal error");
+ ResponseEntity entity = appException.buildErrorResponse();
+ assertNotNull(entity);
+ assertEquals(entity.getStatusCodeValue(), 500);
+ }
+
+}
diff --git a/src/test/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImplTest.java b/src/test/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImplTest.java
index d7b3b03..b64f581 100644
--- a/src/test/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImplTest.java
+++ b/src/test/java/org/onap/so/adapters/nssmf/service/impl/NssmfManagerServiceImplTest.java
@@ -27,22 +27,29 @@ import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.conn.util.DomainType;
+import org.ehcache.config.ResourceType;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.so.adapters.nssmf.config.NssmfAdapterConfig;
import org.onap.so.adapters.nssmf.consts.NssmfAdapterConsts;
import org.onap.so.adapters.nssmf.entity.NssmfInfo;
import org.onap.so.adapters.nssmf.entity.TokenResponse;
+import org.onap.so.adapters.nssmf.enums.ActionType;
import org.onap.so.adapters.nssmf.enums.HttpMethod;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
import org.onap.so.adapters.nssmf.util.RestUtil;
import org.onap.so.beans.nsmf.*;
-import org.onap.so.beans.nsmf.oof.SubnetCapability;
import org.onap.so.db.request.beans.ResourceOperationStatus;
import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
+import javax.persistence.Access;
+import javax.persistence.ManyToOne;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
@@ -56,7 +63,7 @@ import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal;
import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal;
-import static org.onap.so.beans.nsmf.NetworkType.CORE;
+import static org.onap.so.beans.nsmf.NetworkType.*;
import static org.onap.so.beans.nsmf.ResourceSharingLevel.NON_SHARED;
@RunWith(SpringRunner.class)
@@ -91,6 +98,9 @@ public class NssmfManagerServiceImplTest {
private InputStream tokenStream;
@Mock
+ private NssmfAdapterConfig adapterConfig;
+
+ @Mock
private ResourceOperationStatusRepository repository;
@Before
@@ -103,6 +113,10 @@ public class NssmfManagerServiceImplTest {
restUtil.setAccessible(true);
restUtil.set(nssiManagerService, this.restUtil);
+ Field adapterConfig = nssiManagerService.getClass().getDeclaredField("nssmfAdapterConfig");
+ adapterConfig.setAccessible(true);
+ adapterConfig.set(nssiManagerService, this.adapterConfig);
+
Field repository = nssiManagerService.getClass().getDeclaredField("repository");
repository.setAccessible(true);
repository.set(nssiManagerService, this.repository);
@@ -116,6 +130,7 @@ public class NssmfManagerServiceImplTest {
private void createCommonMock(int statusCode, NssmfInfo nssmf) throws Exception {
when(restUtil.getToken(any(NssmfInfo.class))).thenReturn("7512eb3feb5249eca5ddd742fedddd39");
when(restUtil.getHttpsClient()).thenReturn(httpClient);
+ when(restUtil.getServiceInstance(any())).thenReturn(new ServiceInstance());
when(statusLine.getStatusCode()).thenReturn(statusCode);
when(restUtil.getNssmfHost(any(EsrInfo.class))).thenReturn(nssmf);
@@ -128,6 +143,8 @@ public class NssmfManagerServiceImplTest {
when(commonResponse.getStatusLine()).thenReturn(statusLine);
when(commonEntity.getContent()).thenReturn(postStream);
+ when(adapterConfig.getInfraAuth()).thenReturn("SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==");
+
Answer<HttpResponse> answer = invocation -> {
Object[] arguments = invocation.getArguments();
if (arguments != null && arguments.length == 1 && arguments[0] != null) {
@@ -147,8 +164,23 @@ public class NssmfManagerServiceImplTest {
}
@Test
- public void allocateNssi() throws Exception {
+ public void allocateCnNssiTest() throws Exception {
+ allocateNssi(CORE);
+
+ }
+
+ @Test
+ public void allocateTnNssiTest() throws Exception {
+ allocateNssi(TRANSPORT);
+ }
+
+ @Test
+ public void allocateAnNssiTest() throws Exception {
+ allocateNssi(ACCESS);
+ }
+
+ public void allocateNssi(NetworkType domainType) throws Exception {
NssmfInfo nssmf = new NssmfInfo();
nssmf.setUserName("nssmf-user");
nssmf.setPassword("nssmf-pass");
@@ -168,24 +200,37 @@ public class NssmfManagerServiceImplTest {
tokenStream = new ByteArrayInputStream(marshal(token).getBytes(UTF_8));
createCommonMock(200, nssmf);
+ NssmfAdapterNBIRequest nbiRequest = null;
+
+ switch (domainType) {
+ case CORE:
+ nbiRequest = createCnAllocateNssi();
+ break;
+ case TRANSPORT:
+ nbiRequest = createTnAllocateNssi();
+ break;
+ case ACCESS:
+ nbiRequest = createAnAllocateNssi();
+ break;
+ }
-
- NssmfAdapterNBIRequest nbiRequest = createAllocateNssi();
assertNotNull(nbiRequest);
System.out.println(marshal(nbiRequest));
ResponseEntity res = nssiManagerService.allocateNssi(nbiRequest);
assertNotNull(res);
assertNotNull(res.getBody());
NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
- assertEquals(allRes.getNssiId(), "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
+ if (!domainType.equals(ACCESS)) {
+ assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
+ assertEquals(allRes.getNssiId(), "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
+ }
System.out.println(res);
}
- private NssmfAdapterNBIRequest createAllocateNssi() {
+ private NssmfAdapterNBIRequest createCnAllocateNssi() {
CnSliceProfile sP = new CnSliceProfile();
List<String> sns = new LinkedList<>();
sns.add("001-100001");
@@ -220,13 +265,113 @@ public class NssmfManagerServiceImplTest {
cnNssi.setSliceProfile(sP);
cnNssi.setNsiInfo(nsiInfo);
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(CORE);
nbiRequest.setAllocateCnNssi(cnNssi);
return nbiRequest;
}
+ private NssmfAdapterNBIRequest createAnAllocateNssi() {
+
+ AnSliceProfile sP = new AnSliceProfile();
+ List<String> sns = new LinkedList<>();
+ sns.add("001-100001");
+ List<String> plmn = new LinkedList<>();
+ plmn.add("460-00");
+ plmn.add("460-01");
+ PerfReqEmbb embb = new PerfReqEmbb();
+ embb.setActivityFactor(50);
+ List<PerfReqEmbb> embbList = new LinkedList<>();
+ embbList.add(embb);
+ PerfReq perfReq = new PerfReq();
+ perfReq.setPerfReqEmbbList(embbList);
+ List<Integer> taList = new LinkedList<>();
+ taList.add(1);
+ taList.add(2);
+ taList.add(3);
+ sP.setSNSSAIList(sns);
+ sP.setSliceProfileId("ab9af40f13f721b5f13539d87484098");
+ sP.setPLMNIdList(plmn);
+ sP.setPerfReq(perfReq);
+ sP.setMaxNumberOfUEs(200);
+ sP.setCoverageAreaTAList(taList);
+ sP.setLatency(6);
+ sP.setResourceSharingLevel(NON_SHARED);
+ sP.setUeMobilityLevel(UeMobilityLevel.STATIONARY);
+ sP.setResourceSharingLevel(NON_SHARED);
+ NsiInfo nsiInfo = new NsiInfo();
+ nsiInfo.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
+ nsiInfo.setNsiName("eMBB-001");
+ AllocateAnNssi anNssi = new AllocateAnNssi();
+ anNssi.setNssiId("NSST-C-001-HDBNJ-NSSMF-01-A-ZX");
+ anNssi.setNssiName("eMBB-001");
+ anNssi.setScriptName("CN1");
+ anNssi.setSliceProfile(sP);
+ anNssi.setNsiInfo(nsiInfo);
+
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(ACCESS);
+ nbiRequest.setAllocateAnNssi(anNssi);
+ return nbiRequest;
+ }
+
+
+ private NssmfAdapterNBIRequest createTnAllocateNssi() {
+ TnSliceProfile sP = new TnSliceProfile();
+ List<String> sns = new LinkedList<>();
+ sns.add("01-1EB5BA40");
+ List<String> plmn = new LinkedList<>();
+ plmn.add("460-00");
+ PerfReqEmbb embb = new PerfReqEmbb();
+ embb.setActivityFactor(50);
+ List<PerfReqEmbb> embbList = new LinkedList<>();
+ embbList.add(embb);
+
+ sP.setSNSSAIList(sns);
+ sP.setSliceProfileId("fec94836-87a0-41dc-a199-0ad9aa3890d1");
+ sP.setPLMNIdList(plmn);
+ sP.setLatency(10);
+ sP.setMaxBandwidth(1000);
+ sP.setJitter(10);
+
+ List<TransportSliceNetwork> networks = new LinkedList<>();
+ TransportSliceNetwork network = new TransportSliceNetwork();
+ List<ConnectionLink> connectionLinks = new LinkedList<>();
+ ConnectionLink connectionLink = new ConnectionLink();
+ connectionLink.setTransportEndpointA("a47c76e3-c010-4eaf-adbb-0ba264118cab");
+ connectionLink.setTransportEndpointB("c0c83e33-80d2-43da-b6cb-17b930420d74");
+ connectionLinks.add(connectionLink);
+ network.setConnectionLinks(connectionLinks);
+ networks.add(network);
+
+ NsiInfo nsiInfo = new NsiInfo();
+ nsiInfo.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
+ nsiInfo.setNsiName("eMBB-001");
+ AllocateTnNssi tnNssi = new AllocateTnNssi();
+ tnNssi.setTransportSliceNetworks(networks);
+ tnNssi.setScriptName("TN");
+ tnNssi.setSliceProfile(sP);
+ tnNssi.setNsiInfo(nsiInfo);
+
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(TRANSPORT);
+ nbiRequest.setAllocateTnNssi(tnNssi);
+ return nbiRequest;
+ }
+
+ @Test
+ public void deAllocateCnNssi() throws Exception {
+ deAllocateNssi(CORE);
+ }
+
@Test
- public void deAllocateNssi() throws Exception {
+ public void deAllocateAnNssi() throws Exception {
+ deAllocateNssi(ACCESS);
+ }
+
+ @Test
+ public void deAllocateTnNssi() throws Exception {
+ deAllocateNssi(TRANSPORT);
+ }
+
+ public void deAllocateNssi(NetworkType domainType) throws Exception {
DeAllocateNssi deAllocateNssi = new DeAllocateNssi();
deAllocateNssi.setTerminateNssiOption(0);
List<String> snssai = new LinkedList<>();
@@ -236,7 +381,7 @@ public class NssmfManagerServiceImplTest {
deAllocateNssi.setScriptName("CN1");
deAllocateNssi.setSnssaiList(snssai);
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(domainType);
nbiRequest.setDeAllocateNssi(deAllocateNssi);
NssmfInfo nssmf = new NssmfInfo();
@@ -260,13 +405,30 @@ public class NssmfManagerServiceImplTest {
assertNotNull(res);
assertNotNull(res.getBody());
NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
- assertNotNull(res);
- assertNotNull(res.getBody());
+ if (!domainType.equals(ACCESS)) {
+ assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
+ }
+ }
+
+ @Test
+ public void activateAnNssi() throws Exception {
+ activateNssi(ACCESS);
}
+
@Test
- public void activateNssi() throws Exception {
+ public void activateCnNssi() throws Exception {
+ activateNssi(CORE);
+ }
+
+
+ @Test
+ public void activateTnNssi() throws Exception {
+ activateNssi(TRANSPORT);
+ }
+
+
+ private void activateNssi(NetworkType domainType) throws Exception {
NssmfInfo nssmf = new NssmfInfo();
nssmf.setUserName("nssmf-user");
nssmf.setPassword("nssmf-pass");
@@ -287,7 +449,7 @@ public class NssmfManagerServiceImplTest {
act.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
act.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(domainType);
nbiRequest.setActDeActNssi(act);
createCommonMock(200, nssmf);
@@ -295,7 +457,9 @@ public class NssmfManagerServiceImplTest {
assertNotNull(res);
assertNotNull(res.getBody());
NssiResponse allRes = unMarshal(res.getBody().toString(), NssiResponse.class);
- assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
+ if (!domainType.equals(ACCESS)) {
+ assertEquals(allRes.getJobId(), "4b45d919816ccaa2b762df5120f72067");
+ }
}
@Test
@@ -320,7 +484,7 @@ public class NssmfManagerServiceImplTest {
act.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
act.setNssiId("NSSI-C-001-HDBNJ-NSSMF-01-A-ZX");
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(CORE);
nbiRequest.setActDeActNssi(act);
createCommonMock(200, nssmf);
@@ -332,7 +496,33 @@ public class NssmfManagerServiceImplTest {
}
@Test
- public void queryJobStatus() throws Exception {
+ public void testNssmfRequest() throws ApplicationException {
+ NssmfRequest nssmfRequest = new NssmfRequest();
+ String sst = marshal(nssmfRequest);
+ System.out.println(sst);
+ }
+
+ @Test
+ public void queryCnAllocateJobStatus() throws Exception {
+ queryJobStatus(CORE, ActionType.ALLOCATE.toString());
+ }
+
+ @Test
+ public void queryCnActivateJobStatus() throws Exception {
+ queryJobStatus(CORE, ActionType.ACTIVATE.toString());
+ }
+
+ @Test
+ public void queryCnDeActivateJobStatus() throws Exception {
+ queryJobStatus(CORE, ActionType.DEACTIVATE.toString());
+ }
+
+ @Test
+ public void queryAnJobStatus() throws Exception {
+ queryJobStatus(ACCESS, ActionType.ALLOCATE.toString());
+ }
+
+ public void queryJobStatus(NetworkType domainType, String action) throws Exception {
NssmfInfo nssmf = new NssmfInfo();
nssmf.setUserName("nssmf-user");
nssmf.setPassword("nssmf-pass");
@@ -342,9 +532,9 @@ public class NssmfManagerServiceImplTest {
JobStatusResponse jobStatusResponse = new JobStatusResponse();
ResponseDescriptor descriptor = new ResponseDescriptor();
descriptor.setResponseId("7512eb3feb5249eca5ddd742fedddd39");
- descriptor.setProgress(20);
+ descriptor.setProgress(100);
descriptor.setStatusDescription("Initiating VNF Instance");
- descriptor.setStatus("processing");
+ descriptor.setStatus("FINISHED");
jobStatusResponse.setResponseDescriptor(descriptor);
TokenResponse token = new TokenResponse();
@@ -358,8 +548,9 @@ public class NssmfManagerServiceImplTest {
operationStatus.setOperationId("4b45d919816ccaa2b762df5120f72067");
operationStatus.setResourceTemplateUUID("8ee5926d-720b-4bb2-86f9-d20e921c143b");
operationStatus.setServiceId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
+ operationStatus.setOperType(action);
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(domainType);
nbiRequest.setResponseId("7512eb3feb5249eca5ddd742fedddd39");
List<ResourceOperationStatus> optional = new ArrayList<>();
optional.add(operationStatus);
@@ -372,18 +563,18 @@ public class NssmfManagerServiceImplTest {
assertNotNull(res);
assertNotNull(res.getBody());
JobStatusResponse allRes = unMarshal(res.getBody().toString(), JobStatusResponse.class);
- assertEquals(allRes.getResponseDescriptor().getProgress(), 20);
- assertEquals(allRes.getResponseDescriptor().getStatus(), "processing");
- assertEquals(allRes.getResponseDescriptor().getResponseId(), "7512eb3feb5249eca5ddd742fedddd39");
-
- System.out.println(res);
+ assertEquals(allRes.getResponseDescriptor().getProgress(), 100);
+ assertEquals(allRes.getResponseDescriptor().getStatus(), "FINISHED");
+ if (!domainType.equals(ACCESS)) {
+ assertEquals(allRes.getResponseDescriptor().getResponseId(), "7512eb3feb5249eca5ddd742fedddd39");
+ }
}
@Test
public void queryNSSISelectionCapability() throws Exception {
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(CORE);
ResponseEntity res = nssiManagerService.queryNSSISelectionCapability(nbiRequest);
assertNotNull(res);
assertNotNull(res.getBody());
@@ -411,11 +602,23 @@ public class NssmfManagerServiceImplTest {
System.out.println(res);
}
- private NssmfAdapterNBIRequest createNbiRequest() {
+ private NssmfAdapterNBIRequest createNbiRequest(NetworkType networkType) {
NssmfAdapterNBIRequest nbiRequest = new NssmfAdapterNBIRequest();
EsrInfo esrInfo = new EsrInfo();
- esrInfo.setVendor("huawei");
- esrInfo.setNetworkType(CORE);
+ switch (networkType) {
+ case CORE:
+ esrInfo.setVendor("huawei");
+ esrInfo.setNetworkType(CORE);
+ break;
+ case TRANSPORT:
+ esrInfo.setVendor("ONAP_internal");
+ esrInfo.setNetworkType(TRANSPORT);
+ break;
+ case ACCESS:
+ esrInfo.setVendor("huawei");
+ esrInfo.setNetworkType(ACCESS);
+ break;
+ }
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setServiceUuid("8ee5926d-720b-4bb2-86f9-d20e921c143b");
serviceInfo.setServiceInvariantUuid("e75698d9-925a-4cdd-a6c0-edacbe6a0b51");
@@ -429,13 +632,13 @@ public class NssmfManagerServiceImplTest {
@Test
public void querySubnetCapability() {
- NssmfAdapterNBIRequest nbiRequest = createNbiRequest();
+ NssmfAdapterNBIRequest nbiRequest = createNbiRequest(CORE);
QuerySubnetCapability subnetCapabilityQuery = new QuerySubnetCapability();
- List<String> subnetTypes = Arrays.asList("TN-FH", "TN-MH", "TN-BH");
+ List<String> subnetTypes = Arrays.asList("CN");
subnetCapabilityQuery.setSubnetTypes(subnetTypes);
nbiRequest.setSubnetCapabilityQuery(subnetCapabilityQuery);
- ResponseEntity res = nssiManagerService.queryNSSISelectionCapability(nbiRequest);
+ ResponseEntity res = nssiManagerService.querySubnetCapability(nbiRequest);
assertNotNull(res);
assertNotNull(res.getBody());
}
diff --git a/src/test/java/org/onap/so/adapters/nssmf/util/RestUtilTest.java b/src/test/java/org/onap/so/adapters/nssmf/util/RestUtilTest.java
new file mode 100644
index 0000000..ddc9371
--- /dev/null
+++ b/src/test/java/org/onap/so/adapters/nssmf/util/RestUtilTest.java
@@ -0,0 +1,161 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ # Copyright (c) 2020, CMCC Technologies Co., Ltd.
+ #
+ # 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.so.adapters.nssmf.util;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.hibernate.jdbc.Expectations;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.mockito.stubbing.Answer;
+import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.so.adapters.nssmf.entity.NssmfInfo;
+import org.onap.so.adapters.nssmf.entity.RestResponse;
+import org.onap.so.adapters.nssmf.enums.HttpMethod;
+import org.onap.so.adapters.nssmf.exceptions.ApplicationException;
+import org.onap.so.adapters.nssmf.extclients.aai.AaiServiceProvider;
+import org.onap.so.beans.nsmf.EsrInfo;
+import org.onap.so.beans.nsmf.ServiceInfo;
+import org.springframework.test.context.junit4.SpringRunner;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.util.Optional;
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+import static org.mockito.MockitoAnnotations.initMocks;
+import static org.onap.so.beans.nsmf.NetworkType.CORE;
+
+@RunWith(SpringRunner.class)
+public class RestUtilTest {
+
+
+ @Mock
+ public HttpClient httpClient;
+ @Mock
+ private HttpResponse tokenResponse;
+
+ @Mock
+ private HttpEntity tokenEntity;
+
+ private InputStream tokenStream;
+
+ @Mock
+ private StatusLine statusLine;
+
+ @Mock
+ private AaiServiceProvider aaiSvcProv;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ // Field nssmfManagerService = controller.getClass().getDeclaredField("nssmfManagerService");
+ // nssmfManagerService.setAccessible(true);
+ // nssmfManagerService.set(controller, this.nssmfManagerService);
+ }
+
+ private void commonMock() throws IOException, ApplicationException {
+
+ when(tokenResponse.getEntity()).thenReturn(tokenEntity);
+ when(tokenResponse.getStatusLine()).thenReturn(statusLine);
+
+ when(tokenEntity.getContent()).thenReturn(tokenStream);
+
+ when(httpClient.execute(any())).thenReturn(tokenResponse);
+
+ // Mockito.doReturn(httpClient).when(restUtil).getHttpsClient();
+ }
+
+ @Test
+ public void sendTest() throws Exception {
+ String url = "http://127.0.0.1:8080";
+ HttpMethod method = HttpMethod.PUT;
+ String content = "body content";
+ commonMock();
+
+ RestUtil restUtil = new RestUtil();
+ RestUtil util = Mockito.spy(restUtil);
+ doReturn(httpClient).when(util).getHttpsClient();
+
+ RestResponse restResponse = util.send(url, method, content, null);
+ assertNotNull(restResponse);
+ }
+
+ @Test
+ public void serviceInstanceOperationTest() throws NoSuchFieldException, IllegalAccessException {
+
+ RestUtil restUtil = new RestUtil();
+
+ Field aaiSvcProv = restUtil.getClass().getDeclaredField("aaiSvcProv");
+ aaiSvcProv.setAccessible(true);
+ aaiSvcProv.set(restUtil, this.aaiSvcProv);
+
+ ServiceInstance instance = new ServiceInstance();
+ ServiceInfo info = getServiceInfo();
+ restUtil.createServiceInstance(instance, info);
+ restUtil.getServiceInstance(info);
+ restUtil.deleteServiceInstance(info);
+ }
+
+ @Test
+ public void getNssmfHostTest() throws NoSuchFieldException, IllegalAccessException {
+ RestUtil restUtil = new RestUtil();
+
+ Field aaiSvcProv = restUtil.getClass().getDeclaredField("aaiSvcProv");
+ aaiSvcProv.setAccessible(true);
+ aaiSvcProv.set(restUtil, this.aaiSvcProv);
+ try {
+ restUtil.getNssmfHost(getEsrInfo());
+ } catch (ApplicationException ex) {
+ System.out.println(ex.getErrorMsg());
+ }
+ }
+
+
+ private EsrInfo getEsrInfo() {
+ EsrInfo esrInfo = new EsrInfo();
+ esrInfo.setVendor("huawei");
+ esrInfo.setNetworkType(CORE);
+ return esrInfo;
+ }
+
+ private ServiceInfo getServiceInfo() {
+ ServiceInfo serviceInfo = new ServiceInfo();
+ serviceInfo.setServiceUuid("8ee5926d-720b-4bb2-86f9-d20e921c143b");
+ serviceInfo.setServiceInvariantUuid("e75698d9-925a-4cdd-a6c0-edacbe6a0b51");
+ serviceInfo.setGlobalSubscriberId("5GCustomer");
+ serviceInfo.setServiceType("5G");
+ serviceInfo.setNsiId("NSI-M-001-HDBNJ-NSMF-01-A-ZX");
+ return serviceInfo;
+ }
+
+}