diff options
Diffstat (limited to 'bpmn/so-bpmn-tasks/src')
33 files changed, 1302 insertions, 408 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java index 667ac133af..59f8be50c8 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java @@ -20,26 +20,40 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; +import static com.google.common.collect.Sets.newHashSet; +import java.util.Set; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.onap.vnfmadapter.v1.model.OperationStatusRetrievalStatusEnum; + /** * @author waqas.ikram@est.tech */ public class Constants { - public static final String CREATE_VNF_REQUEST_PARAM_NAME = "createVnfRequest"; - public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; - - public static final String INPUT_PARAMETER = "inputParameter"; + public static final String CREATE_VNF_REQUEST_PARAM_NAME = "createVnfRequest"; + public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; + public static final String INPUT_PARAMETER = "inputParameter"; + public static final String DELETE_VNF_RESPONSE_PARAM_NAME = "deleteVnfResponse"; + + + public static final String DOT = "."; + public static final String UNDERSCORE = "_"; + public static final String SPACE = "\\s+"; + + public static final String VNFM_ADAPTER_DEFAULT_URL = "http://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1/"; + public static final String VNFM_ADAPTER_DEFAULT_AUTH = "Basic dm5mbTpwYXNzd29yZDEk"; + + public static final String FORWARD_SLASH = "/"; + public static final String PRELOAD_VNFS_URL = "/restconf/config/VNF-API:preload-vnfs/vnf-preload-list/"; + - public static final String DOT = "."; - public static final String UNDERSCORE = "_"; - public static final String SPACE = "\\s+"; + public static final Set<OperationStateEnum> OPERATION_FINISHED_STATES = + newHashSet(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK); - public static final String VNFM_ADAPTER_DEFAULT_URL = "http://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1/"; - public static final String VNFM_ADAPTER_DEFAULT_AUTH = "Basic dm5mbTpwYXNzd29yZDEk"; - - public static final String FORWARD_SLASH = "/"; - public static final String PRELOAD_VNFS_URL = "/restconf/config/VNF-API:preload-vnfs/vnf-preload-list/"; + public static final Set<OperationStatusRetrievalStatusEnum> OPERATION_RETRIEVAL_STATES = newHashSet( + OperationStatusRetrievalStatusEnum.STATUS_FOUND, OperationStatusRetrievalStatusEnum.WAITING_FOR_STATUS); + public static final String OPERATION_STATUS_PARAM_NAME = "operationStatus"; - private Constants() {} + private Constants() {} } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTask.java new file mode 100644 index 0000000000..857c5cb6fe --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTask.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.base.Optional; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + */ +@Component +public class EtsiVnfDeleteTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(EtsiVnfDeleteTask.class); + private final ExtractPojosForBB extractPojosForBB; + private final ExceptionBuilder exceptionUtil; + private final VnfmAdapterServiceProvider vnfmAdapterServiceProvider; + + @Autowired + public EtsiVnfDeleteTask(final ExceptionBuilder exceptionUtil, final ExtractPojosForBB extractPojosForBB, + final VnfmAdapterServiceProvider vnfmAdapterServiceProvider) { + this.exceptionUtil = exceptionUtil; + this.extractPojosForBB = extractPojosForBB; + this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider; + } + + /** + * Invoke VNFM adapter to delete the VNF + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void invokeVnfmAdapter(final BuildingBlockExecution execution) { + try { + LOGGER.debug("Executing invokeVnfmAdapter ..."); + final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID); + + final Optional<DeleteVnfResponse> response = vnfmAdapterServiceProvider.invokeDeleteRequest(vnf.getVnfId()); + + if (!response.isPresent()) { + final String errorMessage = "Unexpected error while processing delete request"; + LOGGER.error(errorMessage); + exceptionUtil.buildAndThrowWorkflowException(execution, 1211, errorMessage); + } + + final DeleteVnfResponse vnfResponse = response.get(); + + LOGGER.debug("Vnf delete response: {}", vnfResponse); + execution.setVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME, vnfResponse); + + LOGGER.debug("Finished executing invokeVnfmAdapter ..."); + } catch (final Exception exception) { + LOGGER.error("Unable to invoke delete request", exception); + exceptionUtil.buildAndThrowWorkflowException(execution, 1212, exception); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java new file mode 100644 index 0000000000..f89931063c --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTask.java @@ -0,0 +1,154 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_RESPONSE_PARAM_NAME; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_FINISHED_STATES; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_RETRIEVAL_STATES; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.OPERATION_STATUS_PARAM_NAME; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.vnfmadapter.v1.model.CreateVnfResponse; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.base.Optional; + + +/** + * @author waqas.ikram@est.tech + * + */ +@Component +public class MonitorVnfmCreateJobTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorVnfmCreateJobTask.class); + private final ExceptionBuilder exceptionUtil; + private final VnfmAdapterServiceProvider vnfmAdapterServiceProvider; + + @Autowired + public MonitorVnfmCreateJobTask(final VnfmAdapterServiceProvider vnfmAdapterServiceProvider, + final ExceptionBuilder exceptionUtil) { + this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider; + this.exceptionUtil = exceptionUtil; + } + + /** + * Get the current operation status of instantiation job + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void getCurrentOperationStatus(final BuildingBlockExecution execution) { + LOGGER.debug("Executing getCurrentOperationStatus ..."); + final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME); + execution.setVariable(OPERATION_STATUS_PARAM_NAME, getOperationStatus(execution, vnfInstantiateResponse)); + LOGGER.debug("Finished executing getCurrentOperationStatus ..."); + } + + /** + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + * @return boolean to indicate whether job has competed or not + */ + public boolean hasOperationFinished(final BuildingBlockExecution execution) { + LOGGER.debug("Executing hasOperationFinished ..."); + + final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); + if (operationStatusOption != null && operationStatusOption.isPresent()) { + return OPERATION_FINISHED_STATES.contains(operationStatusOption.get()); + } + LOGGER.debug("OperationStatus is not present yet... "); + LOGGER.debug("Finished executing hasOperationFinished ..."); + return false; + + } + + /** + * Log and throw exception on timeout for job status + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void timeOutLogFailue(final BuildingBlockExecution execution) { + final String message = "Instantiation operation time out"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1205, message); + } + + /** + * Check the final status of instantiation throw exception if not completed successfully + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void checkIfOperationWasSuccessful(final BuildingBlockExecution execution) { + LOGGER.debug("Executing checkIfOperationWasSuccessful ..."); + final Optional<OperationStateEnum> operationStatusOption = execution.getVariable(OPERATION_STATUS_PARAM_NAME); + final CreateVnfResponse vnfInstantiateResponse = execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME); + if (operationStatusOption == null || !operationStatusOption.isPresent()) { + final String message = "Unable to instantiate jobId: " + + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null") + + "Unable to retrieve OperationStatus"; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1206, message); + } + if (operationStatusOption.isPresent()) { + final OperationStateEnum operationStatus = operationStatusOption.get(); + if (operationStatus != OperationStateEnum.COMPLETED) { + final String message = "Unable to instantiate jobId: " + + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null") + " OperationStatus: " + + operationStatus; + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1207, message); + } + LOGGER.debug("Successfully completed instatiation of job {}", vnfInstantiateResponse); + } + } + + private Optional<OperationStateEnum> getOperationStatus(final BuildingBlockExecution execution, + final CreateVnfResponse vnfInstantiateResponse) { + + final Optional<QueryJobResponse> instantiateOperationJobStatus = + vnfmAdapterServiceProvider.getInstantiateOperationJobStatus(vnfInstantiateResponse.getJobId()); + + if (instantiateOperationJobStatus.isPresent()) { + final QueryJobResponse queryJobResponse = instantiateOperationJobStatus.get(); + + if (!OPERATION_RETRIEVAL_STATES.contains(queryJobResponse.getOperationStatusRetrievalStatus())) { + final String message = + "Recevied invalid operation reterivel state: " + queryJobResponse.getOperationStatusRetrievalStatus(); + LOGGER.error(message); + exceptionUtil.buildAndThrowWorkflowException(execution, 1203, message); + } + + if (queryJobResponse.getOperationState() != null) { + final OperationStateEnum operationStatus = queryJobResponse.getOperationState(); + LOGGER.debug("Operation {} with {} and operation retrieval status : {}", queryJobResponse.getId(), + operationStatus, queryJobResponse.getOperationStatusRetrievalStatus()); + return Optional.of(queryJobResponse.getOperationState()); + } + + LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}", queryJobResponse.getId(), + queryJobResponse.getOperationStatusRetrievalStatus()); + + } + return Optional.absent(); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java index 02303ef09d..1e785074f3 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java @@ -22,17 +22,22 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; - +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; import com.google.common.base.Optional; /** * Provide a service which interacts with VNFM adapter for instantiating, monitoring VNF - * + * * @author waqas.ikram@est.tech */ public interface VnfmAdapterServiceProvider { - Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request); + Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request); + + Optional<DeleteVnfResponse> invokeDeleteRequest(final String vnfId); + + Optional<QueryJobResponse> getInstantiateOperationJobStatus(final String jobId); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java index afdcccfd36..e8f4c08f38 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java @@ -25,13 +25,14 @@ import org.onap.so.rest.exceptions.RestProcessingException; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; - import com.google.common.base.Optional; /** @@ -40,50 +41,111 @@ import com.google.common.base.Optional; @Service public class VnfmAdapterServiceProviderImpl implements VnfmAdapterServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(VnfmAdapterServiceProviderImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(VnfmAdapterServiceProviderImpl.class); + + private final VnfmAdapterUrlProvider urlProvider; + private final HttpRestServiceProvider httpServiceProvider; + + @Autowired + public VnfmAdapterServiceProviderImpl(final VnfmAdapterUrlProvider urlProvider, + final HttpRestServiceProvider httpServiceProvider) { + this.urlProvider = urlProvider; + this.httpServiceProvider = httpServiceProvider; + } + + @Override + public Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, + final CreateVnfRequest request) { + try { + final String url = urlProvider.getCreateInstantiateUrl(vnfId); + + final ResponseEntity<CreateVnfResponse> response = + httpServiceProvider.postHttpRequest(request, url, CreateVnfResponse.class); + + final HttpStatus httpStatus = response.getStatusCode(); + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); + return Optional.absent(); + } + + if (!response.hasBody()) { + LOGGER.error("Received response without body: {}", response); + return Optional.absent(); + } - private final VnfmAdapterUrlProvider urlProvider; - private final HttpRestServiceProvider httpServiceProvider; + final CreateVnfResponse createVnfResponse = response.getBody(); - @Autowired - public VnfmAdapterServiceProviderImpl(final VnfmAdapterUrlProvider urlProvider, - final HttpRestServiceProvider httpServiceProvider) { - this.urlProvider = urlProvider; - this.httpServiceProvider = httpServiceProvider; + if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { + LOGGER.error("Received invalid instantiation response: {}", response); + return Optional.absent(); + } + + return Optional.of(createVnfResponse); + } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { + LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException); + return Optional.absent(); } - @Override - public Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, - final CreateVnfRequest request) { - try { - final String url = urlProvider.getCreateInstantiateUrl(vnfId); + } + + @Override + public Optional<DeleteVnfResponse> invokeDeleteRequest(final String vnfId) { + try { + final String url = urlProvider.getDeleteUrl(vnfId); + LOGGER.debug("Will send request to vnfm adapter using url: {}", url); + + final ResponseEntity<DeleteVnfResponse> response = + httpServiceProvider.deleteHttpRequest(url, DeleteVnfResponse.class); + + LOGGER.debug("Response received: ", response); - final ResponseEntity<CreateVnfResponse> response = - httpServiceProvider.postHttpRequest(request, url, CreateVnfResponse.class); + final HttpStatus httpStatus = response.getStatusCode(); - final HttpStatus httpStatus = response.getStatusCode(); - if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { - LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); - return Optional.absent(); - } + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value()); + return Optional.absent(); + } + + if (!response.hasBody()) { + LOGGER.error("Received response without body: {}", response); + return Optional.absent(); + } + final DeleteVnfResponse deleteVnfResponse = response.getBody(); + + if (deleteVnfResponse.getJobId() == null || deleteVnfResponse.getJobId().isEmpty()) { + LOGGER.error("Received invalid delete response: {}", response); + return Optional.absent(); + } + return Optional.of(deleteVnfResponse); + } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { + LOGGER.error("Unexpected error while processing delete request", httpInvocationException); + return Optional.absent(); + } + } - if (!response.hasBody()) { - LOGGER.error("Received response without body: {}", response); - return Optional.absent(); - } + @Override + public Optional<QueryJobResponse> getInstantiateOperationJobStatus(final String jobId) { + try { + final String url = urlProvider.getJobStatusUrl(jobId); - final CreateVnfResponse createVnfResponse = response.getBody(); + final ResponseEntity<QueryJobResponse> response = + httpServiceProvider.getHttpResponse(url, QueryJobResponse.class); - if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { - LOGGER.error("Received invalid instantiation response: {}", response); - return Optional.absent(); - } + final HttpStatus httpStatus = response.getStatusCode(); - return Optional.of(createVnfResponse); - } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { - LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException); - return Optional.absent(); - } + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: ", url, httpStatus.value()); + return Optional.absent(); + } + if (!response.hasBody()) { + LOGGER.error("Received response without body: {}", response); + return Optional.absent(); + } + return Optional.of(response.getBody()); + } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { + LOGGER.error("Unexpected error while processing job request", httpInvocationException); + return Optional.absent(); } + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java index 03ee0712e7..97a7197373 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java @@ -21,7 +21,6 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import java.net.URI; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.util.UriComponentsBuilder; @@ -36,23 +35,43 @@ import org.springframework.web.util.UriComponentsBuilder; @Service public class VnfmAdapterUrlProvider { - private final URI baseUri; + private final URI baseUri; - @Autowired - public VnfmAdapterUrlProvider(final VnfmBasicHttpConfigProvider etsiVnfmAdapter) { - this.baseUri = UriComponentsBuilder.fromHttpUrl(etsiVnfmAdapter.getUrl()).build().toUri(); - } + @Autowired + public VnfmAdapterUrlProvider(final VnfmBasicHttpConfigProvider etsiVnfmAdapter) { + this.baseUri = UriComponentsBuilder.fromHttpUrl(etsiVnfmAdapter.getUrl()).build().toUri(); + } + + /** + * Get VNFM create and instantiate URL + * + * @param vnfId The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in + * AAI. + * @return VNFM create and instantiate URL + */ + public String getCreateInstantiateUrl(final String vnfId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("vnfs").pathSegment(vnfId).build().toString(); + } + + /** + * Get VNFM delete URL + * + * @param vnfId The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in + * AAI. + * @return VNFM delete URL + */ + public String getDeleteUrl(final String vnfId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("vnfs").pathSegment(vnfId).build().toString(); + } /** - * Get VNFM create and instantiate URL + * Get job status URL * - * @param vnfId The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in - * AAI. - * @return VNFM create and instantiate URL + * @param jobId The instantiation job identifier + * @return job status URL */ - public String getCreateInstantiateUrl(final String vnfId) { - return UriComponentsBuilder.fromUri(baseUri).pathSegment("vnfs").pathSegment(vnfId).build().toString(); + public String getJobStatusUrl(final String jobId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("jobs").pathSegment(jobId).build().toString(); } - } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java index b11e2caafa..7b86756afa 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapper.java @@ -21,6 +21,7 @@ package org.onap.so.client.sdnc.mapper; import java.net.URI; +import java.util.UUID; import org.onap.sdnc.northbound.client.model.GenericResourceApiConfigurationinformationConfigurationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiGcTopologyOperationInformation; @@ -52,9 +53,13 @@ public class GCTopologyOperationRequestMapper { Configuration vnrConfiguration, GenericVnf voiceVnf, String sdncReqId,URI callbackUri) { + String msoRequestId = UUID.randomUUID().toString(); + if (requestContext != null && requestContext.getMsoRequestId() != null) { + msoRequestId = requestContext.getMsoRequestId(); + } GenericResourceApiGcTopologyOperationInformation req = new GenericResourceApiGcTopologyOperationInformation(); GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId,callbackUri.toString()); - GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, reqAction); + GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, reqAction); GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, false); GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = generalTopologyObjectMapper.buildConfigurationInformation(vnrConfiguration,true); GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = generalTopologyObjectMapper.buildGcRequestInformation(voiceVnf,null); @@ -74,11 +79,15 @@ public class GCTopologyOperationRequestMapper { RequestContext requestContext, Configuration vnrConfiguration, String sdncReqId, URI callbackUri) { + String msoRequestId = null; + if (requestContext != null) { + msoRequestId = requestContext.getMsoRequestId(); + } GenericResourceApiGcTopologyOperationInformation req = new GenericResourceApiGcTopologyOperationInformation(); GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId,callbackUri.toString()); GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper - .buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, + .buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, GenericResourceApiRequestActionEnumeration.DELETEGENERICCONFIGURATIONINSTANCE); GenericResourceApiServiceinformationServiceInformation serviceInformation = new GenericResourceApiServiceinformationServiceInformation(); serviceInformation.setServiceInstanceId(serviceInstance.getServiceInstanceId()); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java index b086b8a7ff..756e5b068e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/GeneralTopologyObjectMapper.java @@ -60,10 +60,10 @@ public class GeneralTopologyObjectMapper { /* * Build GenericResourceApiRequestinformationRequestInformation */ - public GenericResourceApiRequestinformationRequestInformation buildGenericResourceApiRequestinformationRequestInformation(String sdncReqId, GenericResourceApiRequestActionEnumeration requestAction){ + public GenericResourceApiRequestinformationRequestInformation buildGenericResourceApiRequestinformationRequestInformation(String msoReqId, GenericResourceApiRequestActionEnumeration requestAction){ GenericResourceApiRequestinformationRequestInformation requestInformation = new GenericResourceApiRequestinformationRequestInformation(); - requestInformation.setRequestId(sdncReqId); + requestInformation.setRequestId(msoReqId); requestInformation.setRequestAction(requestAction); requestInformation.setSource("MSO"); return requestInformation; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapper.java index 188a228e5d..aef7e9e044 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapper.java @@ -57,8 +57,12 @@ public class NetworkTopologyOperationRequestMapper { Customer customer, RequestContext requestContext, CloudRegion cloudRegion) { GenericResourceApiNetworkOperationInformation req = new GenericResourceApiNetworkOperationInformation(); String sdncReqId = UUID.randomUUID().toString(); + String msoRequestId = UUID.randomUUID().toString(); + if (requestContext != null && requestContext.getMsoRequestId() != null) { + msoRequestId = requestContext.getMsoRequestId(); + } GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId); - GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, reqAction); + GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, reqAction); GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true); GenericResourceApiNetworkinformationNetworkInformation networkInformation = generalTopologyObjectMapper.buildNetworkInformation(network); GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput = buildNetworkRequestInput(network, serviceInstance, cloudRegion); @@ -68,7 +72,7 @@ public class NetworkTopologyOperationRequestMapper { req.setServiceInformation(serviceInformation); req.setNetworkInformation(networkInformation); - if (requestContext.getUserParams() != null) { + if (requestContext != null && requestContext.getUserParams() != null) { for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) { GenericResourceApiParam networkInputParameters = new GenericResourceApiParam(); GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam(); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapper.java index 505466b22c..cdb4ab96aa 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapper.java @@ -49,9 +49,13 @@ public class ServiceTopologyOperationMapper{ SDNCSvcAction svcAction, GenericResourceApiRequestActionEnumeration resourceAction,ServiceInstance serviceInstance, Customer customer, RequestContext requestContext) { String sdncReqId = UUID.randomUUID().toString(); + String msoRequestId = UUID.randomUUID().toString(); + if (requestContext != null && requestContext.getMsoRequestId() != null) { + msoRequestId = requestContext.getMsoRequestId(); + } GenericResourceApiServiceOperationInformation servOpInput = new GenericResourceApiServiceOperationInformation(); GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId); - GenericResourceApiRequestinformationRequestInformation reqInfo = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, resourceAction); + GenericResourceApiRequestinformationRequestInformation reqInfo = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, resourceAction); GenericResourceApiServiceinformationServiceInformation servInfo = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true); GenericResourceApiServicerequestinputServiceRequestInput servReqInfo = new GenericResourceApiServicerequestinputServiceRequestInput(); @@ -62,7 +66,7 @@ public class ServiceTopologyOperationMapper{ servOpInput.setServiceInformation(servInfo); servOpInput.setServiceRequestInput(servReqInfo); - if(requestContext.getUserParams()!=null){ + if(requestContext != null && requestContext.getUserParams()!=null){ for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) { GenericResourceApiServicerequestinputServiceRequestInput serviceRequestInput = new GenericResourceApiServicerequestinputServiceRequestInput(); serviceRequestInput.setServiceInstanceName(serviceInstance.getServiceInstanceName()); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java index b8c5fad41d..86c718d165 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapper.java @@ -96,8 +96,12 @@ public class VfModuleTopologyOperationRequestMapper { } String sdncReqId = UUID.randomUUID().toString(); + String msoRequestId = UUID.randomUUID().toString(); + if (requestContext != null && requestContext.getMsoRequestId() != null) { + msoRequestId = requestContext.getMsoRequestId(); + } - GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, + GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, requestAction); GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, includeModelInformation); GenericResourceApiVnfinformationVnfInformation vnfInformation = generalTopologyObjectMapper.buildVnfInformation(vnf, serviceInstance, includeModelInformation); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapper.java index 7de393bb2f..85e5b85529 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapper.java @@ -59,11 +59,15 @@ public class VnfTopologyOperationRequestMapper { GenericResourceApiRequestActionEnumeration requestAction, GenericVnf vnf, ServiceInstance serviceInstance, Customer customer, CloudRegion cloudRegion, RequestContext requestContext, boolean homing) { String sdncReqId = UUID.randomUUID().toString(); + String msoRequestId = UUID.randomUUID().toString(); + if (requestContext != null && requestContext.getMsoRequestId() != null) { + msoRequestId = requestContext.getMsoRequestId(); + } GenericResourceApiVnfOperationInformation req = new GenericResourceApiVnfOperationInformation(); GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper .buildSdncRequestHeader(svcAction, sdncReqId); GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper - .buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, requestAction); + .buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, requestAction); GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper .buildServiceInformation(serviceInstance, requestContext, customer, true); GenericResourceApiVnfinformationVnfInformation vnfInformation = generalTopologyObjectMapper @@ -84,7 +88,7 @@ public class VnfTopologyOperationRequestMapper { req.setVnfInformation(vnfInformation); GenericResourceApiParam vnfInputParameters = new GenericResourceApiParam(); - if (requestContext.getUserParams() != null) { + if (requestContext != null && requestContext.getUserParams() != null) { for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) { GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam(); paramItem.setName(entry.getKey()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java index 6500e3a850..aefe4c64bf 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/BaseIntegrationTest.java @@ -31,6 +31,7 @@ import org.onap.so.client.orchestration.SDNOHealthCheckResources; import org.onap.so.client.sdnc.SDNCClient; import org.onap.so.client.sniro.SniroClient; import org.onap.so.db.catalog.client.CatalogDbClient; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -40,7 +41,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; -import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.WireMockServer; @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -69,10 +70,13 @@ public abstract class BaseIntegrationTest extends TestDataSetup { @MockBean protected CatalogDbClient catalogDbClient; + + @Autowired + protected WireMockServer wireMockServer; @Before public void baseTestBefore() { - WireMock.reset(); + wireMockServer.resetAll(); } public String readResourceFile(String fileName) { InputStream stream; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTaskTest.java new file mode 100644 index 0000000000..5c76018ced --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTaskTest.java @@ -0,0 +1,111 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.UUID; +import org.junit.Test; +import org.mockito.Mock; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import com.google.common.base.Optional; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +public class EtsiVnfDeleteTaskTest extends BaseTaskTest { + + private static final String MODEL_INSTANCE_NAME = "MODEL_INSTANCE_NAME"; + + private static final String VNF_ID = UUID.randomUUID().toString(); + + private static final String VNF_NAME = "VNF_NAME"; + + private static final String JOB_ID = UUID.randomUUID().toString(); + + @Mock + private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; + + @Mock + private GeneralBuildingBlock buildingBlock; + + @Mock + private RequestContext requestContext; + + private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); + + @Test + public void testInvokeVnfmAdapter() throws Exception { + final EtsiVnfDeleteTask objUnderTest = getEtsiVnfDeleteTask(); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeDeleteRequest(eq(VNF_ID))).thenReturn(getDeleteVnfResponse()); + objUnderTest.invokeVnfmAdapter(stubbedxecution); + assertNotNull(stubbedxecution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME)); + } + + @Test + public void testInvokeVnfmAdapterException() throws Exception { + final EtsiVnfDeleteTask objUnderTest = getEtsiVnfDeleteTask(); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeDeleteRequest(eq(VNF_ID))).thenReturn(Optional.absent()); + objUnderTest.invokeVnfmAdapter(stubbedxecution); + assertNull(stubbedxecution.getVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1212), + any(Exception.class)); + } + + private Optional<DeleteVnfResponse> getDeleteVnfResponse() { + final DeleteVnfResponse response = new DeleteVnfResponse(); + response.setJobId(JOB_ID); + return Optional.of(response); + } + + private GenericVnf getGenericVnf() { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(VNF_ID); + genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); + genericVnf.setVnfName(VNF_NAME); + return genericVnf; + } + + private ModelInfoGenericVnf getModelInfoGenericVnf() { + final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); + return modelInfoGenericVnf; + } + + private EtsiVnfDeleteTask getEtsiVnfDeleteTask() { + return new EtsiVnfDeleteTask(exceptionUtil, extractPojosForBB, mockedVnfmAdapterServiceProvider); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTaskTest.java new file mode 100644 index 0000000000..ed5fa94100 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/MonitorVnfmCreateJobTaskTest.java @@ -0,0 +1,178 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.UUID; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.vnfmadapter.v1.model.CreateVnfResponse; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.onap.vnfmadapter.v1.model.OperationStatusRetrievalStatusEnum; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; +import com.google.common.base.Optional; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +public class MonitorVnfmCreateJobTaskTest extends BaseTaskTest { + + private static final String JOB_ID = UUID.randomUUID().toString(); + + @Mock + private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; + + private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); + + @Test + public void testGetCurrentOperationStatus() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.CREATE_VNF_RESPONSE_PARAM_NAME, getCreateVnfResponse()); + Optional<QueryJobResponse> queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + queryJobResponse.get().setOperationState(OperationStateEnum.COMPLETED); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional<OperationStateEnum> operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertNotNull(operationState); + assertEquals(OperationStateEnum.COMPLETED, operationState.get()); + } + + @Test + public void testGetCurrentOperationStatusFailed() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.CREATE_VNF_RESPONSE_PARAM_NAME, getCreateVnfResponse()); + Optional<QueryJobResponse> queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.CANNOT_RETRIEVE_STATUS); + queryJobResponse.get().setOperationState(OperationStateEnum.FAILED); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional<OperationStateEnum> operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertNotNull(operationState); + assertEquals(OperationStateEnum.FAILED, operationState.get()); + } + + @Test + public void testGetCurrentOperationStatusEmpty() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.CREATE_VNF_RESPONSE_PARAM_NAME, getCreateVnfResponse()); + Optional<QueryJobResponse> queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional<OperationStateEnum> operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertFalse(operationState.isPresent()); + } + + @Test + public void testGetCurrentOperationStatusException() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.CREATE_VNF_RESPONSE_PARAM_NAME, getCreateVnfResponse()); + Optional<QueryJobResponse> queryJobResponse = getQueryJobResponse(); + queryJobResponse.get().setOperationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND); + when(mockedVnfmAdapterServiceProvider.getInstantiateOperationJobStatus(JOB_ID)).thenReturn(queryJobResponse); + objUnderTest.getCurrentOperationStatus(stubbedxecution); + final Optional<OperationStateEnum> operationState = + stubbedxecution.getVariable(Constants.OPERATION_STATUS_PARAM_NAME); + assertFalse(operationState.isPresent()); + } + + @Test + public void testHasOperationFinished() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.of(OperationStateEnum.COMPLETED)); + assertTrue(objUnderTest.hasOperationFinished(stubbedxecution)); + } + + @Test + public void testHasOperationPending() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.absent()); + assertFalse(objUnderTest.hasOperationFinished(stubbedxecution)); + } + + @Test + public void testTimeOutLogFailue() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + objUnderTest.timeOutLogFailue(stubbedxecution); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1205), + eq("Instantiation operation time out")); + } + + @Test + public void testCheckIfOperationWasSuccessful() throws Exception { + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.of(OperationStateEnum.COMPLETED)); + MonitorVnfmCreateJobTask objUnderTest = Mockito.spy(getEtsiVnfMonitorJobTask()); + objUnderTest.checkIfOperationWasSuccessful(stubbedxecution); + verify(objUnderTest, times(1)).checkIfOperationWasSuccessful(stubbedxecution); + } + + @Test + public void testCheckIfOperationWasSuccessfulWithPending() throws Exception { + final MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.of(OperationStateEnum.PROCESSING)); + objUnderTest.checkIfOperationWasSuccessful(stubbedxecution); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1207), anyString()); + } + + @Test + public void testCheckIfOperationWasSuccessfulEmpty() throws Exception { + MonitorVnfmCreateJobTask objUnderTest = getEtsiVnfMonitorJobTask(); + stubbedxecution.setVariable(Constants.CREATE_VNF_RESPONSE_PARAM_NAME, getCreateVnfResponse()); + stubbedxecution.setVariable(Constants.OPERATION_STATUS_PARAM_NAME, Optional.absent()); + objUnderTest.checkIfOperationWasSuccessful(stubbedxecution); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1206), anyString()); + } + + private CreateVnfResponse getCreateVnfResponse() { + final CreateVnfResponse response = new CreateVnfResponse(); + response.setJobId(JOB_ID); + return response; + } + + private Optional<QueryJobResponse> getQueryJobResponse() { + final QueryJobResponse queryJobResponse = new QueryJobResponse(); + queryJobResponse.setId(JOB_ID); + return Optional.of(queryJobResponse); + } + + private MonitorVnfmCreateJobTask getEtsiVnfMonitorJobTask() { + return new MonitorVnfmCreateJobTask(mockedVnfmAdapterServiceProvider, exceptionUtil); + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/StubbedBuildingBlockExecution.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/StubbedBuildingBlockExecution.java new file mode 100644 index 0000000000..260585d208 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/StubbedBuildingBlockExecution.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import java.io.Serializable; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; +import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + * + */ +public class StubbedBuildingBlockExecution implements BuildingBlockExecution { + + private static final String CLOUD_OWNER = "CLOUD_OWNER"; + private static final String LCP_CLOUD_REGIONID = "RegionOnce"; + private static final String TENANT_ID = UUID.randomUUID().toString(); + private final Map<String, Serializable> execution = new HashMap<>(); + private final GeneralBuildingBlock generalBuildingBlock; + + StubbedBuildingBlockExecution() { + generalBuildingBlock = getGeneralBuildingBlockValue(); + } + + @Override + public GeneralBuildingBlock getGeneralBuildingBlock() { + return generalBuildingBlock; + } + + @SuppressWarnings("unchecked") + @Override + public <T> T getVariable(final String key) { + return (T) execution.get(key); + } + + @Override + public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { + return null; + } + + @Override + public void setVariable(final String key, final Serializable value) { + execution.put(key, value); + } + + @Override + public Map<ResourceKey, String> getLookupMap() { + return Collections.emptyMap(); + } + + @Override + public String getFlowToBeCalled() { + return null; + } + + public static String getTenantId() { + return TENANT_ID; + } + + private GeneralBuildingBlock getGeneralBuildingBlockValue() { + final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); + buildingBlock.setCloudRegion(getCloudRegion()); + return buildingBlock; + } + + private CloudRegion getCloudRegion() { + final CloudRegion cloudRegion = new CloudRegion(); + cloudRegion.setCloudOwner(CLOUD_OWNER); + cloudRegion.setLcpCloudRegionId(LCP_CLOUD_REGIONID); + cloudRegion.setTenantId(TENANT_ID); + return cloudRegion; + } + +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java index 5451d4442f..c4f19d6d1a 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/TestConstants.java @@ -20,6 +20,10 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_URL; + +import java.util.UUID; + import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmBasicHttpConfigProvider; /** @@ -32,6 +36,9 @@ public class TestConstants { public static final String DUMMY_BASIC_AUTH = "Basic 123abc"; public static final String DUMMY_URL = "http://localhost:30406/so/vnfm-adapter/v1/"; public static final String EXPECTED_URL = DUMMY_URL + "vnfs/" + DUMMY_GENERIC_VND_ID; + + public static final String DUMMY_JOB_ID = UUID.randomUUID().toString(); + public static final String JOB_STATUS_EXPECTED_URL = DUMMY_URL + "jobs/" + DUMMY_JOB_ID; public static VnfmBasicHttpConfigProvider getVnfmBasicHttpConfigProvider() { return getVnfmBasicHttpConfigProvider(DUMMY_URL, DUMMY_BASIC_AUTH); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java index 20abe6ece1..22c4c15079 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskTest.java @@ -30,28 +30,19 @@ import static org.mockito.Mockito.when; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_REQUEST_PARAM_NAME; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.CREATE_VNF_RESPONSE_PARAM_NAME; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.Constants.INPUT_PARAMETER; - -import java.io.Serializable; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import java.util.UUID; - import org.junit.Test; import org.mockito.Mock; import org.onap.so.bpmn.BaseTaskTest; import org.onap.so.bpmn.common.BuildingBlockExecution; -import org.onap.so.bpmn.common.exceptions.RequiredExecutionVariableExeception; import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.utils.InputParameter; -import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; -import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; import org.onap.vnfmadapter.v1.model.Tenant; - import com.google.common.base.Optional; @@ -60,191 +51,131 @@ import com.google.common.base.Optional; */ public class VnfmAdapterCreateVnfTaskTest extends BaseTaskTest { - private static final String MODEL_INSTANCE_NAME = "MODEL_INSTANCE_NAME"; - - private static final String CLOUD_OWNER = "CLOUD_OWNER"; - - private static final String LCP_CLOUD_REGIONID = "RegionOnce"; - - private static final String TENANT_ID = UUID.randomUUID().toString(); - - private static final String VNF_ID = UUID.randomUUID().toString(); - - private static final String VNF_NAME = "VNF_NAME"; - - private static final String JOB_ID = UUID.randomUUID().toString(); - - @Mock - private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; - - private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); - - @Test - public void testBuildCreateVnfRequest_withValidValues_storesRequestInExecution() throws Exception { - - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - stubbedxecution.setVariable(INPUT_PARAMETER, - new InputParameter(Collections.emptyMap(), Collections.emptyList())); - - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); - objUnderTest.buildCreateVnfRequest(stubbedxecution); - - final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); - assertNotNull(actual); - assertEquals(VNF_NAME + "." + MODEL_INSTANCE_NAME, actual.getName()); - - final Tenant actualTenant = actual.getTenant(); - assertEquals(CLOUD_OWNER, actualTenant.getCloudOwner()); - assertEquals(LCP_CLOUD_REGIONID, actualTenant.getRegionName()); - assertEquals(TENANT_ID, actualTenant.getTenantId()); - - } + private static final String MODEL_INSTANCE_NAME = "MODEL_INSTANCE_NAME"; - @Test - public void testBuildCreateVnfRequest_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { + private static final String CLOUD_OWNER = "CLOUD_OWNER"; - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + private static final String LCP_CLOUD_REGIONID = "RegionOnce"; - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); + private static final String VNF_ID = UUID.randomUUID().toString(); - objUnderTest.buildCreateVnfRequest(stubbedxecution); + private static final String VNF_NAME = "VNF_NAME"; - final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); + private static final String JOB_ID = UUID.randomUUID().toString(); - assertNull(actual); - verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1200), - any(Exception.class)); + @Mock + private VnfmAdapterServiceProvider mockedVnfmAdapterServiceProvider; - } + private final BuildingBlockExecution stubbedxecution = new StubbedBuildingBlockExecution(); - @Test - public void testInvokeVnfmAdapter_validValues_storesResponseInExecution() throws Exception { + @Test + public void testBuildCreateVnfRequest_withValidValues_storesRequestInExecution() throws Exception { - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + stubbedxecution.setVariable(INPUT_PARAMETER, new InputParameter(Collections.emptyMap(), Collections.emptyList())); - stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + objUnderTest.buildCreateVnfRequest(stubbedxecution); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); - when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) - .thenReturn(getCreateVnfResponse()); + final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); + assertNotNull(actual); + assertEquals(VNF_NAME + "." + MODEL_INSTANCE_NAME, actual.getName()); - objUnderTest.invokeVnfmAdapter(stubbedxecution); + final Tenant actualTenant = actual.getTenant(); + assertEquals(CLOUD_OWNER, actualTenant.getCloudOwner()); + assertEquals(LCP_CLOUD_REGIONID, actualTenant.getRegionName()); + assertEquals(StubbedBuildingBlockExecution.getTenantId(), actualTenant.getTenantId()); - assertNotNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); - } + } - @Test - public void testInvokeVnfmAdapter_invalidValues_storesResponseInExecution() throws Exception { + @Test + public void testBuildCreateVnfRequest_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); - when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) - .thenReturn(Optional.absent()); + objUnderTest.buildCreateVnfRequest(stubbedxecution); - objUnderTest.invokeVnfmAdapter(stubbedxecution); + final CreateVnfRequest actual = stubbedxecution.getVariable(CREATE_VNF_REQUEST_PARAM_NAME); - assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); - verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), - any(Exception.class)); - } + assertNull(actual); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1200), + any(Exception.class)); + } - @Test - public void testInvokeVnfmAdapter_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { + @Test + public void testInvokeVnfmAdapter_validValues_storesResponseInExecution() throws Exception { - final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); + stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); - objUnderTest.invokeVnfmAdapter(stubbedxecution); + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) + .thenReturn(getCreateVnfResponse()); - assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); - verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), - any(Exception.class)); + objUnderTest.invokeVnfmAdapter(stubbedxecution); - } + assertNotNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); + } - private Optional<CreateVnfResponse> getCreateVnfResponse() { - final CreateVnfResponse response = new CreateVnfResponse(); - response.setJobId(JOB_ID); - return Optional.of(response); - } + @Test + public void testInvokeVnfmAdapter_invalidValues_storesResponseInExecution() throws Exception { - private GenericVnf getGenericVnf() { - final GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId(VNF_ID); - genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); - genericVnf.setVnfName(VNF_NAME); - return genericVnf; - } + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - private ModelInfoGenericVnf getModelInfoGenericVnf() { - final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); - modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); - return modelInfoGenericVnf; - } + stubbedxecution.setVariable(CREATE_VNF_REQUEST_PARAM_NAME, new CreateVnfRequest()); - private VnfmAdapterCreateVnfTask getEtsiVnfInstantiateTask() { - return new VnfmAdapterCreateVnfTask(exceptionUtil, extractPojosForBB, mockedVnfmAdapterServiceProvider); - } + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(getGenericVnf()); + when(mockedVnfmAdapterServiceProvider.invokeCreateInstantiationRequest(eq(VNF_ID), any(CreateVnfRequest.class))) + .thenReturn(Optional.absent()); - private class StubbedBuildingBlockExecution implements BuildingBlockExecution { + objUnderTest.invokeVnfmAdapter(stubbedxecution); - private final Map<String, Serializable> execution = new HashMap<>(); - private final GeneralBuildingBlock generalBuildingBlock; + assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), + any(Exception.class)); + } - StubbedBuildingBlockExecution() { - generalBuildingBlock = getGeneralBuildingBlockValue(); - } - @Override - public GeneralBuildingBlock getGeneralBuildingBlock() { - return generalBuildingBlock; - } + @Test + public void testInvokeVnfmAdapter_extractPojosForBBThrowsException_exceptionBuilderCalled() throws Exception { - @SuppressWarnings("unchecked") - @Override - public <T> T getVariable(final String key) { - return (T) execution.get(key); - } + final VnfmAdapterCreateVnfTask objUnderTest = getEtsiVnfInstantiateTask(); - @Override - public <T> T getRequiredVariable(final String key) throws RequiredExecutionVariableExeception { - return null; - } + when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenThrow(RuntimeException.class); - @Override - public void setVariable(final String key, final Serializable value) { - execution.put(key, value); - } + objUnderTest.invokeVnfmAdapter(stubbedxecution); - @Override - public Map<ResourceKey, String> getLookupMap() { - return Collections.emptyMap(); - } + assertNull(stubbedxecution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME)); + verify(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(1202), + any(Exception.class)); - @Override - public String getFlowToBeCalled() { - return null; - } + } - private GeneralBuildingBlock getGeneralBuildingBlockValue() { - final GeneralBuildingBlock buildingBlock = new GeneralBuildingBlock(); - buildingBlock.setCloudRegion(getCloudRegion()); - return buildingBlock; - } + private Optional<CreateVnfResponse> getCreateVnfResponse() { + final CreateVnfResponse response = new CreateVnfResponse(); + response.setJobId(JOB_ID); + return Optional.of(response); + } - private CloudRegion getCloudRegion() { - final CloudRegion cloudRegion = new CloudRegion(); - cloudRegion.setCloudOwner(CLOUD_OWNER); - cloudRegion.setLcpCloudRegionId(LCP_CLOUD_REGIONID); - cloudRegion.setTenantId(TENANT_ID); - return cloudRegion; - } + private GenericVnf getGenericVnf() { + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(VNF_ID); + genericVnf.setModelInfoGenericVnf(getModelInfoGenericVnf()); + genericVnf.setVnfName(VNF_NAME); + return genericVnf; + } - } + private ModelInfoGenericVnf getModelInfoGenericVnf() { + final ModelInfoGenericVnf modelInfoGenericVnf = new ModelInfoGenericVnf(); + modelInfoGenericVnf.setModelInstanceName(MODEL_INSTANCE_NAME); + return modelInfoGenericVnf; + } + private VnfmAdapterCreateVnfTask getEtsiVnfInstantiateTask() { + return new VnfmAdapterCreateVnfTask(exceptionUtil, extractPojosForBB, mockedVnfmAdapterServiceProvider); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java index 0f443916c4..6f1b6f0bd2 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImplTest.java @@ -22,29 +22,27 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_GENERIC_VND_ID; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_JOB_ID; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.getVnfmBasicHttpConfigProvider; - -import java.util.UUID; - import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterServiceProvider; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterServiceProviderImpl; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterUrlProvider; import org.onap.so.rest.exceptions.RestProcessingException; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.onap.vnfmadapter.v1.model.OperationStateEnum; +import org.onap.vnfmadapter.v1.model.QueryJobResponse; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; - import com.google.common.base.Optional; @@ -54,114 +52,242 @@ import com.google.common.base.Optional; @RunWith(MockitoJUnitRunner.class) public class VnfmAdapterServiceProviderImplTest { - private static final String EMPTY_JOB_ID = ""; - - private static final CreateVnfRequest CREATE_VNF_REQUEST = new CreateVnfRequest(); - - private static final String DUMMY_JOB_ID = UUID.randomUUID().toString(); - - @Mock - private HttpRestServiceProvider mockedHttpServiceProvider; - - @Mock - private ResponseEntity<CreateVnfResponse> mockedResponseEntity; - - @Test - public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithBody_validResponse() { - - when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), - eq(CreateVnfResponse.class))).thenReturn(mockedResponseEntity); - when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); - when(mockedResponseEntity.hasBody()).thenReturn(true); - final CreateVnfResponse response = getCreateVnfResponse(DUMMY_JOB_ID); - when(mockedResponseEntity.getBody()).thenReturn(response); - - - final VnfmAdapterServiceProvider objUnderTest = - new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); - - final Optional<CreateVnfResponse> actual = - objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); - assertTrue(actual.isPresent()); - assertEquals(actual.get(), response); - - } - - @Test - public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithNoBody_noResponse() { - assertWithStatuCode(HttpStatus.ACCEPTED); - } - - @Test - public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusNotOkWithNoBody_noResponse() { - assertWithStatuCode(HttpStatus.UNAUTHORIZED); - } - - - @Test - public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithBodyWithInvalidJobId_noResponse() { - assertWithJobId(null); - assertWithJobId(EMPTY_JOB_ID); - } - - @Test - public void testInvokeCreateInstantiationRequest_httpServiceProviderThrowException_httpRestServiceProviderNotNull() { - - when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), - eq(CreateVnfResponse.class))).thenThrow(RestProcessingException.class); - - - final VnfmAdapterServiceProvider objUnderTest = - new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); - - final Optional<CreateVnfResponse> actual = - objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); - assertFalse(actual.isPresent()); - - } - - - private void assertWithJobId(final String jobId) { - when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), - eq(CreateVnfResponse.class))).thenReturn(mockedResponseEntity); - when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); - when(mockedResponseEntity.hasBody()).thenReturn(true); - final CreateVnfResponse response = getCreateVnfResponse(jobId); - when(mockedResponseEntity.getBody()).thenReturn(response); - - - final VnfmAdapterServiceProvider objUnderTest = - new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); - - final Optional<CreateVnfResponse> actual = - objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); - assertFalse(actual.isPresent()); - } - - private void assertWithStatuCode(final HttpStatus status) { - when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), - eq(CreateVnfResponse.class))).thenReturn(mockedResponseEntity); - when(mockedResponseEntity.getStatusCode()).thenReturn(status); - when(mockedResponseEntity.hasBody()).thenReturn(false); - - final VnfmAdapterServiceProvider objUnderTest = - new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); - - final Optional<CreateVnfResponse> actual = - objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); - assertFalse(actual.isPresent()); - } + private static final String EMPTY_JOB_ID = ""; + + private static final CreateVnfRequest CREATE_VNF_REQUEST = new CreateVnfRequest(); + + @Mock + private HttpRestServiceProvider mockedHttpServiceProvider; + + @Mock + private ResponseEntity<CreateVnfResponse> mockedResponseEntity; + + @Mock + private ResponseEntity<DeleteVnfResponse> deleteVnfResponse; + @Mock + private ResponseEntity<QueryJobResponse> mockedQueryJobResponseResponseEntity; + + @Test + public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithBody_validResponse() { + + when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), eq(CreateVnfResponse.class))) + .thenReturn(mockedResponseEntity); + when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(mockedResponseEntity.hasBody()).thenReturn(true); + final CreateVnfResponse response = getCreateVnfResponse(DUMMY_JOB_ID); + when(mockedResponseEntity.getBody()).thenReturn(response); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<CreateVnfResponse> actual = + objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); + assertTrue(actual.isPresent()); + assertEquals(actual.get(), response); + } + + @Test + public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithNoBody_noResponse() { + assertWithStatuCode(HttpStatus.ACCEPTED); + } + + @Test + public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusNotOkWithNoBody_noResponse() { + assertWithStatuCode(HttpStatus.UNAUTHORIZED); + } + + + @Test + public void testInvokeCreateInstantiationRequest_httpServiceProviderReturnsStatusAcceptedWithBodyWithInvalidJobId_noResponse() { + assertWithJobId(null); + assertWithJobId(EMPTY_JOB_ID); + } + + @Test + public void testInvokeCreateInstantiationRequest_httpServiceProviderThrowException_httpRestServiceProviderNotNull() { + + when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), eq(CreateVnfResponse.class))) + .thenThrow(RestProcessingException.class); + + + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + + final Optional<CreateVnfResponse> actual = + objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); + assertFalse(actual.isPresent()); + + } + + @Test + public void testInvokeDeleteRequest() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(deleteVnfResponse.hasBody()).thenReturn(true); + final DeleteVnfResponse response = getDeleteVnfResponse(DUMMY_JOB_ID); + when(deleteVnfResponse.getBody()).thenReturn(response); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertTrue(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestNotAccepted() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.BAD_GATEWAY); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestNoBody() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(deleteVnfResponse.hasBody()).thenReturn(false); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestNoJobId() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenReturn(deleteVnfResponse); + when(deleteVnfResponse.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(deleteVnfResponse.hasBody()).thenReturn(true); + final DeleteVnfResponse response = getDeleteVnfResponse(""); + when(deleteVnfResponse.getBody()).thenReturn(response); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testInvokeDeleteRequestException() { + when(mockedHttpServiceProvider.deleteHttpRequest(anyString(), eq(DeleteVnfResponse.class))) + .thenThrow(RestProcessingException.class); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<DeleteVnfResponse> actual = objUnderTest.invokeDeleteRequest(DUMMY_GENERIC_VND_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testGetInstantiateOperationJobStatus_httpServiceProviderReturnsStatusOkWithBody_validResponse() { + + when(mockedQueryJobResponseResponseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(mockedQueryJobResponseResponseEntity.hasBody()).thenReturn(true); + when(mockedQueryJobResponseResponseEntity.getBody()).thenReturn(getQueryJobResponse()); + + when(mockedHttpServiceProvider.getHttpResponse(eq(TestConstants.JOB_STATUS_EXPECTED_URL), + eq(QueryJobResponse.class))).thenReturn(mockedQueryJobResponseResponseEntity); + + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + + final Optional<QueryJobResponse> actual = objUnderTest.getInstantiateOperationJobStatus(DUMMY_JOB_ID); + assertTrue(actual.isPresent()); + final QueryJobResponse actualQueryJobResponse = actual.get(); + assertNotNull(actualQueryJobResponse); + } + + @Test + public void testGetInstantiateOperationJobStatus_httpServiceProviderReturnsStatusOkWithOutBody_invalidResponse() { + + when(mockedQueryJobResponseResponseEntity.getStatusCode()).thenReturn(HttpStatus.OK); + when(mockedQueryJobResponseResponseEntity.hasBody()).thenReturn(false); + + when(mockedHttpServiceProvider.getHttpResponse(eq(TestConstants.JOB_STATUS_EXPECTED_URL), + eq(QueryJobResponse.class))).thenReturn(mockedQueryJobResponseResponseEntity); + + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + + final Optional<QueryJobResponse> actual = objUnderTest.getInstantiateOperationJobStatus(DUMMY_JOB_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testGetInstantiateOperationJobStatus_httpServiceProviderReturnsStatusNotOkWithOutBody_invalidResponse() { + + when(mockedQueryJobResponseResponseEntity.getStatusCode()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR); + + when(mockedHttpServiceProvider.getHttpResponse(eq(TestConstants.JOB_STATUS_EXPECTED_URL), + eq(QueryJobResponse.class))).thenReturn(mockedQueryJobResponseResponseEntity); + + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + + final Optional<QueryJobResponse> actual = objUnderTest.getInstantiateOperationJobStatus(DUMMY_JOB_ID); + assertFalse(actual.isPresent()); + } + + @Test + public void testGetInstantiateOperationJobStatus_Exception() { + + when(mockedHttpServiceProvider.getHttpResponse(eq(TestConstants.JOB_STATUS_EXPECTED_URL), + eq(QueryJobResponse.class))).thenThrow(RestProcessingException.class); + + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + + final Optional<QueryJobResponse> actual = objUnderTest.getInstantiateOperationJobStatus(DUMMY_JOB_ID); + assertFalse(actual.isPresent()); + } + + private QueryJobResponse getQueryJobResponse() { + return new QueryJobResponse().id(DUMMY_JOB_ID).operationState(OperationStateEnum.COMPLETED); + + } + + private void assertWithJobId(final String jobId) { + when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), eq(CreateVnfResponse.class))) + .thenReturn(mockedResponseEntity); + when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.ACCEPTED); + when(mockedResponseEntity.hasBody()).thenReturn(true); + final CreateVnfResponse response = getCreateVnfResponse(jobId); + when(mockedResponseEntity.getBody()).thenReturn(response); + + + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + + final Optional<CreateVnfResponse> actual = + objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); + assertFalse(actual.isPresent()); + } + + private void assertWithStatuCode(final HttpStatus status) { + when(mockedHttpServiceProvider.postHttpRequest(eq(CREATE_VNF_REQUEST), anyString(), eq(CreateVnfResponse.class))) + .thenReturn(mockedResponseEntity); + when(mockedResponseEntity.getStatusCode()).thenReturn(status); + when(mockedResponseEntity.hasBody()).thenReturn(false); + final VnfmAdapterServiceProvider objUnderTest = + new VnfmAdapterServiceProviderImpl(getVnfmAdapterUrlProvider(), mockedHttpServiceProvider); + final Optional<CreateVnfResponse> actual = + objUnderTest.invokeCreateInstantiationRequest(DUMMY_GENERIC_VND_ID, CREATE_VNF_REQUEST); + assertFalse(actual.isPresent()); + } - private CreateVnfResponse getCreateVnfResponse(final String jobId) { - final CreateVnfResponse response = new CreateVnfResponse(); - response.setJobId(jobId); - return response; - } + private CreateVnfResponse getCreateVnfResponse(final String jobId) { + return new CreateVnfResponse().jobId(jobId); + } + private DeleteVnfResponse getDeleteVnfResponse(final String jobId) { + final DeleteVnfResponse response = new DeleteVnfResponse(); + response.setJobId(jobId); + return response; + } - private VnfmAdapterUrlProvider getVnfmAdapterUrlProvider() { - return new VnfmAdapterUrlProvider(getVnfmBasicHttpConfigProvider()); - } + private VnfmAdapterUrlProvider getVnfmAdapterUrlProvider() { + return new VnfmAdapterUrlProvider(getVnfmBasicHttpConfigProvider()); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProviderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProviderTest.java index cb93adca69..133f24bbe1 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProviderTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProviderTest.java @@ -22,11 +22,12 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import static org.junit.Assert.assertEquals; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_GENERIC_VND_ID; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.DUMMY_JOB_ID; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.EXPECTED_URL; +import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.JOB_STATUS_EXPECTED_URL; import static org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.TestConstants.getVnfmBasicHttpConfigProvider; import org.junit.Test; -import org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks.VnfmAdapterUrlProvider; /** @@ -41,9 +42,16 @@ public class VnfmAdapterUrlProviderTest { final VnfmAdapterUrlProvider objUnderTest = new VnfmAdapterUrlProvider(getVnfmBasicHttpConfigProvider()); final String actual = objUnderTest.getCreateInstantiateUrl(DUMMY_GENERIC_VND_ID); - assertEquals(EXPECTED_URL, actual); } + @Test + public void testGetJobStatuUrl_returnValidCreationInstantiationRequest() { + final VnfmAdapterUrlProvider objUnderTest = new VnfmAdapterUrlProvider(getVnfmBasicHttpConfigProvider()); + + final String actual = objUnderTest.getJobStatusUrl(DUMMY_JOB_ID); + assertEquals(JOB_STATUS_EXPECTED_URL, actual); + + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java index c4129a3b96..b50cd69f73 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/SniroHomingV2IT.java @@ -22,7 +22,6 @@ package org.onap.so.bpmn.infrastructure.flowspecific.tasks; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -41,6 +40,7 @@ import org.json.JSONObject; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.onap.so.BaseIntegrationTest; import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource; import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; @@ -53,7 +53,7 @@ import org.onap.so.bpmn.servicedecomposition.homingobjects.Candidate; import org.onap.so.bpmn.servicedecomposition.homingobjects.CandidateType; import org.onap.so.client.exception.BadResponseException; import org.onap.so.client.sniro.beans.SniroManagerRequest; -import org.onap.so.BaseIntegrationTest; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -117,7 +117,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ public void testCallSniro_success_1VpnLink() throws BadResponseException, IOException{ beforeVpnBondingLink("1"); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -138,7 +138,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ beforeVpnBondingLink("2"); beforeVpnBondingLink("3"); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -157,7 +157,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ public void testCallSniro_success_3Allotteds() throws BadResponseException, JsonProcessingException{ beforeAllottedResource(); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -176,7 +176,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ public void testCallSniro_success_1Vnf() throws JsonProcessingException, BadResponseException{ beforeVnf(); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -193,7 +193,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ beforeAllottedResource(); beforeVnf(); - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -482,7 +482,7 @@ public class SniroHomingV2IT extends BaseIntegrationTest{ beforeAllottedResource(); mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java index 1bcc464fa0..fe9e1c1608 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/network/NetworkAdapterClientIT.java @@ -21,15 +21,17 @@ package org.onap.so.client.adapter.network; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; + import javax.ws.rs.core.Response; + import org.junit.BeforeClass; import org.junit.Test; import org.onap.so.BaseIntegrationTest; @@ -74,7 +76,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ CreateNetworkResponse mockResponse = new CreateNetworkResponse(); mockResponse.setNetworkCreated(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT)) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -89,7 +91,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ CreateNetworkError mockResponse = new CreateNetworkError(); mockResponse.setMessage("Error in create network"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT)) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -104,7 +106,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ DeleteNetworkResponse mockResponse = new DeleteNetworkResponse(); mockResponse.setNetworkDeleted(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -119,7 +121,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ DeleteNetworkError mockResponse = new DeleteNetworkError(); mockResponse.setMessage("Error in delete network"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -136,7 +138,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ RollbackNetworkResponse mockResponse = new RollbackNetworkResponse(); mockResponse.setNetworkRolledBack(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -154,7 +156,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ RollbackNetworkError mockResponse = new RollbackNetworkError(); mockResponse.setMessage("Error in rollback network"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -166,7 +168,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ QueryNetworkResponse mockResponse = new QueryNetworkResponse(); mockResponse.setNetworkExists(true); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("networkStackId", equalTo("networkStackId")).withQueryParam("skipAAI", equalTo("true")) .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) @@ -184,7 +186,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ QueryNetworkError mockResponse = new QueryNetworkError(); mockResponse.setMessage("Error in query network"); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)).withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("networkStackId", equalTo("networkStackId")).withQueryParam("skipAAI", equalTo("true")) .withQueryParam("msoRequest.requestId", equalTo("testRequestId")) @@ -204,7 +206,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ UpdateNetworkResponse mockResponse = new UpdateNetworkResponse(); mockResponse.setNetworkId("test1"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -220,7 +222,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ UpdateNetworkResponse mockResponse = new UpdateNetworkResponse(); mockResponse.setNetworkId("test1"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -236,7 +238,7 @@ public class NetworkAdapterClientIT extends BaseIntegrationTest{ UpdateNetworkError mockResponse = new UpdateNetworkError(); mockResponse.setMessage("Error in update network"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_NETWORK_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java index 3387920d40..90e99eb0ad 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfAdapterClientIT.java @@ -21,11 +21,11 @@ package org.onap.so.client.adapter.vnf; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertEquals; @@ -70,7 +70,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ CreateVfModuleResponse mockResponse = new CreateVfModuleResponse(); mockResponse.setVfModuleCreated(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -85,7 +85,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in create Vf module"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) + wireMockServer.stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -101,8 +101,8 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ RollbackVfModuleResponse mockResponse = new RollbackVfModuleResponse(); mockResponse.setVfModuleRolledback(true); - stubFor( - post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) + wireMockServer.stubFor( + delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -119,8 +119,8 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in rollback Vf module"); - stubFor( - post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) + wireMockServer.stubFor( + delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID + "/rollback")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -134,7 +134,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ DeleteVfModuleResponse mockResponse = new DeleteVfModuleResponse(); mockResponse.setVfModuleDeleted(true); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -149,7 +149,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in delete Vf module"); - stubFor(post(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(delete(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -164,7 +164,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ UpdateVfModuleResponse mockResponse = new UpdateVfModuleResponse(); mockResponse.setVfModuleId("test1"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(200))); @@ -180,7 +180,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in update Vf module"); - stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(put(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBody(mapper.writeValueAsString(mockResponse)).withStatus(500))); @@ -192,7 +192,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ QueryVfModuleResponse mockResponse = new QueryVfModuleResponse(); mockResponse.setVnfId(AAI_VNF_ID); mockResponse.setVfModuleId(AAI_VF_MODULE_ID); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("vfModuleName", equalTo("someName")) @@ -210,7 +210,7 @@ public class VnfAdapterClientIT extends BaseIntegrationTest{ public void queryVfModuleTestThrowException() throws JsonProcessingException, VnfAdapterClientException { VfModuleExceptionResponse mockResponse = new VfModuleExceptionResponse(); mockResponse.setMessage("Error in update Vf module"); - stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) + wireMockServer.stubFor(get(urlPathEqualTo(REST_ENDPOINT + "/" + AAI_VNF_ID + "/vf-modules/" + AAI_VF_MODULE_ID)) .withQueryParam("cloudSiteId", equalTo(TESTING_ID)) .withQueryParam("tenantId", equalTo(TESTING_ID)) .withQueryParam("vfModuleName", equalTo("someName")) diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java index 40b6498034..4a006f8b66 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/adapter/vnf/VnfVolumeAdapterClientIT.java @@ -44,8 +44,6 @@ import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse; import org.onap.so.client.adapter.rest.AdapterRestClient; import org.onap.so.BaseIntegrationTest; - -@RunWith(MockitoJUnitRunner.Silent.class) public class VnfVolumeAdapterClientIT extends BaseIntegrationTest{ private static final String TESTING_ID = "___TESTING___"; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java index d6f8c70aa1..4bae5b40e4 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/namingservice/NamingClientTest.java @@ -23,7 +23,6 @@ package org.onap.so.client.namingservice; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.delete; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static org.junit.Assert.assertTrue; @@ -55,7 +54,7 @@ public class NamingClientTest extends BaseIntegrationTest{ @Test public void assignNameGenRequest() throws BadResponseException, IOException{ - stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/AssignResponse.json") .withStatus(HttpStatus.SC_ACCEPTED))); @@ -66,7 +65,7 @@ public class NamingClientTest extends BaseIntegrationTest{ } @Test public void assignNameGenRequestError() throws BadResponseException, IOException{ - stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(post(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/ErrorResponse.json") .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); @@ -78,7 +77,7 @@ public class NamingClientTest extends BaseIntegrationTest{ } @Test public void unassignNameGenRequest() throws BadResponseException, IOException{ - stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/UnassignResponse.json") .withStatus(HttpStatus.SC_ACCEPTED))); @@ -88,7 +87,7 @@ public class NamingClientTest extends BaseIntegrationTest{ } @Test public void unassignNameGenRequestError() throws BadResponseException, IOException{ - stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) + wireMockServer.stubFor(delete(urlPathEqualTo("/web/service/v1/genNetworkElementName")) .willReturn(aResponse().withHeader("Content-Type", "application/json") .withBodyFile("NamingClient/ErrorResponse.json") .withStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java index 0b33b1d187..05ba512c9d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/oof/OofClientTestIT.java @@ -22,7 +22,6 @@ package org.onap.so.client.oof; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import org.junit.Test; @@ -44,7 +43,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -56,7 +55,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testAsyncResponse_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"status\", \"requestStatus\": \"accepted\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -68,7 +67,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -84,7 +83,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -98,7 +97,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -112,7 +111,7 @@ public class OofClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { String mockResponse = "{ }"; - stubFor(post(urlEqualTo("/api/oof/v1/placement")) + wireMockServer.stubFor(post(urlEqualTo("/api/oof/v1/placement")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java index 9117b8ea64..70f196db8c 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/SDNCClientIT.java @@ -23,7 +23,6 @@ package org.onap.so.client.sdnc; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; @@ -46,7 +45,7 @@ public class SDNCClientIT extends BaseIntegrationTest { String responseJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "SDNCClientGetResponse.json"))); String queryLink = "/topologyQuery"; - stubFor(get(urlEqualTo(queryLink)) + wireMockServer.stubFor(get(urlEqualTo(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); String response = SPY_sdncClient.get(queryLink); @@ -59,7 +58,7 @@ public class SDNCClientIT extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - stubFor(post(urlMatching(queryLink)) + wireMockServer.stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); @@ -72,7 +71,7 @@ public class SDNCClientIT extends BaseIntegrationTest { String queryLink = "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation/"; - stubFor(post(urlMatching(queryLink)) + wireMockServer.stubFor(post(urlMatching(queryLink)) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json").withBody(responseJson))); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java index 0ca80c75f7..302bb551c3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/GCTopologyOperationRequestMapperTest.java @@ -75,6 +75,7 @@ public class GCTopologyOperationRequestMapperTest extends TestDataSetup { Assert.assertEquals("VLAN-NETWORK-RECEPTOR", genericInfo.getConfigurationInformation().getConfigurationType()); Assert.assertEquals("uuid",genericInfo.getSdncRequestHeader().getSvcRequestId()); Assert.assertEquals("http://localhost",genericInfo.getSdncRequestHeader().getSvcNotificationUrl()); + Assert.assertEquals("MsoRequestId",genericInfo.getRequestInformation().getRequestId()); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java index 6a14f8b567..1bfa78ad6d 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/NetworkTopologyOperationRequestMapperTest.java @@ -23,6 +23,7 @@ package org.onap.so.client.sdnc.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.io.IOException; @@ -109,6 +110,7 @@ public class NetworkTopologyOperationRequestMapperTest { userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); network = new L3Network(); network.setNetworkId("TEST_NETWORK_ID"); @@ -138,8 +140,24 @@ public class NetworkTopologyOperationRequestMapperTest { assertThat(networkSDNCrequest, sameBeanAs(reqMapper1).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", networkSDNCrequest.getRequestInformation().getRequestId()); } + + @Test + public void createGenericResourceApiNetworkOperationInformationReqContextNullTest() throws Exception { + RequestContext rc = new RequestContext(); + rc.setMsoRequestId(null); + GenericResourceApiNetworkOperationInformation networkSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer, + rc, cloudRegion); + assertNotNull(networkSDNCrequest.getRequestInformation().getRequestId()); + GenericResourceApiNetworkOperationInformation networkSDNCrequest2 = mapper.reqMapper( + SDNCSvcOperation.NETWORK_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATENETWORKINSTANCE, network, serviceInstance, customer, + null, cloudRegion); + assertNotNull(networkSDNCrequest2.getRequestInformation().getRequestId()); + } + @Test public void reqMapperTest() throws Exception { @@ -175,7 +193,8 @@ public class NetworkTopologyOperationRequestMapperTest { assertThat(reqMapperUnassign, sameBeanAs(networkSDNCrequestUnassign).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); - + assertEquals("MsoRequestId", networkSDNCrequestUnassign.getRequestInformation().getRequestId()); + } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java index 0bf06a0bb0..1919ef437b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/ServiceTopologyOperationMapperTest.java @@ -22,6 +22,8 @@ package org.onap.so.client.sdnc.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import java.nio.file.Files; import java.nio.file.Paths; @@ -80,10 +82,14 @@ public class ServiceTopologyOperationMapperTest { userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); GenericResourceApiServiceOperationInformation serviceOpInformation = mapper.reqMapper( SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, requestContext); + GenericResourceApiServiceOperationInformation serviceOpInformationNullReqContext = mapper.reqMapper( + SDNCSvcOperation.SERVICE_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN, GenericResourceApiRequestActionEnumeration.CREATESERVICEINSTANCE, serviceInstance, customer, + null); String jsonToCompare = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/BuildingBlocks/genericResourceApiEcompModelInformation.json"))); @@ -92,5 +98,7 @@ public class ServiceTopologyOperationMapperTest { GenericResourceApiOnapmodelinformationOnapModelInformation.class); assertThat(reqMapper1, sameBeanAs(serviceOpInformation.getServiceInformation().getOnapModelInformation())); + assertEquals("MsoRequestId", serviceOpInformation.getRequestInformation().getRequestId()); + assertNotNull(serviceOpInformationNullReqContext.getRequestInformation().getRequestId()); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java index 282f23caa7..7fce8c48c8 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VfModuleTopologyOperationRequestMapperTest.java @@ -23,6 +23,7 @@ package org.onap.so.client.sdnc.mapper; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.nio.file.Files; @@ -102,6 +103,7 @@ public class VfModuleTopologyOperationRequestMapperTest { RequestParameters requestParameters = new RequestParameters(); requestParameters.setUsePreload(true); requestContext.setRequestParameters(requestParameters); + requestContext.setMsoRequestId("MsoRequestId"); GenericVnf vnf = new GenericVnf(); vnf.setVnfId("testVnfId"); @@ -148,6 +150,7 @@ public class VfModuleTopologyOperationRequestMapperTest { assertThat(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @Test @@ -168,10 +171,13 @@ public class VfModuleTopologyOperationRequestMapperTest { VfModule vfModule = new VfModule(); vfModule.setVfModuleId("testVfModuleId"); vfModule.setVfModuleName("testVfModuleName"); + + RequestContext requestContext = new RequestContext(); + requestContext.setMsoRequestId("MsoRequestId"); GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, - null, null, null); + null, requestContext, null); String jsonToCompare = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "genericResourceApiVfModuleOperationInformationUnassign.json"))); @@ -182,6 +188,35 @@ public class VfModuleTopologyOperationRequestMapperTest { assertThat(reqMapper1, sameBeanAs(vfModuleSDNCrequest).ignoring("sdncRequestHeader.svcRequestId") .ignoring("requestInformation.requestId")); + assertEquals("MsoRequestId", vfModuleSDNCrequest.getRequestInformation().getRequestId()); + } + + @Test + public void unassignGenericResourceApiVfModuleInformationNullMsoReqIdTest() throws Exception { + + // prepare and set service instance + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setServiceInstanceId("serviceInstanceId"); + + // prepare and set vnf instance + + GenericVnf vnf = new GenericVnf(); + vnf.setVnfId("testVnfId"); + vnf.setVnfType("testVnfType"); + + // prepare and set vf module instance + + VfModule vfModule = new VfModule(); + vfModule.setVfModuleId("testVfModuleId"); + vfModule.setVfModuleName("testVfModuleName"); + + RequestContext requestContext = new RequestContext(); + + GenericResourceApiVfModuleOperationInformation vfModuleSDNCrequest = mapper.reqMapper( + SDNCSvcOperation.VF_MODULE_TOPOLOGY_OPERATION, SDNCSvcAction.UNASSIGN, vfModule, null, vnf, serviceInstance, null, + null, requestContext, null); + + assertNotNull(vfModuleSDNCrequest.getRequestInformation().getRequestId()); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java index 229a8cf601..64b532fd07 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sdnc/mapper/VnfTopologyOperationRequestMapperTest.java @@ -21,6 +21,7 @@ package org.onap.so.client.sdnc.mapper; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.util.ArrayList; @@ -122,12 +123,16 @@ public class VnfTopologyOperationRequestMapperTest { userParams.put("key1", "value1"); requestContext.setUserParams(userParams); requestContext.setProductFamilyId("productFamilyId"); + requestContext.setMsoRequestId("MsoRequestId"); CloudRegion cloudRegion = new CloudRegion(); GenericResourceApiVnfOperationInformation vnfOpInformation = mapper.reqMapper( SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, cloudRegion, requestContext,true); + GenericResourceApiVnfOperationInformation vnfOpInformationNullReqContext = mapper.reqMapper( + SDNCSvcOperation.VNF_TOPOLOGY_OPERATION, SDNCSvcAction.ASSIGN,GenericResourceApiRequestActionEnumeration.CREATEVNFINSTANCE, vnf, serviceInstance, customer, + cloudRegion, null,true); assertNull(vnfOpInformation.getServiceInformation().getOnapModelInformation().getModelCustomizationUuid()); assertEquals("vnfModelCustomizationUUID", vnfOpInformation.getVnfInformation().getOnapModelInformation().getModelCustomizationUuid()); @@ -136,5 +141,7 @@ public class VnfTopologyOperationRequestMapperTest { assertEquals("l3-network-ig-222", vnfOpInformation.getVnfRequestInput().getVnfNetworkInstanceGroupIds().get(1).getVnfNetworkInstanceGroupId()); assertEquals("entitlementPoolUuid", vnfOpInformation.getVnfRequestInput().getVnfInputParameters().getParam().get(1).getValue()); assertEquals("licenseKeyGroupUuid", vnfOpInformation.getVnfRequestInput().getVnfInputParameters().getParam().get(2).getValue()); + assertEquals("MsoRequestId", vnfOpInformation.getRequestInformation().getRequestId()); + assertNotNull(vnfOpInformationNullReqContext.getRequestInformation().getRequestId()); } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java index 3387e9ddef..722180f54b 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/sniro/SniroClientTestIT.java @@ -22,7 +22,6 @@ package org.onap.so.client.sniro; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import org.junit.Test; @@ -45,7 +44,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"corys cool\", \"requestStatus\": \"accepted\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -58,7 +57,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_failed() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -74,7 +73,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noMessage() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"\", \"requestStatus\": \"failed\"}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -88,7 +87,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_noStatus() throws JsonProcessingException, BadResponseException { String mockResponse = "{\"transactionId\": \"123456789\", \"requestId\": \"1234\", \"statusMessage\": \"missing data\", \"requestStatus\": null}"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -102,7 +101,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostDemands_error_empty() throws JsonProcessingException, BadResponseException { String mockResponse = "{ }"; - stubFor(post(urlEqualTo("/sniro/api/placement/v2")) + wireMockServer.stubFor(post(urlEqualTo("/sniro/api/placement/v2")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -115,7 +114,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_success() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"success\", \"message\": \"corys cool\"}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -127,7 +126,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_failed() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"failure\", \"message\": \"corys cool\"}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -139,7 +138,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_noStatus() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"\", \"message\": \"corys cool\"}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -152,7 +151,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_noMessage() throws BadResponseException, JsonProcessingException { String mockResponse = "{\"status\": \"failure\", \"message\": null}"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); @@ -165,7 +164,7 @@ public class SniroClientTestIT extends BaseIntegrationTest { public void testPostRelease_error_empty() throws BadResponseException, JsonProcessingException { String mockResponse = "{ }"; - stubFor(post(urlEqualTo("/v1/release-orders")) + wireMockServer.stubFor(post(urlEqualTo("/v1/release-orders")) .willReturn(aResponse().withStatus(200) .withHeader("Content-Type", "application/json") .withBody(mockResponse))); |