From ff08d87f973c3aa4c041a55d42ae73a51593b7ca Mon Sep 17 00:00:00 2001 From: golabek Date: Wed, 27 Feb 2019 16:47:09 +0100 Subject: VnfInPlaceFields and ScaleOut rendered dynamically * hardcoded workflows parameters moved to the internal API. * html changed to dynamically render parameters from the new API. Change-Id: Id2f61dbf88ae65401a8974422ab7c6da07053da2 Issue-ID: VID-398 Signed-off-by: Tomasz Golabek --- .../onap/vid/controller/WorkflowsController.java | 26 ++-- .../main/java/org/onap/vid/model/SOWorkflows.kt | 53 +++++-- .../org/onap/vid/services/ExtWorkflowsService.java | 31 ---- .../onap/vid/services/ExtWorkflowsServiceImpl.java | 79 ---------- .../vid/services/ExternalWorkflowsService.java | 31 ++++ .../vid/services/ExternalWorkflowsServiceImpl.java | 79 ++++++++++ .../onap/vid/services/LocalWorkflowsService.java | 26 ++++ .../vid/services/LocalWorkflowsServiceImpl.java | 58 ++++++++ .../vid/scripts/constants/componentConstants.js | 3 +- .../new-change-management.controller.js | 90 +++++++---- .../new-change-management.controller.test.js | 165 ++++++++++++++++++++- .../new-change-management.html | 40 ++--- .../scripts/services/change-management.service.js | 9 +- .../vid/services/ExtWorkflowServiceImplTest.java | 118 --------------- .../services/ExternalWorkflowServiceImplTest.java | 116 +++++++++++++++ 15 files changed, 620 insertions(+), 304 deletions(-) delete mode 100644 vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java delete mode 100644 vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsService.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsServiceImpl.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java create mode 100644 vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java delete mode 100644 vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java create mode 100644 vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java (limited to 'vid-app-common/src') diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java index b8f033c95..a94481b9e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/WorkflowsController.java @@ -21,10 +21,11 @@ package org.onap.vid.controller; import java.util.List; -import org.onap.portalsdk.core.controller.RestrictedBaseController; +import org.onap.vid.model.LocalWorkflowParameterDefinitions; import org.onap.vid.model.SOWorkflow; import org.onap.vid.model.SOWorkflowParameterDefinitions; -import org.onap.vid.services.ExtWorkflowsService; +import org.onap.vid.services.ExternalWorkflowsService; +import org.onap.vid.services.LocalWorkflowsService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -34,24 +35,31 @@ import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping(WorkflowsController.WORKFLOWS_MANAGEMENT) -public class WorkflowsController extends RestrictedBaseController { +public class WorkflowsController extends VidRestrictedBaseController { static final String WORKFLOWS_MANAGEMENT = "workflows-management"; - private ExtWorkflowsService extWorkflowsService; + private ExternalWorkflowsService externalWorkflowsService; + private LocalWorkflowsService localWorkflowsService; @Autowired - public WorkflowsController(ExtWorkflowsService extWorkflowsService) { - this.extWorkflowsService = extWorkflowsService; + public WorkflowsController(ExternalWorkflowsService externalWorkflowsService, LocalWorkflowsService localWorkflowsService) { + this.externalWorkflowsService = externalWorkflowsService; + this.localWorkflowsService = localWorkflowsService; } @RequestMapping(value = "workflows", method = RequestMethod.GET) public List getWorkflows(@RequestParam(value = "vnfName") String vnfName){ - return extWorkflowsService.getWorkflows(vnfName); + return externalWorkflowsService.getWorkflows(vnfName); } - @RequestMapping(value = "workflow-parameters/{id}", method = RequestMethod.GET) + @RequestMapping(value = "remote-workflow-parameters/{id}", method = RequestMethod.GET) SOWorkflowParameterDefinitions getParameters(@PathVariable Long id) { - return extWorkflowsService.getWorkflowParameterDefinitions(id); + return externalWorkflowsService.getWorkflowParameterDefinitions(id); + } + + @RequestMapping(value = "local-workflow-parameters/{name}", method = RequestMethod.GET) + LocalWorkflowParameterDefinitions getParameters(@PathVariable String name) { + return localWorkflowsService.getWorkflowParameterDefinitions(name); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt index 9fbae0612..b88c3f6f6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt +++ b/vid-app-common/src/main/java/org/onap/vid/model/SOWorkflows.kt @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * VID * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,27 +20,62 @@ package org.onap.vid.model -data class SOWorkflow constructor(val id: Long, val name: String) { +data class SOWorkflow constructor( + val id: Long, + val name: String) { fun clone(): SOWorkflow { return copy() } } -data class SOWorkflows @JvmOverloads constructor(val workflows: List = emptyList()) { +data class SOWorkflows @JvmOverloads constructor( + val workflows: List = emptyList()) { fun clone(): SOWorkflows { return copy(workflows.toMutableList()) } } -enum class SOWorkflowType(val type: String) { +enum class SOWorkflowType( + val type: String) { STRING("STRING") } -data class SOWorkflowParameterDefinition constructor(val id: Long, val name: String, val pattern: String, - val type: SOWorkflowType, val required: Boolean) +enum class LocalWorkflowType( + val type: String) { + STRING("STRING"), + FILE("FILE") +} + +data class SOWorkflowParameterDefinition constructor( + val id: Long, + val name: String, + val pattern: String, + val type: SOWorkflowType, + val required: Boolean) -data class SOWorkflowParameterDefinitions constructor(val parameterDefinitions: List = emptyList()) { +data class SOWorkflowParameterDefinitions constructor( + val parameterDefinitions: List = emptyList()) { fun clone(): SOWorkflowParameterDefinitions { return copy(parameterDefinitions.toMutableList()) } } + +data class LocalWorkflowParameterDefinition @JvmOverloads constructor( + val id: Long, + val name: String, + val required: Boolean, + val type: LocalWorkflowType, + val pattern: String? = null, + val msgOnPatternError: String? = null, + val msgOnContentError: String? = null, + val acceptableFileType: String? = null +) + +data class LocalWorkflowParameterDefinitions constructor( + val parameterDefinitions: List = emptyList() +) { + fun clone(): LocalWorkflowParameterDefinitions { + return copy(parameterDefinitions.toMutableList()) + } +} + diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java deleted file mode 100644 index a4450ca01..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsService.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.services; - -import java.util.List; -import org.onap.vid.model.SOWorkflow; -import org.onap.vid.model.SOWorkflowParameterDefinitions; - -public interface ExtWorkflowsService { - List getWorkflows(String vnfName); - - SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId); -} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java deleted file mode 100644 index 61ed2da67..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/services/ExtWorkflowsServiceImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.services; - -import java.util.List; -import org.onap.vid.model.SOWorkflow; -import org.onap.vid.model.SOWorkflowParameterDefinitions; -import org.onap.vid.model.SOWorkflows; -import org.onap.vid.mso.MsoResponseWrapper2; -import org.onap.vid.mso.rest.MockedWorkflowsRestClient; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class ExtWorkflowsServiceImpl implements ExtWorkflowsService { - - private MockedWorkflowsRestClient mockedWorkflowsRestClient; - - @Autowired - public ExtWorkflowsServiceImpl(MockedWorkflowsRestClient mockedWorkflowsRestClient) { - this.mockedWorkflowsRestClient = mockedWorkflowsRestClient; - } - - @Override - public List getWorkflows(String vnfName) { - MsoResponseWrapper2 msoResponse = mockedWorkflowsRestClient.getWorkflows(vnfName); - validateSOResponse(msoResponse, SOWorkflows.class); - return convertMsoResponseToWorkflowList(msoResponse); - } - - @Override - public SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId) { - MsoResponseWrapper2 msoResponse = mockedWorkflowsRestClient.getWorkflowParameterDefinitions(workflowId); - validateSOResponse(msoResponse, SOWorkflowParameterDefinitions.class); - return (SOWorkflowParameterDefinitions) msoResponse.getEntity(); - } - - private List convertMsoResponseToWorkflowList(MsoResponseWrapper2 msoResponse) { - SOWorkflows soWorkflows = (SOWorkflows) msoResponse.getEntity(); - return soWorkflows.getWorkflows(); - } - - private void validateSOResponse(MsoResponseWrapper2 response, Class expectedResponseClass){ - if (response.getStatus() >= 400 || !expectedResponseClass.isInstance(response.getEntity())) { - throw new BadResponseFromMso(response); - } - } - - public static class BadResponseFromMso extends RuntimeException { - private final MsoResponseWrapper2 msoResponse; - - BadResponseFromMso(MsoResponseWrapper2 msoResponse) { - this.msoResponse = msoResponse; - } - - public MsoResponseWrapper2 getMsoResponse() { - return msoResponse; - } - } - -} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsService.java new file mode 100644 index 000000000..da909a54d --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsService.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.services; + +import java.util.List; +import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinitions; + +public interface ExternalWorkflowsService { + List getWorkflows(String vnfName); + + SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsServiceImpl.java new file mode 100644 index 000000000..1da03f0ac --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/ExternalWorkflowsServiceImpl.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.services; + +import java.util.List; +import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinitions; +import org.onap.vid.model.SOWorkflows; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.rest.MockedWorkflowsRestClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ExternalWorkflowsServiceImpl implements ExternalWorkflowsService { + + private MockedWorkflowsRestClient mockedWorkflowsRestClient; + + @Autowired + public ExternalWorkflowsServiceImpl(MockedWorkflowsRestClient mockedWorkflowsRestClient) { + this.mockedWorkflowsRestClient = mockedWorkflowsRestClient; + } + + @Override + public List getWorkflows(String vnfName) { + MsoResponseWrapper2 msoResponse = mockedWorkflowsRestClient.getWorkflows(vnfName); + validateSOResponse(msoResponse, SOWorkflows.class); + return convertMsoResponseToWorkflowList(msoResponse); + } + + @Override + public SOWorkflowParameterDefinitions getWorkflowParameterDefinitions(Long workflowId) { + MsoResponseWrapper2 msoResponse = mockedWorkflowsRestClient.getWorkflowParameterDefinitions(workflowId); + validateSOResponse(msoResponse, SOWorkflowParameterDefinitions.class); + return (SOWorkflowParameterDefinitions) msoResponse.getEntity(); + } + + private List convertMsoResponseToWorkflowList(MsoResponseWrapper2 msoResponse) { + SOWorkflows soWorkflows = (SOWorkflows) msoResponse.getEntity(); + return soWorkflows.getWorkflows(); + } + + private void validateSOResponse(MsoResponseWrapper2 response, Class expectedResponseClass){ + if (response.getStatus() >= 400 || !expectedResponseClass.isInstance(response.getEntity())) { + throw new BadResponseFromMso(response); + } + } + + public static class BadResponseFromMso extends RuntimeException { + private final MsoResponseWrapper2 msoResponse; + + BadResponseFromMso(MsoResponseWrapper2 msoResponse) { + this.msoResponse = msoResponse; + } + + public MsoResponseWrapper2 getMsoResponse() { + return msoResponse; + } + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java new file mode 100644 index 000000000..b0674f0e3 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsService.java @@ -0,0 +1,26 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.services; + +import org.onap.vid.model.LocalWorkflowParameterDefinitions; + +public interface LocalWorkflowsService { + LocalWorkflowParameterDefinitions getWorkflowParameterDefinitions(String workflowName); +} diff --git a/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java new file mode 100644 index 000000000..733d275d8 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/services/LocalWorkflowsServiceImpl.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.vid.services; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import java.util.Map; +import org.onap.vid.model.LocalWorkflowParameterDefinition; +import org.onap.vid.model.LocalWorkflowParameterDefinitions; +import org.onap.vid.model.LocalWorkflowType; +import org.springframework.stereotype.Service; + +@Service +public class LocalWorkflowsServiceImpl implements LocalWorkflowsService { + + Map WORKFLOWS_WITH_PARAMETERS = ImmutableMap.builder() + .put("VNF Scale Out", new LocalWorkflowParameterDefinitions( + ImmutableList.of( + new LocalWorkflowParameterDefinition(1, "Configuration Parameters", true, LocalWorkflowType.STRING,".*") + ) + )) + .put("VNF In Place Software Update", new LocalWorkflowParameterDefinitions( + ImmutableList.of( + new LocalWorkflowParameterDefinition(2, "Operations timeout",true, LocalWorkflowType.STRING,"[0-9]+"), + new LocalWorkflowParameterDefinition(3, "Existing software version", true, LocalWorkflowType.STRING, "[-a-zA-Z0-9.]+"), + new LocalWorkflowParameterDefinition(4, "New software version", true, LocalWorkflowType.STRING, "[-a-zA-Z0-9.]+") + ) + )) + .put("VNF Config Update", new LocalWorkflowParameterDefinitions( + ImmutableList.of( + new LocalWorkflowParameterDefinition(5, "Attach configuration file", true, LocalWorkflowType.FILE, ".*", "Invalid file type. Please select a file with a CSV extension.", "Invalid file structure.", ".csv") + ) + )) + .build(); + + @Override + public LocalWorkflowParameterDefinitions getWorkflowParameterDefinitions(String workflowName) { + return WORKFLOWS_WITH_PARAMETERS.get(workflowName); + } + +} diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js b/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js index 4ac5f85ac..dbf6588ce 100755 --- a/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/constants/componentConstants.js @@ -116,7 +116,8 @@ appDS2 CHANGE_MANAGEMENT_OPERATION_NO_SCHEDULER: "change-management/workflow/@vnfName", GET_WORKFLOW: "change-management/get_vnf_workflow_relation", GET_SO_WORKFLOWS: "workflows-management/workflows", - GET_SO_WORKFLOW_PARAMETER: "workflows-management/workflow-parameters/@workflowID", + GET_SO_WORKFLOW_PARAMETER: "workflows-management/remote-workflow-parameters/@workflowID", + GET_LOCAL_WORKFLOW_PARAMETER: "workflows-management/local-workflow-parameters/@workflowName", GET_MSO_WORKFLOWS: "change-management/mso", GET_SCHEDULER_CHANGE_MANAGEMENTS: "change-management/scheduler", CANCEL_SCHEDULE_REQUEST: "change-management/scheduler/schedules", diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js index e525f0f5c..8a7d59a62 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.js @@ -28,8 +28,6 @@ var vm = this; vm.hasScheduler = !!VIDCONFIGURATION.SCHEDULER_PORTAL_URL; - vm.configUpdatePatternError = "Invalid file type. Please select a file with a CSV extension."; - vm.configUpdateContentError = "Invalid file structure."; vm.wizardStep = 1; vm.nextStep = function(){ @@ -202,7 +200,7 @@ }] }) .then(function (configUpdateResponse) { - vm.changeManagement.configUpdateFile = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload; + vm.getInternalWorkFlowParameter("VNF Config Update", "FILE", "Attach configuration file").value = configUpdateResponse && JSON.parse(configUpdateResponse.data).payload; defer.resolve(true); }) .catch(function (error) { @@ -218,7 +216,6 @@ var result = {}; result.requestType = changeManagement.workflow; var workflowType = changeManagement.workflow; - var configurationParameters = changeManagement.configurationParameters; result.requestDetails = []; _.forEach(changeManagement.vnfNames, function (vnf) { @@ -246,51 +243,50 @@ } }else if(workflowType=="VNF In Place Software Update"){ var payloadObj = { - 'existing_software_version':changeManagement.existingSoftwareVersion, - 'new_software_version':changeManagement.newSoftwareVersion, - 'operations_timeout':changeManagement.operationTimeout + 'existing_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Existing software version').value, + 'new_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'New software version').value, + 'operations_timeout':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Operations timeout').value }; requestParametersData = { payload: JSON.stringify(payloadObj) } }else if(workflowType=="VNF Config Update"){ requestParametersData = { - payload: changeManagement.configUpdateFile + payload: vm.getInternalWorkFlowParameter("VNF Config Update", "FILE", "Attach configuration file").value } - }else if(workflowType=="VNF Scale Out"){ - if(!moduleToScale) return null; - - if(moduleToScale.userParams) { - requestParametersData = { - userParams: moduleToScale.userParams - //,usePreload: true - } - }else{ - requestParametersData = { - userParams: [] - //,usePreload: false - } - } - } + }else if(workflowType=="VNF Scale Out"){ + if(!moduleToScale) return null; + + if(moduleToScale.userParams) { + requestParametersData = { + userParams: moduleToScale.userParams + //,usePreload: true + } + }else{ + requestParametersData = { + userParams: [] + //,usePreload: false + } + } + } $log.info('SchedulerWidgetCtrl:extractChangeManagementCallbackDataStr info:: workflowType '+ workflowType); $log.info('SchedulerWidgetCtrl:extractChangeManagementCallbackDataStr info:: requestParametersData '+ requestParametersData); }else if(workflowType=="VNF In Place Software Update"){ var payloadObj = { - 'existing_software_version':changeManagement.existingSoftwareVersion, - 'new_software_version':changeManagement.newSoftwareVersion, - 'operations_timeout':changeManagement.operationTimeout + 'existing_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Existing software version').value, + 'new_software_version':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'New software version').value, + 'operations_timeout':vm.getInternalWorkFlowParameter(workflowType, 'STRING', 'Operations timeout').value }; requestParametersData = { payload: JSON.stringify(payloadObj) } }else if(workflowType=="VNF Config Update"){ requestParametersData = { - payload: changeManagement.configUpdateFile + payload: vm.getInternalWorkFlowParameter("VNF Config Update", "FILE", "Attach configuration file").value } } - var data; if(workflowType=="VNF Scale Out") { data = { @@ -309,7 +305,7 @@ requestInfo: requestInfoData, relatedInstanceList: [], requestParameters:requestParametersData, - configurationParameters: JSON.parse(configurationParameters) + configurationParameters: JSON.parse(vm.getInternalWorkFlowParameter("VNF Scale Out", "STRING", "Configuration Parameters").value) }; requestInfoData.instanceName = vnf.name + "_" + (moduleToScale.currentCount + 1); }else{ @@ -641,6 +637,7 @@ // Should be corrected when VID-397 will be closed. At the moment there is a need // to merge local and remote workflows not to broke current functionality. return vm.loadLocalWorkFlows() + .then(vm.loadLocalWorkFlowsParameters) .then(vm.loadRemoteWorkFlows) .then(function () { vm.workflows = vm.localWorkflows.concat(vm.remoteWorkflows.map(item => item.name)); @@ -668,6 +665,28 @@ }); }; + vm.loadLocalWorkFlowsParameters = function () { + vm.localWorkflowsParameters = new Map(); + vm.localWorkflows.forEach(function(workflow) { + vm.loadLocalWorkFlowParameters(workflow); + }); + }; + + vm.loadLocalWorkFlowParameters = function (workflow) { + changeManagementService.getLocalWorkflowParameter(workflow) + .then(function (response) { + let fileParameters = response.data.parameterDefinitions.filter(item => item.type === 'FILE'); + let textParameters = response.data.parameterDefinitions.filter(item => item.type === 'STRING'); + let parameters = new Map(); + parameters.set('FILE', fileParameters); + parameters.set('STRING', textParameters); + vm.localWorkflowsParameters.set(workflow, parameters); + }) + .catch(function (error) { + $log.error(error); + }); + }; + vm.loadRemoteWorkFlowsParameters = function () { vm.remoteWorkflowsParameters = new Map(); vm.remoteWorkflows.forEach(function(workflow) { @@ -692,6 +711,19 @@ return []; }; + vm.getInternalWorkFlowParameters = function (workflow, type) { + if (workflow && vm.localWorkflowsParameters.has(workflow) && vm.localWorkflowsParameters.get(workflow).has(type)) { + return vm.localWorkflowsParameters.get(workflow).get(type) + } + return []; + }; + + vm.getInternalWorkFlowParameter = function (workflow, type, parameterName) { + if (workflow && vm.localWorkflowsParameters.has(workflow) && vm.localWorkflowsParameters.get(workflow).has(type)) { + return vm.localWorkflowsParameters.get(workflow).get(type).filter(parameter => parameter.name === parameterName)[0] + } + }; + //Must be $scope because we bind to the onchange of the html (cannot attached to vm variable). $scope.selectFileForVNFName = function (fileInput) { if (fileInput && fileInput.id) { diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js index c271b7505..5f3669152 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.controller.test.js @@ -80,11 +80,13 @@ describe('Testing workFlows from SO', () => { test('Verify load workflows will call load from SO and join workflow lists', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}}); let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 1"}, {"id": "2", "name": "workflow 2"}]}); let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": []}}); $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}]; $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; // when @@ -98,6 +100,7 @@ describe('Testing workFlows from SO', () => { test('Verify load workflows will call load workflows parameters from SO', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data": {}}); let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{"id": "1", "name": "workflow 0"}]}); let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{"parameterDefinitions": [ {"id": 1, "name": "parameter 1", "required": true, "type": "STRING", "pattern": "[0-9]*"}, @@ -106,6 +109,7 @@ describe('Testing workFlows from SO', () => { $controller.changeManagement.vnfNames = [{name: 'test1'}, {name: "test2"}]; $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; // when @@ -118,6 +122,56 @@ describe('Testing workFlows from SO', () => { }); }); + test('Verify load workflows will call load workflows parameters from local service', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + // when + + let result = new Map(); + const scaleOutResult = new Map(); + scaleOutResult.set("FILE", []); + scaleOutResult.set("STRING", [ + { + "acceptableFileType": null, + "id": 1, + "msgOnContentError": null, + "msgOnPatternError": null, + "name": "Configuration Parameters", + "pattern": ".*", + "required": true, + "type": "STRING", + } + ]); + result.set("VNF Scale Out", scaleOutResult); + + return $controller.loadWorkFlows() + .then(() => { + expect($controller.localWorkflowsParameters).toEqual(result); + }); + }); + test('Verify broken SO workflows wont change content of local workflows', () => { // given let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["workflow 0"]}}); @@ -132,5 +186,114 @@ describe('Testing workFlows from SO', () => { expect($controller.workflows).toEqual(['workflow 0']); }); }); -}); + test('Verify get internal workflow parameters should return an empty list if not such workflow exist', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + // when + return $controller.loadWorkFlows() + .then(() => { + let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("NON-EXISTENT WF", "STRING"); + expect(internalWorkFlowParameters).toEqual([]); + }); + }); + + test('Verify get internal workflow parameters should return an empty list if not such type exist', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + // when + return $controller.loadWorkFlows() + .then(() => { + let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "FILE"); + expect(internalWorkFlowParameters).toEqual([]); + }); + }); + + test('Verify get internal workflow parameters should return a list if such workflow and type exist', () => { + // given + let getWorkflowsStub = Promise.resolve({"data": {"workflows": ["VNF Scale Out"]}}); + let getLocalWorkflowsParametersStub = Promise.resolve({"data":{ + "parameterDefinitions": [ + { + "id": 1, + "name": "Configuration Parameters", + "required": true, + "type": "STRING", + "pattern": ".*", + "msgOnPatternError": null, + "msgOnContentError": null, + "acceptableFileType": null + } + ], + }}); + let getSOWorkflowsPromiseStub = Promise.resolve({"data": [{}]}); + let getSOWorkflowsParametersPromiseStub = Promise.resolve({"data":{}}); + + $controller.changeManagement.vnfNames = [{name: 'test1'}]; + $changeManagementService.getWorkflows = () => getWorkflowsStub; + $changeManagementService.getLocalWorkflowParameter = () => getLocalWorkflowsParametersStub; + $changeManagementService.getSOWorkflows = () => getSOWorkflowsPromiseStub; + $changeManagementService.getSOWorkflowParameter = () => getSOWorkflowsParametersPromiseStub; + + let result = [{ + "acceptableFileType": null, + "id": 1, + "msgOnContentError": null, + "msgOnPatternError": null, + "name": "Configuration Parameters", + "pattern": ".*", + "required": true, + "type": "STRING", + }]; + // when + return $controller.loadWorkFlows() + .then(() => { + let internalWorkFlowParameters = $controller.getInternalWorkFlowParameters("VNF Scale Out", "STRING"); + expect(internalWorkFlowParameters).toEqual(result); + }); + }); +}); diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html index 2cf879001..9fb978c42 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html +++ b/vid-app-common/src/main/webapp/app/vid/scripts/modals/new-change-management/new-change-management.html @@ -78,38 +78,26 @@ -
- - -
-
- + +
+
- - - + + +
- - + +
-
-
- - -
-
- - -
-
- - -
+ +
+ +
+
- +
diff --git a/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js b/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js index 5820ae212..45aedd1a1 100644 --- a/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js +++ b/vid-app-common/src/main/webapp/app/vid/scripts/services/change-management.service.js @@ -36,7 +36,7 @@ .success(function (response) { return {data: response}; }) - .catch(function (err) { + .catch(function () { return {data: []}; }); }; @@ -57,6 +57,13 @@ }); }; + this.getLocalWorkflowParameter = function (workflowName){ + return $http.get(COMPONENT.GET_LOCAL_WORKFLOW_PARAMETER.replace('@workflowName', encodeURIComponent(workflowName))) + .success(function (response) { + return {data: response.parameterDefinitions} + }); + }; + this.getMSOChangeManagements = function() { var deferred = $q.defer(); diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java deleted file mode 100644 index d8d8552ec..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/services/ExtWorkflowServiceImplTest.java +++ /dev/null @@ -1,118 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.services; - - - -import com.google.common.collect.Lists; -import io.joshworks.restclient.http.HttpResponse; -import java.util.Collections; -import java.util.List; - -import org.assertj.core.api.Assertions; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.onap.vid.model.SOWorkflow; -import org.onap.vid.model.SOWorkflowParameterDefinition; -import org.onap.vid.model.SOWorkflowParameterDefinitions; -import org.onap.vid.model.SOWorkflowType; -import org.onap.vid.model.SOWorkflows; -import org.onap.vid.mso.MsoResponseWrapper2; -import org.onap.vid.mso.rest.MockedWorkflowsRestClient; -import org.onap.vid.services.ExtWorkflowsServiceImpl.BadResponseFromMso; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - - - -public class ExtWorkflowServiceImplTest { - - @Mock - private MockedWorkflowsRestClient client; - @Mock - private HttpResponse response; - - @Mock - private HttpResponse parameterDefinitionsHttpResponse; - - - @BeforeMethod - public void init(){ - MockitoAnnotations.initMocks(this); - } - - @Test - public void shouldReturnWorkflowsOnValidResponse(){ - // given - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); - Mockito.when(response.getStatus()).thenReturn(200); - Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); - MsoResponseWrapper2 msoResponseStub = new MsoResponseWrapper2<>(response); - Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub); - // when - List workflows = extWorkflowsService.getWorkflows("test"); - // then - Mockito.verify(client).getWorkflows("test"); - Assertions.assertThat(workflows.get(0).getName()).isEqualTo("xyz"); - } - - @Test(expectedExceptions = BadResponseFromMso.class) - public void shouldThrowBadResponseOnInvalidResponse(){ - // given - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); - Mockito.when(response.getStatus()).thenReturn(500); - Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); - MsoResponseWrapper2 msoResponseStub = new MsoResponseWrapper2<>(response); - Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub); - // when - extWorkflowsService.getWorkflows("test"); - // then throw exception - } - @Test - public void shouldReturnWorkflowParametersOnValidResponse() { - SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true))); - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); - Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); - Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters); - MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); - Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); - - - SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); - - Assertions.assertThat(workflowParameterDefinitions).isEqualTo(parameters); - } - - @Test - public void shouldProperlyHandleEmptyParametersList(){ - ExtWorkflowsService extWorkflowsService = new ExtWorkflowsServiceImpl(client); - Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); - Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList())); - - MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); - Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); - - - SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); - Assertions.assertThat(workflowParameterDefinitions.getParameterDefinitions()).isEmpty(); - } -} diff --git a/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java new file mode 100644 index 000000000..160ba97a5 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/services/ExternalWorkflowServiceImplTest.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.services; + + + +import com.google.common.collect.Lists; +import io.joshworks.restclient.http.HttpResponse; +import java.util.Collections; +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vid.model.SOWorkflow; +import org.onap.vid.model.SOWorkflowParameterDefinition; +import org.onap.vid.model.SOWorkflowParameterDefinitions; +import org.onap.vid.model.SOWorkflowType; +import org.onap.vid.model.SOWorkflows; +import org.onap.vid.mso.MsoResponseWrapper2; +import org.onap.vid.mso.rest.MockedWorkflowsRestClient; +import org.onap.vid.services.ExternalWorkflowsServiceImpl.BadResponseFromMso; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class ExternalWorkflowServiceImplTest { + + @Mock + private MockedWorkflowsRestClient client; + @Mock + private HttpResponse response; + + @Mock + private HttpResponse parameterDefinitionsHttpResponse; + + + @BeforeMethod + public void init(){ + MockitoAnnotations.initMocks(this); + } + + @Test + public void shouldReturnWorkflowsOnValidResponse(){ + // given + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); + Mockito.when(response.getStatus()).thenReturn(200); + Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); + MsoResponseWrapper2 msoResponseStub = new MsoResponseWrapper2<>(response); + Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub); + // when + List workflows = extWorkflowsService.getWorkflows("test"); + // then + Mockito.verify(client).getWorkflows("test"); + Assertions.assertThat(workflows.get(0).getName()).isEqualTo("xyz"); + } + + @Test(expectedExceptions = BadResponseFromMso.class) + public void shouldThrowBadResponseOnInvalidResponse(){ + // given + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); + Mockito.when(response.getStatus()).thenReturn(500); + Mockito.when(response.getBody()).thenReturn(new SOWorkflows(Collections.singletonList(new SOWorkflow(1L, "xyz")))); + MsoResponseWrapper2 msoResponseStub = new MsoResponseWrapper2<>(response); + Mockito.when(client.getWorkflows("test")).thenReturn(msoResponseStub); + // when + extWorkflowsService.getWorkflows("test"); + // then throw exception + } + @Test + public void shouldReturnWorkflowParametersOnValidResponse() { + SOWorkflowParameterDefinitions parameters = new SOWorkflowParameterDefinitions(Collections.singletonList(new SOWorkflowParameterDefinition(1L, "sample", "[0-9]", SOWorkflowType.STRING, true))); + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); + Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); + Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(parameters); + MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); + Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); + + + SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); + + Assertions.assertThat(workflowParameterDefinitions).isEqualTo(parameters); + } + + @Test + public void shouldProperlyHandleEmptyParametersList(){ + ExternalWorkflowsService extWorkflowsService = new ExternalWorkflowsServiceImpl(client); + Mockito.when(parameterDefinitionsHttpResponse.getStatus()).thenReturn(200); + Mockito.when(parameterDefinitionsHttpResponse.getBody()).thenReturn(new SOWorkflowParameterDefinitions(Lists.newArrayList())); + + MsoResponseWrapper2 msoResponseWrapper = new MsoResponseWrapper2<>(parameterDefinitionsHttpResponse); + Mockito.when(client.getWorkflowParameterDefinitions(1L)).thenReturn(msoResponseWrapper); + + + SOWorkflowParameterDefinitions workflowParameterDefinitions = extWorkflowsService.getWorkflowParameterDefinitions(1L); + Assertions.assertThat(workflowParameterDefinitions.getParameterDefinitions()).isEmpty(); + } +} -- cgit 1.2.3-korg