diff options
author | aosull01 <adrian.osullivan@huawei.com> | 2019-10-15 14:15:46 +0100 |
---|---|---|
committer | aosull01 <adrian.osullivan@huawei.com> | 2019-10-15 14:38:21 +0100 |
commit | 297bacd11441130e2f08636c415c561e2f59d607 (patch) | |
tree | a5e2ea6ad73f87e1833fb45a2f3947777d6c06c9 | |
parent | ab38dd33bc35ae61fc40d5c4a090a21cb214078c (diff) |
Add support for object characteristic type in Service Order
Change-Id: I36d30f8f4e38400d594215fce2a54a3beea77f2c
Issue-ID: EXTAPI-294
Signed-off-by: aosull01 <adrian.osullivan@huawei.com>
6 files changed, 1198 insertions, 885 deletions
diff --git a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java index fc0494f..649ae22 100644 --- a/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java +++ b/src/main/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessor.java @@ -14,9 +14,11 @@ package org.onap.nbi.apis.servicecatalog; import java.nio.file.Path; -import java.util.*; - -import io.swagger.util.Json; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; @@ -32,6 +34,7 @@ import io.swagger.models.Model; import io.swagger.models.ModelImpl; import io.swagger.models.properties.Property; import io.swagger.models.properties.PropertyBuilder; +import io.swagger.util.Json; @Service public class ToscaInfosProcessor { @@ -47,7 +50,7 @@ public class ToscaInfosProcessor { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaInfosProcessor.class); public void buildResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) - throws SdcToscaParserException { + throws SdcToscaParserException { SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false); @@ -66,7 +69,7 @@ public class ToscaInfosProcessor { // If this Input has a default value, then put it in serviceSpecCharacteristicValue if (input.getDefault() != null) { List<LinkedHashMap> serviceSpecCharacteristicValues = - buildServiceSpecCharacteristicsValuesFromSdc(input); + buildServiceSpecCharacteristicsValuesFromSdc(input); mapParameter.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValues); } serviceSpecCharacteristic.add(mapParameter); @@ -76,7 +79,7 @@ public class ToscaInfosProcessor { List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); List<LinkedHashMap> resourceSpecifications = - (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); + (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); for (LinkedHashMap resourceSpecification : resourceSpecifications) { if (resourceSpecification.get("id") != null) { String id = (String) resourceSpecification.get("id"); @@ -91,7 +94,7 @@ public class ToscaInfosProcessor { if (nodeTemplate == null) continue; resourceSpecification.put("modelCustomizationId", - sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); } } } @@ -109,13 +112,14 @@ public class ToscaInfosProcessor { return serviceSpecCharacteristicValues; } - public void buildAndSaveResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) throws SdcToscaParserException { + public void buildAndSaveResponseWithSdcToscaParser(Path path, Map serviceCatalogResponse) + throws SdcToscaParserException { SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance(); ISdcCsarHelper sdcCsarHelper = factory.getSdcCsarHelper(path.toFile().getAbsolutePath(), false); List<Input> inputs = sdcCsarHelper.getServiceInputs(); - Map<String, Model> definitions = new HashMap<String,Model>(); + Map<String, Model> definitions = new HashMap<String, Model>(); Model model = new ModelImpl(); if (inputs != null && inputs.size() > 0) { @@ -134,26 +138,32 @@ public class ToscaInfosProcessor { } String svcCharacteristicsJson = Json.pretty(definitions); - serviceSpecificationDBManager.saveSpecificationInputSchema(svcCharacteristicsJson,serviceCatalogResponse); + serviceSpecificationDBManager.saveSpecificationInputSchema(svcCharacteristicsJson, + serviceCatalogResponse); LinkedHashMap inputSchemaRef = new LinkedHashMap(); - inputSchemaRef.put("valueType","Object"); - inputSchemaRef.put("@schemaLocation","/serviceSpecification/"+serviceCatalogResponse.get("id")+"/specificationInputSchema"); - inputSchemaRef.put("@type",serviceCatalogResponse.get("name") + "_ServiceCharacteristic"); + // use object to match examples in Specifications + inputSchemaRef.put("valueType", "object"); + inputSchemaRef.put("@schemaLocation", + "/serviceSpecification/" + serviceCatalogResponse.get("id") + "/specificationInputSchema"); + inputSchemaRef.put("@type", serviceCatalogResponse.get("name") + "_ServiceCharacteristic"); LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap(); - serviceSpecCharacteristic.put("name",serviceCatalogResponse.get("name") + "_ServiceCharacteristics"); - serviceSpecCharacteristic.put("description","This object describes all the inputs needed from the client to interact with the " + serviceCatalogResponse.get("name") + " Service Topology"); - serviceSpecCharacteristic.put("valueType", "Object"); - serviceSpecCharacteristic.put("@type","ONAPServiceCharacteristic"); + serviceSpecCharacteristic.put("name", + serviceCatalogResponse.get("name") + "_ServiceCharacteristics"); + serviceSpecCharacteristic.put("description", + "This object describes all the inputs needed from the client to interact with the " + + serviceCatalogResponse.get("name") + " Service Topology"); + serviceSpecCharacteristic.put("valueType", "object"); + serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic"); serviceSpecCharacteristic.put("@schemaLocation", "null"); - serviceSpecCharacteristic.put("serviceSpecCharacteristicValue",inputSchemaRef); + serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", inputSchemaRef); - serviceCatalogResponse.put("serviceSpecCharacteristic",serviceSpecCharacteristic); + serviceCatalogResponse.put("serviceSpecCharacteristic", serviceSpecCharacteristic); List<NodeTemplate> nodeTemplates = sdcCsarHelper.getServiceNodeTemplates(); List<LinkedHashMap> resourceSpecifications = - (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); + (List<LinkedHashMap>) serviceCatalogResponse.get("resourceSpecification"); for (LinkedHashMap resourceSpecification : resourceSpecifications) { if (resourceSpecification.get("id") != null) { String id = (String) resourceSpecification.get("id"); @@ -167,7 +177,8 @@ public class ToscaInfosProcessor { } if (nodeTemplate == null) continue; - resourceSpecification.put("modelCustomizationId", sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); + resourceSpecification.put("modelCustomizationId", + sdcCsarHelper.getNodeTemplateCustomizationUuid(nodeTemplate)); } } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java index 208a93d..0caa093 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/PostSoProcessor.java @@ -1,19 +1,22 @@ /** * Copyright (c) 2018 Orange * - * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.onap.nbi.apis.serviceorder.workflow; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import org.onap.nbi.apis.serviceorder.SoClient; @@ -46,237 +49,290 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; @Service public class PostSoProcessor { - private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class); + private static final Logger LOGGER = LoggerFactory.getLogger(PostSoProcessor.class); - @Value("${onap.lcpCloudRegionId}") - private String lcpCloudRegionId; + @Value("${onap.lcpCloudRegionId}") + private String lcpCloudRegionId; - @Value("${onap.tenantId}") - private String tenantId; + @Value("${onap.tenantId}") + private String tenantId; - @Value("${so.owning.entity.id}") - private String soOwningEntityId; + @Value("${so.owning.entity.id}") + private String soOwningEntityId; - @Value("${so.owning.entity.name}") - private String soOwningEntityName; + @Value("${so.owning.entity.name}") + private String soOwningEntityName; - @Value("${so.project.name}") - private String soProjectName; + @Value("${so.project.name}") + private String soProjectName; - @Autowired - private ServiceOrderService serviceOrderService; + @Autowired + private ServiceOrderService serviceOrderService; - @Autowired - private SoClient soClient; + @Autowired + private SoClient soClient; - public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem(ServiceOrderInfo serviceOrderInfo, - ServiceOrderItem serviceOrderItem) { - ResponseEntity<CreateServiceInstanceResponse> response = null; - try { - response = postSORequest(serviceOrderItem,serviceOrderInfo); - } catch (NullPointerException e) { - LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e); - response = null; - } - return response; + public ResponseEntity<CreateServiceInstanceResponse> postServiceOrderItem( + ServiceOrderInfo serviceOrderInfo, ServiceOrderItem serviceOrderItem) { + ResponseEntity<CreateServiceInstanceResponse> response = null; + try { + response = postSORequest(serviceOrderItem, serviceOrderInfo); + } catch (NullPointerException e) { + LOGGER.error( + "Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), + e); + response = null; } - - public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem(ServiceOrderInfo serviceOrderInfo, - ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder) { - ResponseEntity<CreateE2EServiceInstanceResponse> response; - try { - response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder); - } catch (NullPointerException e) { - LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e); - response = null; - } - return response; + return response; + } + + public ResponseEntity<CreateE2EServiceInstanceResponse> postE2EServiceOrderItem( + ServiceOrderInfo serviceOrderInfo, ServiceOrderItem serviceOrderItem, + ServiceOrder serviceOrder) { + ResponseEntity<CreateE2EServiceInstanceResponse> response; + try { + response = postE2ESORequest(serviceOrderItem, serviceOrderInfo, serviceOrder); + } catch (NullPointerException e) { + LOGGER.error( + "Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), + e); + response = null; } - - private ResponseEntity<CreateServiceInstanceResponse> postSORequest(ServiceOrderItem serviceOrderItem, - ServiceOrderInfo serviceOrderInfo) { - RequestDetails requestDetails = buildSoRequest(serviceOrderItem, - serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), + return response; + } + + private ResponseEntity<CreateServiceInstanceResponse> postSORequest( + ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo) { + RequestDetails requestDetails = + buildSoRequest( + serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos() + .get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo()); - MSOPayload msoPayload = new MSOPayload(requestDetails); - ResponseEntity<CreateServiceInstanceResponse> response = null; - - switch (serviceOrderItem.getAction()) { - case ADD: - response = soClient.callCreateServiceInstance(msoPayload); - break; - case DELETE: - response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId()); - break; - case MODIFY: - if(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE ==serviceOrderItem.getState()) { - response = soClient.callCreateServiceInstance(msoPayload); - } - if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()) { - response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId()); - } - break; - default: - break; + MSOPayload msoPayload = new MSOPayload(requestDetails); + ResponseEntity<CreateServiceInstanceResponse> response = null; + + switch (serviceOrderItem.getAction()) { + case ADD: + response = soClient.callCreateServiceInstance(msoPayload); + break; + case DELETE: + response = + soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId()); + break; + case MODIFY: + if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) { + response = soClient.callCreateServiceInstance(msoPayload); } - return response; - } - - private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem, - ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) { - ServiceModel service = buildE2ESoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo(), serviceOrder); - MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service); - ResponseEntity<CreateE2EServiceInstanceResponse> response = null; - switch (serviceOrderItem.getAction()) { - case ADD: - response = soClient.callE2ECreateServiceInstance(msoE2EPayload); - break; - case DELETE: - response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(),serviceOrderItem.getService().getId()); - break; - case MODIFY: - if(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE ==serviceOrderItem.getState()) { - response = soClient.callE2ECreateServiceInstance(msoE2EPayload); - } - if(StateType.ACKNOWLEDGED==serviceOrderItem.getState()) { - response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), service.getServiceType(),serviceOrderItem.getService().getId()); - } - break; - default: - break; + if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { + response = + soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId()); } - return response; - } - - - - /** - * Build SO CREATE request from the ServiceOrder and catalog informations from SDC - * - * @param orderItem - * @param sdcInfos - * @param subscriberInfo - * @return - */ - private RequestDetails buildSoRequest(ServiceOrderItem orderItem, Map<String, Object> sdcInfos, - SubscriberInfo subscriberInfo) { - RequestDetails requestDetails = new RequestDetails(); - - requestDetails.setSubscriberInfo(subscriberInfo); - - ModelInfo modelInfo = new ModelInfo(); - modelInfo.setModelType("service"); - modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID")); - modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId()); - modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId()); - modelInfo.setModelName((String) sdcInfos.get("name")); - modelInfo.setModelVersion((String) sdcInfos.get("version")); - requestDetails.setModelInfo(modelInfo); - - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setInstanceName(orderItem.getService().getName()); - requestInfo.setSource("VID"); - requestInfo.setSuppressRollback(false); - requestInfo.setRequestorId("NBI"); - requestDetails.setRequestInfo(requestInfo); - - RequestParameters requestParameters = new RequestParameters(); - requestParameters.setSubscriptionServiceType((String) sdcInfos.get("name")); - requestParameters.setUserParams( - retrieveUserParamsFromServiceCharacteristics(orderItem.getService().getServiceCharacteristic())); - requestParameters.setaLaCarte(true); - requestDetails.setRequestParameters(requestParameters); - - CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId); - requestDetails.setCloudConfiguration(cloudConfiguration); - - OwningEntity owningEntity = new OwningEntity(); - owningEntity.setOwningEntityId(soOwningEntityId); - owningEntity.setOwningEntityName(soOwningEntityName); - requestDetails.setOwningEntity(owningEntity); - - Project project = new Project(); - project.setProjectName(soProjectName); - - requestDetails.setProject(project); - - return requestDetails; + break; + default: + break; } - - /** - * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC - * - * @param serviceOrderItem - * @param serviceOrder - * @param sdcInfos - * @return - */ - //ServiceOrderItem serviceOrderItem --> orderItem? - private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, Map<String, Object> sdcInfos, - SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) { - - subscriberInfo.getGlobalSubscriberId(); - ServiceModel service = new ServiceModel(); - service.setName(serviceOrderItem.getService().getName()); - service.setDescription(serviceOrder.getDescription()); - service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId()); - service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID")); - service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId()); - service.setServiceType((String) sdcInfos.get("name")); - - ParametersModel parameters = new ParametersModel(); - ArrayList<ResourceModel> resources = new ArrayList(); - - ArrayList<Object> resourceObjects = (ArrayList<Object>)sdcInfos.get("resourceSpecification"); - - for(int i = 0; i < resourceObjects.size(); i++) { - - ResourceModel resourceModel = new ResourceModel((Map<String, Object>)resourceObjects.get(i)); - ParametersModel resourceParameters = new ParametersModel(); - resourceModel.setParameters(resourceParameters); - resources.add(resourceModel); - + return response; + } + + private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest( + ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo, + ServiceOrder serviceOrder) { + ServiceModel service = + buildE2ESoRequest( + serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos() + .get(serviceOrderItem.getId()).getCatalogResponse(), + serviceOrderInfo.getSubscriberInfo(), serviceOrder); + MSOE2EPayload msoE2EPayload = new MSOE2EPayload(service); + ResponseEntity<CreateE2EServiceInstanceResponse> response = null; + switch (serviceOrderItem.getAction()) { + case ADD: + response = soClient.callE2ECreateServiceInstance(msoE2EPayload); + break; + case DELETE: + response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), + service.getServiceType(), serviceOrderItem.getService().getId()); + break; + case MODIFY: + if (StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE == serviceOrderItem.getState()) { + response = soClient.callE2ECreateServiceInstance(msoE2EPayload); } - parameters.setResources(resources); - List<UserParams> userParams = retrieveUserParamsFromServiceCharacteristics(serviceOrderItem.getService().getServiceCharacteristic()); - - // If there are ServiceCharacteristics add them to requestInputs - if (!userParams.isEmpty()){ - Map<String, String> requestInputs = new HashMap<String, String>(); - for (int i = 0; i < userParams.size(); i++) { - requestInputs.put(userParams.get(i).getName(), userParams.get(i).getValue()); - } - - parameters.setRequestInputs(requestInputs); + if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { + response = soClient.callE2EDeleteServiceInstance(service.getGlobalSubscriberId(), + service.getServiceType(), serviceOrderItem.getService().getId()); } - service.setParameters(parameters); - - return service; + break; + default: + break; } + return response; + } + + + + /** + * Build SO CREATE request from the ServiceOrder and catalog informations from SDC + * + * @param orderItem + * @param sdcInfos + * @param subscriberInfo + * @return + */ + private RequestDetails buildSoRequest(ServiceOrderItem orderItem, Map<String, Object> sdcInfos, + SubscriberInfo subscriberInfo) { + RequestDetails requestDetails = new RequestDetails(); + + requestDetails.setSubscriberInfo(subscriberInfo); + + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelType("service"); + modelInfo.setModelInvariantId((String) sdcInfos.get("invariantUUID")); + modelInfo.setModelNameVersionId(orderItem.getService().getServiceSpecification().getId()); + modelInfo.setModelVersionId(orderItem.getService().getServiceSpecification().getId()); + modelInfo.setModelName((String) sdcInfos.get("name")); + modelInfo.setModelVersion((String) sdcInfos.get("version")); + requestDetails.setModelInfo(modelInfo); + + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setInstanceName(orderItem.getService().getName()); + requestInfo.setSource("VID"); + requestInfo.setSuppressRollback(false); + requestInfo.setRequestorId("NBI"); + requestDetails.setRequestInfo(requestInfo); + + RequestParameters requestParameters = new RequestParameters(); + requestParameters.setSubscriptionServiceType((String) sdcInfos.get("name")); + requestParameters.setUserParams(retrieveUserParamsFromServiceCharacteristics( + orderItem.getService().getServiceCharacteristic())); + requestParameters.setaLaCarte(true); + requestDetails.setRequestParameters(requestParameters); + + CloudConfiguration cloudConfiguration = new CloudConfiguration(lcpCloudRegionId, tenantId); + requestDetails.setCloudConfiguration(cloudConfiguration); + + OwningEntity owningEntity = new OwningEntity(); + owningEntity.setOwningEntityId(soOwningEntityId); + owningEntity.setOwningEntityName(soOwningEntityName); + requestDetails.setOwningEntity(owningEntity); + + Project project = new Project(); + project.setProjectName(soProjectName); + + requestDetails.setProject(project); + + return requestDetails; + } + + /** + * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC + * + * @param serviceOrderItem + * @param serviceOrder + * @param sdcInfos + * @return + */ + // ServiceOrderItem serviceOrderItem --> orderItem? + private ServiceModel buildE2ESoRequest(ServiceOrderItem serviceOrderItem, + Map<String, Object> sdcInfos, SubscriberInfo subscriberInfo, ServiceOrder serviceOrder) { + + subscriberInfo.getGlobalSubscriberId(); + ServiceModel service = new ServiceModel(); + service.setName(serviceOrderItem.getService().getName()); + service.setDescription(serviceOrder.getDescription()); + service.setServiceUuid(serviceOrderItem.getService().getServiceSpecification().getId()); + service.setServiceInvariantUuid((String) sdcInfos.get("invariantUUID")); + service.setGlobalSubscriberId(subscriberInfo.getGlobalSubscriberId()); + service.setServiceType((String) sdcInfos.get("name")); + + ParametersModel parameters = new ParametersModel(); + ArrayList<ResourceModel> resources = new ArrayList(); + + ArrayList<Object> resourceObjects = (ArrayList<Object>) sdcInfos.get("resourceSpecification"); + + for (int i = 0; i < resourceObjects.size(); i++) { + + ResourceModel resourceModel = new ResourceModel((Map<String, Object>) resourceObjects.get(i)); + ParametersModel resourceParameters = new ParametersModel(); + resourceModel.setParameters(resourceParameters); + resources.add(resourceModel); - /** - * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from SDC - */ - private List<UserParams> retrieveUserParamsFromServiceCharacteristics(List<ServiceCharacteristic> characteristics) { - List<UserParams> userParams = new ArrayList<>(); - - if (!CollectionUtils.isEmpty(characteristics)) { - for (ServiceCharacteristic characteristic : characteristics) { - UserParams userParam = new UserParams(characteristic.getName(), - characteristic.getValue().getServiceCharacteristicValue()); - userParams.add(userParam); + } + parameters.setResources(resources); + List<UserParams> userParams = retrieveUserParamsFromServiceCharacteristics( + serviceOrderItem.getService().getServiceCharacteristic()); + + // If there are ServiceCharacteristics add them to requestInputs + if (!userParams.isEmpty()) { + Map<String, String> requestInputs = new HashMap<String, String>(); + for (int i = 0; i < userParams.size(); i++) { + requestInputs.put(userParams.get(i).getName(), userParams.get(i).getValue()); + } + + parameters.setRequestInputs(requestInputs); + } + service.setParameters(parameters); + + return service; + } + + /** + * Build a list of UserParams for the SO request by browsing a list of ServiceCharacteristics from + * SDC + */ + private List<UserParams> retrieveUserParamsFromServiceCharacteristics( + List<ServiceCharacteristic> characteristics) { + List<UserParams> userParams = new ArrayList<>(); + UserParams userParam; + + if (!CollectionUtils.isEmpty(characteristics)) { + for (ServiceCharacteristic characteristic : characteristics) { + // Check is the characteristic is of type object, if proceed as before to allow for + // backwards compatibility. + if (characteristic.getValueType() != null && !characteristic.getValueType().isEmpty() + && characteristic.getValueType().equals("object")) { + ObjectMapper mapper = new ObjectMapper(); + JsonNode jsonNode = null; + try { + jsonNode = mapper.readTree(characteristic.getValue().getServiceCharacteristicValue()); + } catch (IOException e) { + LOGGER.error("Failed to read object json {} , exception is ", + characteristic.getValue().getServiceCharacteristicValue(), e.getMessage()); + } + ObjectNode objectNode = (ObjectNode) jsonNode; + Iterator<Map.Entry<String, JsonNode>> iter = objectNode.fields(); + while (iter.hasNext()) { + Map.Entry<String, JsonNode> entry = iter.next(); + if (!entry.getValue().isArray()) { + userParam = new UserParams(entry.getKey(), entry.getValue().asText()); + } else { + ArrayNode arrayNode = (ArrayNode) entry.getValue(); + String arrayNodeValueString = arrayNode.toString(); + userParam = new UserParams(entry.getKey(), arrayNodeValueString); } + userParams.add(userParam); + } } - - return userParams; + // as UserParams for all other types, boolean, string, integer etc + else { + userParam = new UserParams(characteristic.getName(), + characteristic.getValue().getServiceCharacteristicValue()); + userParams.add(userParam); + } + } } + return userParams; + } + } diff --git a/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java b/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java index 6fea745..5dc261a 100644 --- a/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java +++ b/src/test/java/org/onap/nbi/apis/assertions/ServiceOrderExecutionTaskAssertions.java @@ -1,17 +1,15 @@ /** - * Copyright (c) 2018 Orange + * Copyright (c) 2018 Orange * - * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.onap.nbi.apis.assertions; @@ -43,258 +41,404 @@ import org.onap.nbi.apis.serviceorder.utils.JsonEntityConverter; public class ServiceOrderExecutionTaskAssertions { - public static ServiceOrder createTestServiceOrderRejected() { - ServiceOrder serviceOrder = new ServiceOrder(); - serviceOrder.setExternalId("LudONAP001"); - serviceOrder.setPriority("1"); - serviceOrder.setDescription("Ludo first ONAP Order"); - serviceOrder.setCategory("Consumer"); - serviceOrder.setRequestedStartDate(new Date()); - serviceOrder.setRequestedCompletionDate(new Date()); - - RelatedParty party = new RelatedParty(); - party.setId("6490"); - party.setRole("ONAPcustomer"); - party.setReferredType("individual"); - party.setName("Jean Pontus"); - List<RelatedParty> relatedPartyList = new ArrayList<>(); - relatedPartyList.add(party); - serviceOrder.setRelatedParty(relatedPartyList); - - List<ServiceOrderItem> items = new ArrayList<>(); - - ServiceOrderItem itemA = new ServiceOrderItem(); - itemA.id("A"); - itemA.action(ActionType.ADD); - Service serviceA = new Service(); - serviceA.setServiceState("active"); - ServiceSpecificationRef serviceSpecificationRefA = new ServiceSpecificationRef(); - serviceSpecificationRefA.setId("333"); - serviceA.setServiceSpecification(serviceSpecificationRefA); - itemA.setService(serviceA); - items.add(itemA); - - ServiceOrderItem itemB = new ServiceOrderItem(); - itemB.id("B"); - itemB.action(ActionType.ADD); - Service serviceB = new Service(); - serviceB.setServiceState("active"); - ServiceSpecificationRef serviceSpecificationRefB = new ServiceSpecificationRef(); - serviceSpecificationRefB.setId("1e3feeb0-8e36-46c6-862c-236d9c626439"); - serviceB.setServiceSpecification(serviceSpecificationRefB); - itemB.setService(serviceB); - List<OrderItemRelationship> orderItemRelationships = new ArrayList<>(); - OrderItemRelationship orderItemRelationship = new OrderItemRelationship(); - orderItemRelationship.setId("A"); - orderItemRelationships.add(orderItemRelationship); - itemB.setOrderItemRelationship(orderItemRelationships); - items.add(itemB); - serviceOrder.setOrderItem(items); - return serviceOrder; - + public static ServiceOrder createTestServiceOrderRejected() { + ServiceOrder serviceOrder = new ServiceOrder(); + serviceOrder.setExternalId("LudONAP001"); + serviceOrder.setPriority("1"); + serviceOrder.setDescription("Ludo first ONAP Order"); + serviceOrder.setCategory("Consumer"); + serviceOrder.setRequestedStartDate(new Date()); + serviceOrder.setRequestedCompletionDate(new Date()); + + RelatedParty party = new RelatedParty(); + party.setId("6490"); + party.setRole("ONAPcustomer"); + party.setReferredType("individual"); + party.setName("Jean Pontus"); + List<RelatedParty> relatedPartyList = new ArrayList<>(); + relatedPartyList.add(party); + serviceOrder.setRelatedParty(relatedPartyList); + + List<ServiceOrderItem> items = new ArrayList<>(); + + ServiceOrderItem itemA = new ServiceOrderItem(); + itemA.id("A"); + itemA.action(ActionType.ADD); + Service serviceA = new Service(); + serviceA.setServiceState("active"); + ServiceSpecificationRef serviceSpecificationRefA = new ServiceSpecificationRef(); + serviceSpecificationRefA.setId("333"); + serviceA.setServiceSpecification(serviceSpecificationRefA); + itemA.setService(serviceA); + items.add(itemA); + + ServiceOrderItem itemB = new ServiceOrderItem(); + itemB.id("B"); + itemB.action(ActionType.ADD); + Service serviceB = new Service(); + serviceB.setServiceState("active"); + ServiceSpecificationRef serviceSpecificationRefB = new ServiceSpecificationRef(); + serviceSpecificationRefB.setId("1e3feeb0-8e36-46c6-862c-236d9c626439"); + serviceB.setServiceSpecification(serviceSpecificationRefB); + itemB.setService(serviceB); + List<OrderItemRelationship> orderItemRelationships = new ArrayList<>(); + OrderItemRelationship orderItemRelationship = new OrderItemRelationship(); + orderItemRelationship.setId("A"); + orderItemRelationships.add(orderItemRelationship); + itemB.setOrderItemRelationship(orderItemRelationships); + items.add(itemB); + serviceOrder.setOrderItem(items); + return serviceOrder; + + } + + + public static ServiceOrder createTestServiceOrder(ActionType actionType) { + ServiceOrder serviceOrder = new ServiceOrder(); + serviceOrder.setExternalId("LudONAP001"); + serviceOrder.setPriority("1"); + serviceOrder.setDescription("Ludo first ONAP Order"); + serviceOrder.setCategory("Consumer"); + serviceOrder.setRequestedStartDate(new Date()); + serviceOrder.setRequestedCompletionDate(new Date()); + serviceOrder.setBaseType("toto"); + serviceOrder.setCompletionDateTime(new Date()); + serviceOrder.setExpectedCompletionDate(new Date()); + serviceOrder.setSchemaLocation("/tutu"); + + OrderRelationship orderRelationship = new OrderRelationship(); + orderRelationship.setId("test"); + orderRelationship.setHref("test"); + orderRelationship.setReferredType("test"); + orderRelationship.setType("type"); + List<OrderRelationship> relationships = new ArrayList<>(); + serviceOrder.setOrderRelationship(relationships); + + RelatedParty party = new RelatedParty(); + party.setId("6490"); + party.setRole("ONAPcustomer"); + party.setReferredType("individual"); + party.setName("Jean Pontus"); + List<RelatedParty> relatedPartyList = new ArrayList<>(); + relatedPartyList.add(party); + serviceOrder.setRelatedParty(relatedPartyList); + + List<ServiceOrderItem> items = new ArrayList<>(); + + ServiceOrderItem itemA = new ServiceOrderItem(); + itemA.id("A"); + itemA.action(actionType); + Service serviceA = new Service(); + if (actionType != ActionType.ADD) { + serviceA.setId("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb"); } - - - public static ServiceOrder createTestServiceOrder(ActionType actionType) { - ServiceOrder serviceOrder = new ServiceOrder(); - serviceOrder.setExternalId("LudONAP001"); - serviceOrder.setPriority("1"); - serviceOrder.setDescription("Ludo first ONAP Order"); - serviceOrder.setCategory("Consumer"); - serviceOrder.setRequestedStartDate(new Date()); - serviceOrder.setRequestedCompletionDate(new Date()); - serviceOrder.setBaseType("toto"); - serviceOrder.setCompletionDateTime(new Date()); - serviceOrder.setExpectedCompletionDate(new Date()); - serviceOrder.setSchemaLocation("/tutu"); - - OrderRelationship orderRelationship = new OrderRelationship(); - orderRelationship.setId("test"); - orderRelationship.setHref("test"); - orderRelationship.setReferredType("test"); - orderRelationship.setType("type"); - List<OrderRelationship> relationships = new ArrayList<>(); - serviceOrder.setOrderRelationship(relationships); - - RelatedParty party = new RelatedParty(); - party.setId("6490"); - party.setRole("ONAPcustomer"); - party.setReferredType("individual"); - party.setName("Jean Pontus"); - List<RelatedParty> relatedPartyList = new ArrayList<>(); - relatedPartyList.add(party); - serviceOrder.setRelatedParty(relatedPartyList); - - List<ServiceOrderItem> items = new ArrayList<>(); - - ServiceOrderItem itemA = new ServiceOrderItem(); - itemA.id("A"); - itemA.action(actionType); - Service serviceA = new Service(); - if (actionType != ActionType.ADD) { - serviceA.setId("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb"); - } - serviceA.setServiceState("active"); - ServiceSpecificationRef serviceSpecificationRefA = new ServiceSpecificationRef(); - serviceSpecificationRefA.setId("1e3feeb0-8e36-46c6-862c-236d9c626439"); - serviceA.setServiceSpecification(serviceSpecificationRefA); - itemA.setService(serviceA); - items.add(itemA); - - ServiceOrderItem itemB = new ServiceOrderItem(); - itemB.id("B"); - itemB.action(actionType); - Service serviceB = new Service(); - if (actionType != ActionType.ADD) { - serviceB.setId("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb"); - } - serviceB.setServiceState("active"); - ServiceSpecificationRef serviceSpecificationRefB = new ServiceSpecificationRef(); - serviceSpecificationRefB.setId("1e3feeb0-8e36-46c6-862c-236d9c626439"); - serviceB.setServiceSpecification(serviceSpecificationRefB); - itemB.setService(serviceB); - List<OrderItemRelationship> orderItemRelationships = new ArrayList<>(); - OrderItemRelationship orderItemRelationship = new OrderItemRelationship(); - orderItemRelationship.setId("A"); - orderItemRelationship.setType(RelationshipType.RELIESON); - orderItemRelationships.add(orderItemRelationship); - itemB.setOrderItemRelationship(orderItemRelationships); - items.add(itemB); - serviceOrder.setOrderItem(items); - return serviceOrder; - + serviceA.setServiceState("active"); + ServiceSpecificationRef serviceSpecificationRefA = new ServiceSpecificationRef(); + serviceSpecificationRefA.setId("1e3feeb0-8e36-46c6-862c-236d9c626439"); + serviceA.setServiceSpecification(serviceSpecificationRefA); + itemA.setService(serviceA); + items.add(itemA); + + ServiceOrderItem itemB = new ServiceOrderItem(); + itemB.id("B"); + itemB.action(actionType); + Service serviceB = new Service(); + if (actionType != ActionType.ADD) { + serviceB.setId("e4688e5f-61a0-4f8b-ae02-a2fbde623bcb"); + } + serviceB.setServiceState("active"); + ServiceSpecificationRef serviceSpecificationRefB = new ServiceSpecificationRef(); + serviceSpecificationRefB.setId("1e3feeb0-8e36-46c6-862c-236d9c626439"); + serviceB.setServiceSpecification(serviceSpecificationRefB); + itemB.setService(serviceB); + List<OrderItemRelationship> orderItemRelationships = new ArrayList<>(); + OrderItemRelationship orderItemRelationship = new OrderItemRelationship(); + orderItemRelationship.setId("A"); + orderItemRelationship.setType(RelationshipType.RELIESON); + orderItemRelationships.add(orderItemRelationship); + itemB.setOrderItemRelationship(orderItemRelationships); + items.add(itemB); + serviceOrder.setOrderItem(items); + return serviceOrder; + + } + + + public static ExecutionTask setUpBddForExecutionTaskSucess( + ServiceOrderRepository serviceOrderRepository, + ExecutionTaskRepository executionTaskRepository, ActionType actionType) { + ServiceOrder testServiceOrder = createTestServiceOrder(actionType); + + for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) { + serviceOrderItem.setState(StateType.ACKNOWLEDGED); } - - public static ExecutionTask setUpBddForExecutionTaskSucess(ServiceOrderRepository serviceOrderRepository, - ExecutionTaskRepository executionTaskRepository, - ActionType actionType) { - ServiceOrder testServiceOrder = createTestServiceOrder(actionType); - - for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) { - serviceOrderItem.setState(StateType.ACKNOWLEDGED); - } - - testServiceOrder.setState(StateType.ACKNOWLEDGED); - testServiceOrder.setId("test"); - serviceOrderRepository.save(testServiceOrder); - - LinkedHashMap<String, String> sdcResponse = new LinkedHashMap<>(); - sdcResponse.put("invariantUUID", "uuid"); - sdcResponse.put("name", "vFW"); - sdcResponse.put("version", "v1"); - sdcResponse.put("category", "NonE2E"); - - ServiceOrderInfo serviceOrderInfo = new ServiceOrderInfo(); - serviceOrderInfo.setServiceOrderId("test"); - SubscriberInfo subscriberInfo = new SubscriberInfo(); - subscriberInfo.setGlobalSubscriberId("6490"); - subscriberInfo.setSubscriberName("edgar"); - serviceOrderInfo.setSubscriberInfo(subscriberInfo); - - ServiceOrderItemInfo serviceOrderItemInfoA = new ServiceOrderItemInfo(); - serviceOrderItemInfoA.setId("A"); - serviceOrderItemInfoA.setCatalogResponse(sdcResponse); - - ServiceOrderItemInfo serviceOrderItemInfoB = new ServiceOrderItemInfo(); - serviceOrderItemInfoB.setId("B"); - serviceOrderItemInfoB.setCatalogResponse(sdcResponse); - serviceOrderInfo.addServiceOrderItemInfos("A", serviceOrderItemInfoA); - serviceOrderInfo.addServiceOrderItemInfos("B", serviceOrderItemInfoB); - - String json = JsonEntityConverter.convertServiceOrderInfoToJson(serviceOrderInfo); - - ExecutionTask executionTaskA = new ExecutionTask(); - executionTaskA.setCreateDate(new Date()); - executionTaskA.setOrderItemId("A"); - executionTaskA.setServiceOrderInfoJson(json); - executionTaskA = executionTaskRepository.save(executionTaskA); - ExecutionTask executionTaskB = new ExecutionTask(); - executionTaskB.setCreateDate(new Date()); - executionTaskB.setOrderItemId("B"); - executionTaskB.setReliedTasks(String.valueOf(executionTaskA.getInternalId())); - executionTaskB.setServiceOrderInfoJson(json); - executionTaskRepository.save(executionTaskB); - return executionTaskA; + testServiceOrder.setState(StateType.ACKNOWLEDGED); + testServiceOrder.setId("test"); + serviceOrderRepository.save(testServiceOrder); + + LinkedHashMap<String, String> sdcResponse = new LinkedHashMap<>(); + sdcResponse.put("invariantUUID", "uuid"); + sdcResponse.put("name", "vFW"); + sdcResponse.put("version", "v1"); + sdcResponse.put("category", "NonE2E"); + + ServiceOrderInfo serviceOrderInfo = new ServiceOrderInfo(); + serviceOrderInfo.setServiceOrderId("test"); + SubscriberInfo subscriberInfo = new SubscriberInfo(); + subscriberInfo.setGlobalSubscriberId("6490"); + subscriberInfo.setSubscriberName("edgar"); + serviceOrderInfo.setSubscriberInfo(subscriberInfo); + + ServiceOrderItemInfo serviceOrderItemInfoA = new ServiceOrderItemInfo(); + serviceOrderItemInfoA.setId("A"); + serviceOrderItemInfoA.setCatalogResponse(sdcResponse); + + ServiceOrderItemInfo serviceOrderItemInfoB = new ServiceOrderItemInfo(); + serviceOrderItemInfoB.setId("B"); + serviceOrderItemInfoB.setCatalogResponse(sdcResponse); + serviceOrderInfo.addServiceOrderItemInfos("A", serviceOrderItemInfoA); + serviceOrderInfo.addServiceOrderItemInfos("B", serviceOrderItemInfoB); + + String json = JsonEntityConverter.convertServiceOrderInfoToJson(serviceOrderInfo); + + ExecutionTask executionTaskA = new ExecutionTask(); + executionTaskA.setCreateDate(new Date()); + executionTaskA.setOrderItemId("A"); + executionTaskA.setServiceOrderInfoJson(json); + executionTaskA = executionTaskRepository.save(executionTaskA); + ExecutionTask executionTaskB = new ExecutionTask(); + executionTaskB.setCreateDate(new Date()); + executionTaskB.setOrderItemId("B"); + executionTaskB.setReliedTasks(String.valueOf(executionTaskA.getInternalId())); + executionTaskB.setServiceOrderInfoJson(json); + executionTaskRepository.save(executionTaskB); + return executionTaskA; + } + + public static ExecutionTask setUpBddForE2EExecutionTaskSucess( + ServiceOrderRepository serviceOrderRepository, + ExecutionTaskRepository executionTaskRepository, ActionType actionType) { + ServiceOrder testServiceOrder = createTestServiceOrder(actionType); + + for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) { + serviceOrderItem.setState(StateType.ACKNOWLEDGED); + List<ServiceCharacteristic> serviceCharacteristics = new ArrayList(); + ServiceCharacteristic serviceCharacteristic1 = new ServiceCharacteristic(); + serviceCharacteristic1.setName("access-site-id"); + Value value1 = new Value(); + value1.setServiceCharacteristicValue("1234765"); + serviceCharacteristic1.setValue(value1); + serviceCharacteristics.add(serviceCharacteristic1); + ServiceCharacteristic serviceCharacteristic2 = new ServiceCharacteristic(); + serviceCharacteristic2.setName("provider-site-id"); + Value value2 = new Value(); + value2.setServiceCharacteristicValue("654321"); + serviceCharacteristic2.setValue(value2); + serviceCharacteristics.add(serviceCharacteristic2); + serviceOrderItem.getService().setServiceCharacteristic(serviceCharacteristics); } - public static ExecutionTask setUpBddForE2EExecutionTaskSucess(ServiceOrderRepository serviceOrderRepository, - ExecutionTaskRepository executionTaskRepository, - ActionType actionType) { - ServiceOrder testServiceOrder = createTestServiceOrder(actionType); - - for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) { - serviceOrderItem.setState(StateType.ACKNOWLEDGED); - List<ServiceCharacteristic> serviceCharacteristics = new ArrayList(); - ServiceCharacteristic serviceCharacteristic1 = new ServiceCharacteristic(); - serviceCharacteristic1.setName("access-site-id"); - Value value1 = new Value(); - value1.setServiceCharacteristicValue("1234765"); - serviceCharacteristic1.setValue(value1); - serviceCharacteristics.add(serviceCharacteristic1); - ServiceCharacteristic serviceCharacteristic2 = new ServiceCharacteristic(); - serviceCharacteristic2.setName("provider-site-id"); - Value value2 = new Value(); - value2.setServiceCharacteristicValue("654321"); - serviceCharacteristic2.setValue(value2); - serviceCharacteristics.add(serviceCharacteristic2); - serviceOrderItem.getService().setServiceCharacteristic(serviceCharacteristics); - } - - testServiceOrder.setState(StateType.ACKNOWLEDGED); - testServiceOrder.setId("test"); - serviceOrderRepository.save(testServiceOrder); - - LinkedHashMap<String, Object> sdcResponse = new LinkedHashMap<>(); - sdcResponse.put("invariantUUID", "uuid"); - sdcResponse.put("name", "vFW"); - sdcResponse.put("version", "v1"); - sdcResponse.put("category", "E2E Service"); - - List<ResourceSpecification> resourceSpecs = new ArrayList<>(); - ResourceSpecification resourceSpecificationA = new ResourceSpecification(); - resourceSpecificationA.setId("2e3feeb0-8e36-46c6-862c-236d9c626438"); - resourceSpecificationA.setInstanceName("vFW-vSINK"); - resourceSpecificationA.setName("vFW-SINK"); - resourceSpecificationA.setType("ONAPresource"); - resourceSpecificationA.setVersion("2.0"); - resourceSpecificationA.setResourceInvariantUUID("6e3feeb0-8e36-46c6-862c-236d9c626438"); - resourceSpecs.add(resourceSpecificationA); - - sdcResponse.put("resourceSpecification", resourceSpecs ); - - ServiceOrderInfo serviceOrderInfo = new ServiceOrderInfo(); - serviceOrderInfo.setServiceOrderId("test"); - SubscriberInfo subscriberInfo = new SubscriberInfo(); - subscriberInfo.setGlobalSubscriberId("6490"); - subscriberInfo.setSubscriberName("edgar"); - serviceOrderInfo.setSubscriberInfo(subscriberInfo); - - ServiceOrderItemInfo serviceOrderItemInfoA = new ServiceOrderItemInfo(); - serviceOrderItemInfoA.setId("A"); - serviceOrderItemInfoA.setCatalogResponse(sdcResponse); - - ServiceOrderItemInfo serviceOrderItemInfoB = new ServiceOrderItemInfo(); - serviceOrderItemInfoB.setId("B"); - serviceOrderItemInfoB.setCatalogResponse(sdcResponse); - serviceOrderInfo.addServiceOrderItemInfos("A", serviceOrderItemInfoA); - serviceOrderInfo.addServiceOrderItemInfos("B", serviceOrderItemInfoB); - - String json = JsonEntityConverter.convertServiceOrderInfoToJson(serviceOrderInfo); - - ExecutionTask executionTaskA = new ExecutionTask(); - executionTaskA.setCreateDate(new Date()); - executionTaskA.setOrderItemId("A"); - executionTaskA.setServiceOrderInfoJson(json); - executionTaskA = executionTaskRepository.save(executionTaskA); - ExecutionTask executionTaskB = new ExecutionTask(); - executionTaskB.setCreateDate(new Date()); - executionTaskB.setOrderItemId("B"); - executionTaskB.setReliedTasks(String.valueOf(executionTaskA.getInternalId())); - executionTaskB.setServiceOrderInfoJson(json); - executionTaskRepository.save(executionTaskB); - return executionTaskA; - } + testServiceOrder.setState(StateType.ACKNOWLEDGED); + testServiceOrder.setId("test"); + serviceOrderRepository.save(testServiceOrder); + + LinkedHashMap<String, Object> sdcResponse = new LinkedHashMap<>(); + sdcResponse.put("invariantUUID", "uuid"); + sdcResponse.put("name", "vFW"); + sdcResponse.put("version", "v1"); + sdcResponse.put("category", "E2E Service"); + + List<ResourceSpecification> resourceSpecs = new ArrayList<>(); + ResourceSpecification resourceSpecificationA = new ResourceSpecification(); + resourceSpecificationA.setId("2e3feeb0-8e36-46c6-862c-236d9c626438"); + resourceSpecificationA.setInstanceName("vFW-vSINK"); + resourceSpecificationA.setName("vFW-SINK"); + resourceSpecificationA.setType("ONAPresource"); + resourceSpecificationA.setVersion("2.0"); + resourceSpecificationA.setResourceInvariantUUID("6e3feeb0-8e36-46c6-862c-236d9c626438"); + resourceSpecs.add(resourceSpecificationA); + + sdcResponse.put("resourceSpecification", resourceSpecs); + + ServiceOrderInfo serviceOrderInfo = new ServiceOrderInfo(); + serviceOrderInfo.setServiceOrderId("test"); + SubscriberInfo subscriberInfo = new SubscriberInfo(); + subscriberInfo.setGlobalSubscriberId("6490"); + subscriberInfo.setSubscriberName("edgar"); + serviceOrderInfo.setSubscriberInfo(subscriberInfo); + + ServiceOrderItemInfo serviceOrderItemInfoA = new ServiceOrderItemInfo(); + serviceOrderItemInfoA.setId("A"); + serviceOrderItemInfoA.setCatalogResponse(sdcResponse); + + ServiceOrderItemInfo serviceOrderItemInfoB = new ServiceOrderItemInfo(); + serviceOrderItemInfoB.setId("B"); + serviceOrderItemInfoB.setCatalogResponse(sdcResponse); + serviceOrderInfo.addServiceOrderItemInfos("A", serviceOrderItemInfoA); + serviceOrderInfo.addServiceOrderItemInfos("B", serviceOrderItemInfoB); + + String json = JsonEntityConverter.convertServiceOrderInfoToJson(serviceOrderInfo); + + ExecutionTask executionTaskA = new ExecutionTask(); + executionTaskA.setCreateDate(new Date()); + executionTaskA.setOrderItemId("A"); + executionTaskA.setServiceOrderInfoJson(json); + executionTaskA = executionTaskRepository.save(executionTaskA); + ExecutionTask executionTaskB = new ExecutionTask(); + executionTaskB.setCreateDate(new Date()); + executionTaskB.setOrderItemId("B"); + executionTaskB.setReliedTasks(String.valueOf(executionTaskA.getInternalId())); + executionTaskB.setServiceOrderInfoJson(json); + executionTaskRepository.save(executionTaskB); + return executionTaskA; + } + + public static ExecutionTask setUpBddForE2EExecutionTaskSucessWithObject( + ServiceOrderRepository serviceOrderRepository, + ExecutionTaskRepository executionTaskRepository, ActionType actionType) { + ServiceOrder testServiceOrder = createTestServiceOrder(actionType); + + for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) { + serviceOrderItem.setState(StateType.ACKNOWLEDGED); + List<ServiceCharacteristic> serviceCharacteristics = new ArrayList(); + ServiceCharacteristic serviceCharacteristic1 = new ServiceCharacteristic(); + serviceCharacteristic1.setName("EPL_ServiceCharacteristics"); + serviceCharacteristic1.setValueType("object"); + Value value1 = new Value(); + value1.setServiceCharacteristicValue("{ \"key1\":\"value1\", \"key2\":\"value2\"}"); + serviceCharacteristic1.setValue(value1); + serviceCharacteristics.add(serviceCharacteristic1); + serviceOrderItem.getService().setServiceCharacteristic(serviceCharacteristics); + } + testServiceOrder.setState(StateType.ACKNOWLEDGED); + testServiceOrder.setId("test"); + serviceOrderRepository.save(testServiceOrder); + + LinkedHashMap<String, Object> sdcResponse = new LinkedHashMap<>(); + sdcResponse.put("invariantUUID", "uuid"); + sdcResponse.put("name", "vFW"); + sdcResponse.put("version", "v1"); + sdcResponse.put("category", "E2E Service"); + + List<ResourceSpecification> resourceSpecs = new ArrayList<>(); + ResourceSpecification resourceSpecificationA = new ResourceSpecification(); + resourceSpecificationA.setId("2e3feeb0-8e36-46c6-862c-236d9c626438"); + resourceSpecificationA.setInstanceName("vFW-vSINK"); + resourceSpecificationA.setName("vFW-SINK"); + resourceSpecificationA.setType("ONAPresource"); + resourceSpecificationA.setVersion("2.0"); + resourceSpecificationA.setResourceInvariantUUID("6e3feeb0-8e36-46c6-862c-236d9c626438"); + resourceSpecs.add(resourceSpecificationA); + + sdcResponse.put("resourceSpecification", resourceSpecs); + + ServiceOrderInfo serviceOrderInfo = new ServiceOrderInfo(); + serviceOrderInfo.setServiceOrderId("test"); + SubscriberInfo subscriberInfo = new SubscriberInfo(); + subscriberInfo.setGlobalSubscriberId("6490"); + subscriberInfo.setSubscriberName("edgar"); + serviceOrderInfo.setSubscriberInfo(subscriberInfo); + + ServiceOrderItemInfo serviceOrderItemInfoA = new ServiceOrderItemInfo(); + serviceOrderItemInfoA.setId("A"); + serviceOrderItemInfoA.setCatalogResponse(sdcResponse); + + ServiceOrderItemInfo serviceOrderItemInfoB = new ServiceOrderItemInfo(); + serviceOrderItemInfoB.setId("B"); + serviceOrderItemInfoB.setCatalogResponse(sdcResponse); + serviceOrderInfo.addServiceOrderItemInfos("A", serviceOrderItemInfoA); + serviceOrderInfo.addServiceOrderItemInfos("B", serviceOrderItemInfoB); + + String json = JsonEntityConverter.convertServiceOrderInfoToJson(serviceOrderInfo); + + ExecutionTask executionTaskA = new ExecutionTask(); + executionTaskA.setCreateDate(new Date()); + executionTaskA.setOrderItemId("A"); + executionTaskA.setServiceOrderInfoJson(json); + executionTaskA = executionTaskRepository.save(executionTaskA); + ExecutionTask executionTaskB = new ExecutionTask(); + executionTaskB.setCreateDate(new Date()); + executionTaskB.setOrderItemId("B"); + executionTaskB.setReliedTasks(String.valueOf(executionTaskA.getInternalId())); + executionTaskB.setServiceOrderInfoJson(json); + executionTaskRepository.save(executionTaskB); + return executionTaskA; + } + + public static ExecutionTask setUpBddForE2EExecutionTaskSucessWithComplexObject( + ServiceOrderRepository serviceOrderRepository, + ExecutionTaskRepository executionTaskRepository, ActionType actionType) { + ServiceOrder testServiceOrder = createTestServiceOrder(actionType); + + for (ServiceOrderItem serviceOrderItem : testServiceOrder.getOrderItem()) { + serviceOrderItem.setState(StateType.ACKNOWLEDGED); + List<ServiceCharacteristic> serviceCharacteristics = new ArrayList(); + ServiceCharacteristic serviceCharacteristic1 = new ServiceCharacteristic(); + serviceCharacteristic1.setName("EPL_ServiceCharacteristics"); + serviceCharacteristic1.setValueType("object"); + Value value1 = new Value(); + // Three parameters , one is an array of child objects + value1.setServiceCharacteristicValue( + "{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":[ {\"lat1\":\"value1\",\"lon1\":\"value1\"}, { \"lat2\":\"value2\", \"lon2\":\"value2\"}]}"); + serviceCharacteristic1.setValue(value1); + serviceCharacteristics.add(serviceCharacteristic1); + serviceOrderItem.getService().setServiceCharacteristic(serviceCharacteristics); + } + testServiceOrder.setState(StateType.ACKNOWLEDGED); + testServiceOrder.setId("test"); + serviceOrderRepository.save(testServiceOrder); + + LinkedHashMap<String, Object> sdcResponse = new LinkedHashMap<>(); + sdcResponse.put("invariantUUID", "uuid"); + sdcResponse.put("name", "vFW"); + sdcResponse.put("version", "v1"); + sdcResponse.put("category", "E2E Service"); + + List<ResourceSpecification> resourceSpecs = new ArrayList<>(); + ResourceSpecification resourceSpecificationA = new ResourceSpecification(); + resourceSpecificationA.setId("2e3feeb0-8e36-46c6-862c-236d9c626438"); + resourceSpecificationA.setInstanceName("vFW-vSINK"); + resourceSpecificationA.setName("vFW-SINK"); + resourceSpecificationA.setType("ONAPresource"); + resourceSpecificationA.setVersion("2.0"); + resourceSpecificationA.setResourceInvariantUUID("6e3feeb0-8e36-46c6-862c-236d9c626438"); + resourceSpecs.add(resourceSpecificationA); + + sdcResponse.put("resourceSpecification", resourceSpecs); + + ServiceOrderInfo serviceOrderInfo = new ServiceOrderInfo(); + serviceOrderInfo.setServiceOrderId("test"); + SubscriberInfo subscriberInfo = new SubscriberInfo(); + subscriberInfo.setGlobalSubscriberId("6490"); + subscriberInfo.setSubscriberName("edgar"); + serviceOrderInfo.setSubscriberInfo(subscriberInfo); + + ServiceOrderItemInfo serviceOrderItemInfoA = new ServiceOrderItemInfo(); + serviceOrderItemInfoA.setId("A"); + serviceOrderItemInfoA.setCatalogResponse(sdcResponse); + + ServiceOrderItemInfo serviceOrderItemInfoB = new ServiceOrderItemInfo(); + serviceOrderItemInfoB.setId("B"); + serviceOrderItemInfoB.setCatalogResponse(sdcResponse); + serviceOrderInfo.addServiceOrderItemInfos("A", serviceOrderItemInfoA); + serviceOrderInfo.addServiceOrderItemInfos("B", serviceOrderItemInfoB); + + String json = JsonEntityConverter.convertServiceOrderInfoToJson(serviceOrderInfo); + + ExecutionTask executionTaskA = new ExecutionTask(); + executionTaskA.setCreateDate(new Date()); + executionTaskA.setOrderItemId("A"); + executionTaskA.setServiceOrderInfoJson(json); + executionTaskA = executionTaskRepository.save(executionTaskA); + ExecutionTask executionTaskB = new ExecutionTask(); + executionTaskB.setCreateDate(new Date()); + executionTaskB.setOrderItemId("B"); + executionTaskB.setReliedTasks(String.valueOf(executionTaskA.getInternalId())); + executionTaskB.setServiceOrderInfoJson(json); + executionTaskRepository.save(executionTaskB); + return executionTaskA; + } } diff --git a/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java b/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java index 68a955f..0043a8a 100644 --- a/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java +++ b/src/test/java/org/onap/nbi/apis/servicecatalog/ToscaInfosProcessorTest.java @@ -23,13 +23,13 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.onap.nbi.exceptions.TechnicalException; import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; @RunWith(SpringRunner.class) @@ -48,7 +48,7 @@ public class ToscaInfosProcessorTest { ClassLoader classLoader = getClass().getClassLoader(); Path path = new File( - classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile()) + classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile()) .toPath().toAbsolutePath(); List<LinkedHashMap> resources = new ArrayList<>(); LinkedHashMap resource1 = new LinkedHashMap(); @@ -64,22 +64,22 @@ public class ToscaInfosProcessorTest { toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response); } catch (SdcToscaParserException e) { throw new TechnicalException("unable to build response from tosca csar using sdc-parser : " - + path.toString() + " " + e.getMessage()); + + path.toString() + " " + e.getMessage()); } resources = (List<LinkedHashMap>) response.get("resourceSpecification"); List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>(); serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic"); assertThat(serviceSpecCharacteristic.get(0).get("name")) - .isEqualTo("sdwanconnectivity0_topology"); + .isEqualTo("sdwanconnectivity0_topology"); assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string"); assertThat(serviceSpecCharacteristic.get(0).get("required")).isEqualTo(true); assertThat(serviceSpecCharacteristic.get(1).get("name")).isEqualTo("sdwanconnectivity0_name"); assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string"); assertThat(serviceSpecCharacteristic.get(1).get("required")).isEqualTo(true); assertThat(resources.get(0).get("modelCustomizationId")) - .isEqualTo("94ec574b-2306-4cbd-8214-09662b040f73"); + .isEqualTo("94ec574b-2306-4cbd-8214-09662b040f73"); assertThat(resources.get(1).get("modelCustomizationId")) - .isEqualTo("a7baba5d-6ac3-42b5-b47d-070841303ab1"); + .isEqualTo("a7baba5d-6ac3-42b5-b47d-070841303ab1"); } @@ -88,7 +88,7 @@ public class ToscaInfosProcessorTest { ClassLoader classLoader = getClass().getClassLoader(); Path path = new File( - classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile()) + classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile()) .toPath().toAbsolutePath(); List<LinkedHashMap> resources = new ArrayList<>(); LinkedHashMap resource1 = new LinkedHashMap(); @@ -104,15 +104,15 @@ public class ToscaInfosProcessorTest { toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response); } catch (SdcToscaParserException e) { throw new TechnicalException("unable to build response from tosca csar using sdc-parser : " - + path.toString() + " " + e.getMessage()); + + path.toString() + " " + e.getMessage()); } resources = (List<LinkedHashMap>) response.get("resourceSpecification"); List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>(); serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic"); assertThat(resources.get(0).get("modelCustomizationId")) - .isEqualTo("b44071c8-04fd-4d6b-b6af-772cbfaa1129"); + .isEqualTo("b44071c8-04fd-4d6b-b6af-772cbfaa1129"); assertThat(resources.get(1).get("modelCustomizationId")) - .isEqualTo("c3612284-6c67-4d8c-8b41-b699cc90e76d"); + .isEqualTo("c3612284-6c67-4d8c-8b41-b699cc90e76d"); assertThat(serviceSpecCharacteristic.get(12).get("serviceSpecCharacteristicValue")).isNull(); assertThat(serviceSpecCharacteristic.get(13).get("serviceSpecCharacteristicValue")).isNotNull(); } @@ -122,7 +122,7 @@ public class ToscaInfosProcessorTest { ClassLoader classLoader = getClass().getClassLoader(); Path path = new File( - classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile()) + classLoader.getResource("toscafile/service-Sdwanvpninfraservice-csar.csar").getFile()) .toPath().toAbsolutePath(); List<LinkedHashMap> resources = new ArrayList<>(); LinkedHashMap resource1 = new LinkedHashMap(); @@ -138,13 +138,13 @@ public class ToscaInfosProcessorTest { toscaInfosProcessor.buildResponseWithSdcToscaParser(path, response); } catch (SdcToscaParserException e) { throw new TechnicalException("unable to build response from tosca csar using sdc-parser : " - + path.toString() + " " + e.getMessage()); + + path.toString() + " " + e.getMessage()); } resources = (List<LinkedHashMap>) response.get("resourceSpecification"); List<LinkedHashMap> serviceSpecCharacteristic = new ArrayList<>(); serviceSpecCharacteristic = (List<LinkedHashMap>) response.get("serviceSpecCharacteristic"); assertThat(serviceSpecCharacteristic.get(0).get("name")) - .isEqualTo("sdwanconnectivity0_topology"); + .isEqualTo("sdwanconnectivity0_topology"); assertThat(serviceSpecCharacteristic.get(1).get("valueType")).isEqualTo("string"); assertThat(serviceSpecCharacteristic.get(0).get("required")).isEqualTo(true); assertThat(serviceSpecCharacteristic.get(1).get("name")).isEqualTo("sdwanconnectivity0_name"); @@ -160,7 +160,9 @@ public class ToscaInfosProcessorTest { public void testBuildAndSaveResponseWithSdcToscaParser() { ClassLoader classLoader = getClass().getClassLoader(); - Path path = new File(classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile()).toPath().toAbsolutePath(); + Path path = new File( + classLoader.getResource("toscafile/service-Sotnvpninfraservice-csar.csar").getFile()) + .toPath().toAbsolutePath(); LinkedHashMap response = new LinkedHashMap(); response.put("version", "1.0"); @@ -179,17 +181,20 @@ public class ToscaInfosProcessorTest { response.put("resourceSpecification", resources); LinkedHashMap serviceSpecCharacteristicValue = new LinkedHashMap(); - serviceSpecCharacteristicValue.put("valueType","Object"); - serviceSpecCharacteristicValue.put("@schemaLocation","/serviceSpecification/7f5e5139-768d-4410-a871-c41430785214/specificationInputSchema"); - serviceSpecCharacteristicValue.put("@type","Service_vMME_ServiceCharacteristic"); + serviceSpecCharacteristicValue.put("valueType", "object"); + serviceSpecCharacteristicValue.put("@schemaLocation", + "/serviceSpecification/7f5e5139-768d-4410-a871-c41430785214/specificationInputSchema"); + serviceSpecCharacteristicValue.put("@type", "Service_vMME_ServiceCharacteristic"); LinkedHashMap serviceSpecCharacteristic = new LinkedHashMap(); - serviceSpecCharacteristic.put("name","Service_vMME_ServiceCharacteristics"); - serviceSpecCharacteristic.put("description", "This object describes all the inputs needed from the client to interact with the Service_vMME Service Topology"); - serviceSpecCharacteristic.put("valueType","Object"); - serviceSpecCharacteristic.put("@type","ONAPServiceCharacteristic"); - serviceSpecCharacteristic.put("@schemaLocation","null"); - serviceSpecCharacteristic.put("serviceSpecCharacteristicValue",serviceSpecCharacteristicValue); + serviceSpecCharacteristic.put("name", "Service_vMME_ServiceCharacteristics"); + serviceSpecCharacteristic.put("description", + "This object describes all the inputs needed from the client to interact with the Service_vMME Service Topology"); + // using object to match examples in specifications + serviceSpecCharacteristic.put("valueType", "object"); + serviceSpecCharacteristic.put("@type", "ONAPServiceCharacteristic"); + serviceSpecCharacteristic.put("@schemaLocation", "null"); + serviceSpecCharacteristic.put("serviceSpecCharacteristicValue", serviceSpecCharacteristicValue); try { toscaInfosProcessor.buildAndSaveResponseWithSdcToscaParser(path, response); } catch (SdcToscaParserException ex) { diff --git a/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java index 7bc8a41..4d32672 100644 --- a/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java +++ b/src/test/java/org/onap/nbi/test/ExecutionTaskTest.java @@ -1,26 +1,20 @@ /** - * Copyright (c) 2018 Orange + * Copyright (c) 2018 Orange * - * 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 + * 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 + * 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. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package org.onap.nbi.test; import static org.assertj.core.api.Assertions.assertThat; - -import com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult; -import com.github.tomakehurst.wiremock.http.ResponseDefinition; -import com.github.tomakehurst.wiremock.stubbing.StubMapping; import java.util.Calendar; import java.util.Date; import java.util.List; @@ -52,522 +46,625 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult; +import com.github.tomakehurst.wiremock.http.ResponseDefinition; +import com.github.tomakehurst.wiremock.stubbing.StubMapping; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) @ActiveProfiles("test") -@DirtiesContext(classMode= ClassMode.AFTER_CLASS) +@DirtiesContext(classMode = ClassMode.AFTER_CLASS) public class ExecutionTaskTest { - @Autowired - ServiceOrderRepository serviceOrderRepository; + @Autowired + ServiceOrderRepository serviceOrderRepository; - @Autowired - ExecutionTaskRepository executionTaskRepository; + @Autowired + ExecutionTaskRepository executionTaskRepository; - @Autowired - SOTaskProcessor SoTaskProcessor; + @Autowired + SOTaskProcessor SoTaskProcessor; - static Validator validator; + static Validator validator; - @Before - public void before() { - MockHttpServletRequest request = new MockHttpServletRequest(); - RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); - } + @Before + public void before() { + MockHttpServletRequest request = new MockHttpServletRequest(); + RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); + } - @BeforeClass - public static void setUp() throws Exception { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - validator = factory.getValidator(); - Context.startWiremock(); - } + @BeforeClass + public static void setUp() throws Exception { + ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); + validator = factory.getValidator(); + Context.startWiremock(); + } - @AfterClass - public static void tearsDown() throws Exception { - Context.stopServers(); + @AfterClass + public static void tearsDown() throws Exception { + Context.stopServers(); - } + } - @After - public void tearsDownUpPort() throws Exception { - executionTaskRepository.deleteAll(); - serviceOrderRepository.deleteAll(); - Context.wireMockServer.resetToDefaultMappings(); + @After + public void tearsDownUpPort() throws Exception { + executionTaskRepository.deleteAll(); + serviceOrderRepository.deleteAll(); + Context.wireMockServer.resetToDefaultMappings(); - } + } - public ExecutionTask getExecutionTask(String orderItemId) { - for (ExecutionTask executionTask : executionTaskRepository.findAll()) { - if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) { - return executionTask; - } + public ExecutionTask getExecutionTask(String orderItemId) { + for (ExecutionTask executionTask : executionTaskRepository.findAll()) { + if (executionTask.getOrderItemId().equalsIgnoreCase(orderItemId)) { + return executionTask; + } - } - return null; } - - private void changeWireMockResponse(String s,int statusCode, String bodyContent) { - ListStubMappingsResult listStubMappingsResult = Context.wireMockServer.listAllStubMappings(); - ResponseDefinition responseDefinition = new ResponseDefinition(statusCode,bodyContent); - List<StubMapping> mappings = listStubMappingsResult.getMappings(); - for (StubMapping mapping : mappings) { - if (mapping.getRequest().getUrl().equals(s)) { - mapping.setResponse(responseDefinition); - } - } + return null; + } + + private void changeWireMockResponse(String s, int statusCode, String bodyContent) { + ListStubMappingsResult listStubMappingsResult = Context.wireMockServer.listAllStubMappings(); + ResponseDefinition responseDefinition = new ResponseDefinition(statusCode, bodyContent); + List<StubMapping> mappings = listStubMappingsResult.getMappings(); + for (StubMapping mapping : mappings) { + if (mapping.getRequest().getUrl().equals(s)) { + mapping.setResponse(responseDefinition); + } } + } - private ServiceOrder getServiceOrder(String serviceOrderId) { - Optional<ServiceOrder> serviceOrderChecked = serviceOrderRepository.findById(serviceOrderId); - return serviceOrderChecked.get(); - } + private ServiceOrder getServiceOrder(String serviceOrderId) { + Optional<ServiceOrder> serviceOrderChecked = serviceOrderRepository.findById(serviceOrderId); + return serviceOrderChecked.get(); + } - @Test - public void testExecutionTaskSuccess() throws Exception { + @Test + public void testExecutionTaskSuccess() throws Exception { - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, executionTaskRepository, ActionType.ADD); - ExecutionTask executionTaskB; + ExecutionTask executionTaskB; + + + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } + } + + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); + + SoTaskProcessor.processOrderItem(executionTaskB); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } + assertThat(executionTaskRepository.count()).isEqualTo(0); - executionTaskB = getExecutionTask("B"); - assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA).isNull(); - SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } + } - assertThat(executionTaskRepository.count()).isEqualTo(0); + @Test + public void testE2EExecutionTaskSuccess() throws Exception { + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess( + serviceOrderRepository, executionTaskRepository, ActionType.ADD); + ExecutionTask executionTaskB; + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } } - @Test - public void testE2EExecutionTaskSuccess() throws Exception { + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); - ExecutionTask executionTaskB; + SoTaskProcessor.processOrderItem(executionTaskB); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } + assertThat(executionTaskRepository.count()).isEqualTo(0); - executionTaskB = getExecutionTask("B"); - assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA).isNull(); - SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } + } - assertThat(executionTaskRepository.count()).isEqualTo(0); + @Test + public void testE2EExecutionTaskSuccessWithObject() throws Exception { + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucessWithObject( + serviceOrderRepository, executionTaskRepository, ActionType.ADD); + ExecutionTask executionTaskB; + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } } - @Test - public void testExecutionTaskDeleteSuccess() throws Exception { + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.DELETE); - ExecutionTask executionTaskB; + SoTaskProcessor.processOrderItem(executionTaskB); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } + + assertThat(executionTaskRepository.count()).isEqualTo(0); - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } - executionTaskB = getExecutionTask("B"); - assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA).isNull(); - SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } - } + @Test + public void testE2EExecutionTaskSuccessWithComplexObject() throws Exception { + // A Service Order with complex object including arrays + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucessWithComplexObject( + serviceOrderRepository, executionTaskRepository, ActionType.ADD); + ExecutionTask executionTaskB; - assertThat(executionTaskRepository.count()).isEqualTo(0); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } + } + + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); + SoTaskProcessor.processOrderItem(executionTaskB); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); } - @Test - public void testE2EExecutionTaskDeleteSuccess() throws Exception { + assertThat(executionTaskRepository.count()).isEqualTo(0); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository, + + + } + + @Test + public void testExecutionTaskDeleteSuccess() throws Exception { + + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, executionTaskRepository, ActionType.DELETE); - ExecutionTask executionTaskB; + ExecutionTask executionTaskB; + + + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } + } + + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); + SoTaskProcessor.processOrderItem(executionTaskB); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + + } - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } + assertThat(executionTaskRepository.count()).isEqualTo(0); - executionTaskB = getExecutionTask("B"); - assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA).isNull(); - SoTaskProcessor.processOrderItem(executionTaskB); - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } + } - assertThat(executionTaskRepository.count()).isEqualTo(0); + @Test + public void testE2EExecutionTaskDeleteSuccess() throws Exception { + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess( + serviceOrderRepository, executionTaskRepository, ActionType.DELETE); + ExecutionTask executionTaskB; + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } } + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); - @Test - public void testExecutionTaskFailed() throws Exception { + SoTaskProcessor.processOrderItem(executionTaskB); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); + } - Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId"); + assertThat(executionTaskRepository.count()).isEqualTo(0); - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } - executionTaskA = getExecutionTask("A"); - Date createDate = executionTaskA.getCreateDate(); - assertThat(executionTaskA.getLastAttemptDate().getTime()> createDate.getTime()).isTrue(); - changeCreationDate(executionTaskA); - SoTaskProcessor.processOrderItem(executionTaskA); + } - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - } + @Test + public void testExecutionTaskFailed() throws Exception { - assertThat(executionTaskRepository.count()).isEqualTo(0); + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + executionTaskRepository, ActionType.ADD); + Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId"); - } - private void changeCreationDate(ExecutionTask executionTaskA) { - Calendar cal = Calendar.getInstance(); - cal.setTime(executionTaskA.getCreateDate()); - cal.add(Calendar.SECOND, -30); - executionTaskA.setCreateDate(cal.getTime()); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } } + executionTaskA = getExecutionTask("A"); + Date createDate = executionTaskA.getCreateDate(); + assertThat(executionTaskA.getLastAttemptDate().getTime() > createDate.getTime()).isTrue(); + changeCreationDate(executionTaskA); + SoTaskProcessor.processOrderItem(executionTaskA); - @Test - public void testE2EExecutionTaskFailed() throws Exception { + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); + + } + + assertThat(executionTaskRepository.count()).isEqualTo(0); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); - Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId"); + } + private void changeCreationDate(ExecutionTask executionTaskA) { + Calendar cal = Calendar.getInstance(); + cal.setTime(executionTaskA.getCreateDate()); + cal.add(Calendar.SECOND, -30); + executionTaskA.setCreateDate(cal.getTime()); + } - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA.getLastAttemptDate().getTime()>executionTaskA.getCreateDate().getTime()).isTrue(); - changeCreationDate(executionTaskA); - SoTaskProcessor.processOrderItem(executionTaskA); - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); + @Test + public void testE2EExecutionTaskFailed() throws Exception { - } + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess( + serviceOrderRepository, executionTaskRepository, ActionType.ADD); - assertThat(executionTaskRepository.count()).isEqualTo(0); + Context.removeWireMockMapping( + "/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId"); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } } + executionTaskA = getExecutionTask("A"); + assertThat( + executionTaskA.getLastAttemptDate().getTime() > executionTaskA.getCreateDate().getTime()) + .isTrue(); + changeCreationDate(executionTaskA); + SoTaskProcessor.processOrderItem(executionTaskA); + + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - @Test - public void testExecutionTaskFailedNoSoResponse() throws Exception { + } - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); + assertThat(executionTaskRepository.count()).isEqualTo(0); - Context.removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/"); + } - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - } + @Test + public void testExecutionTaskFailedNoSoResponse() throws Exception { - assertThat(executionTaskRepository.count()).isEqualTo(0); + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + executionTaskRepository, ActionType.ADD); + Context.removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/"); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); } - @Test - public void testExecutionTaskFailedNoSoAndStatusResponse() throws Exception { + assertThat(executionTaskRepository.count()).isEqualTo(0); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); - Context.removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/"); - Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId"); + } - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - } + @Test + public void testExecutionTaskFailedNoSoAndStatusResponse() throws Exception { - assertThat(executionTaskRepository.count()).isEqualTo(0); + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + executionTaskRepository, ActionType.ADD); + + Context.removeWireMockMapping("/onap/so/infra/serviceInstantiation/v7/serviceInstances/"); + Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId"); + + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); } - @Test - public void testE2EExecutionTaskFailedNoSoAndStatusResponse() throws Exception { + assertThat(executionTaskRepository.count()).isEqualTo(0); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); + } - Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3"); - Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId"); + @Test + public void testE2EExecutionTaskFailedNoSoAndStatusResponse() throws Exception { + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForE2EExecutionTaskSucess( + serviceOrderRepository, executionTaskRepository, ActionType.ADD); - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - } + Context.removeWireMockMapping("/onap/so/infra/e2eServiceInstances/v3"); + Context.removeWireMockMapping( + "/onap/so/infra/e2eServiceInstances/v3/serviceId/operations/operationId"); - assertThat(executionTaskRepository.count()).isEqualTo(0); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); } + assertThat(executionTaskRepository.count()).isEqualTo(0); - @Test - public void testExecutionTaskFailedBadRequestSo() throws Exception { + } - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + + @Test + public void testExecutionTaskFailedBadRequestSo() throws Exception { + + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, executionTaskRepository, ActionType.ADD); - changeWireMockResponse("/onap/so/infra/serviceInstantiation/v7/serviceInstances/",400,"\"serviceException\": {\n" - + " \"messageId\": \"SVC0002\",\n" + changeWireMockResponse("/onap/so/infra/serviceInstantiation/v7/serviceInstances/", 400, + "\"serviceException\": {\n" + " \"messageId\": \"SVC0002\",\n" + " \"text\": \"Error parsing request. org.openecomp.mso.apihandler.common.ValidationException: serviceInstance already existsd\"\n" + " }"); - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - } - - assertThat(executionTaskRepository.count()).isEqualTo(0); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); + } - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if(serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1); - assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("105"); - assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()).isEqualTo("service.name"); - } - } + assertThat(executionTaskRepository.count()).isEqualTo(0); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getOrderItemMessage().size()).isEqualTo(1); + assertThat(serviceOrderItem.getOrderItemMessage().get(0).getCode()).isEqualTo("105"); + assertThat(serviceOrderItem.getOrderItemMessage().get(0).getField()) + .isEqualTo("service.name"); + } } + } - @Test - public void testExecutionTaskModifySuccess() throws Exception { - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + @Test + public void testExecutionTaskModifySuccess() throws Exception { + + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, executionTaskRepository, ActionType.MODIFY); - ExecutionTask executionTaskB; - - - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - //assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } - SoTaskProcessor.processOrderItem(executionTaskA); - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } - - executionTaskB = getExecutionTask("B"); - assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA).isNull(); - - SoTaskProcessor.processOrderItem(executionTaskB); - SoTaskProcessor.processOrderItem(executionTaskB); - - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); - - } - - assertThat(executionTaskRepository.count()).isEqualTo(0); + ExecutionTask executionTaskB; + + + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + // assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); + assertThat(serviceOrderItem.getState()) + .isEqualTo(StateType.INPROGRESS_MODIFY_ITEM_TO_CREATE); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } + } + SoTaskProcessor.processOrderItem(executionTaskA); + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } + } + + executionTaskB = getExecutionTask("B"); + assertThat(executionTaskB.getReliedTasks()).isNullOrEmpty(); + executionTaskA = getExecutionTask("A"); + assertThat(executionTaskA).isNull(); + + SoTaskProcessor.processOrderItem(executionTaskB); + SoTaskProcessor.processOrderItem(executionTaskB); + + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.COMPLETED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.COMPLETED); } + assertThat(executionTaskRepository.count()).isEqualTo(0); + } - @Test - public void testExecutionTaskModifyFailed() throws Exception { - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + @Test + public void testExecutionTaskModifyFailed() throws Exception { + + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, executionTaskRepository, ActionType.MODIFY); - ExecutionTask executionTaskB; - Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId"); - - - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - if (serviceOrderItem.getId().equals("A")) { - //assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND); - } else { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); - } - } - executionTaskA = getExecutionTask("A"); - assertThat(executionTaskA.getLastAttemptDate().getTime()>executionTaskA.getCreateDate().getTime()).isTrue(); - changeCreationDate(executionTaskA); - SoTaskProcessor.processOrderItem(executionTaskA); - - serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - - } - - assertThat(executionTaskRepository.count()).isEqualTo(0); + ExecutionTask executionTaskB; + Context.removeWireMockMapping("/onap/so/infra/orchestrationRequests/v7/requestId"); + + + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.INPROGRESS); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + if (serviceOrderItem.getId().equals("A")) { + // assertThat(serviceOrderItem.getState()).isEqualTo(StateType.INPROGRESS); + assertThat(serviceOrderItem.getState()) + .isEqualTo(StateType.INPROGRESS_MODIFY_REQUEST_DELETE_SEND); + } else { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.ACKNOWLEDGED); + } + } + executionTaskA = getExecutionTask("A"); + assertThat( + executionTaskA.getLastAttemptDate().getTime() > executionTaskA.getCreateDate().getTime()) + .isTrue(); + changeCreationDate(executionTaskA); + SoTaskProcessor.processOrderItem(executionTaskA); + + serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); } - @Test - public void testExecutionTaskWithoutOnap() throws Exception { - Context.stopWiremock(); - ExecutionTask executionTaskA = ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, - executionTaskRepository, ActionType.ADD); + assertThat(executionTaskRepository.count()).isEqualTo(0); - SoTaskProcessor.processOrderItem(executionTaskA); - ServiceOrder serviceOrderChecked = getServiceOrder("test"); - assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); - for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { - assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); - } - assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0); - assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502"); - assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()).isEqualTo("Problem with SO API"); + } - assertThat(executionTaskRepository.count()).isEqualTo(0); - Context.startWiremock(); + @Test + public void testExecutionTaskWithoutOnap() throws Exception { + Context.stopWiremock(); + ExecutionTask executionTaskA = + ServiceOrderExecutionTaskAssertions.setUpBddForExecutionTaskSucess(serviceOrderRepository, + executionTaskRepository, ActionType.ADD); + SoTaskProcessor.processOrderItem(executionTaskA); + ServiceOrder serviceOrderChecked = getServiceOrder("test"); + assertThat(serviceOrderChecked.getState()).isEqualTo(StateType.FAILED); + for (ServiceOrderItem serviceOrderItem : serviceOrderChecked.getOrderItem()) { + assertThat(serviceOrderItem.getState()).isEqualTo(StateType.FAILED); } + assertThat(serviceOrderChecked.getOrderMessage().size()).isGreaterThan(0); + assertThat(serviceOrderChecked.getOrderMessage().get(0).getCode()).isEqualTo("502"); + assertThat(serviceOrderChecked.getOrderMessage().get(0).getMessageInformation()) + .isEqualTo("Problem with SO API"); + + assertThat(executionTaskRepository.count()).isEqualTo(0); + Context.startWiremock(); + + } -}
\ No newline at end of file +} diff --git a/src/test/resources/karatetest/features/00--ServiceCatalog.feature b/src/test/resources/karatetest/features/00--ServiceCatalog.feature index 728d3c8..25f15df 100644 --- a/src/test/resources/karatetest/features/00--ServiceCatalog.feature +++ b/src/test/resources/karatetest/features/00--ServiceCatalog.feature @@ -42,12 +42,12 @@ And match $.serviceSpecCharacteristic contains { name : 'vFW_ServiceCharacteristics', description : 'This object describes all the inputs needed from the client to interact with the vFW Service Topology', - valueType : 'Object', + valueType : 'object', @type : 'ONAPServiceCharacteristic', @schemaLocation : 'null', serviceSpecCharacteristicValue : { - valueType : 'Object', + valueType : 'object', @schemaLocation : '/serviceSpecification/462f84e5-f0e5-44c5-ab95-38fb4bf77064/specificationInputSchema', @type : 'vFW_ServiceCharacteristic', } |