diff options
Diffstat (limited to 'bpmn/MSOCommonBPMN')
19 files changed, 461 insertions, 40 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy index c19851d223..865b9ee8a7 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/CompleteMsoProcess.groovy @@ -243,7 +243,7 @@ public class CompleteMsoProcess extends AbstractServiceTaskProcessor { msoLogger.trace('Entered ' + method) try { - def msoCompletionResponse = """ + String msoCompletionResponse = """ <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} FAILED</sdncadapterworkflow:out> </sdncadapterworkflow:MsoCompletionResponse> @@ -275,7 +275,7 @@ public class CompleteMsoProcess extends AbstractServiceTaskProcessor { // msoLogger.trace("Started CompleteMsoProcess PostProcessRequest Method "); try { - def msoCompletionResponse = """ + String msoCompletionResponse = """ <sdncadapterworkflow:MsoCompletionResponse xmlns:sdncadapterworkflow="http://ecomp.com/mso/workflow/schema/v1"> <sdncadapterworkflow:out>BPEL ${execution.getVariable("CMSO_mso-bpel-name")} completed</sdncadapterworkflow:out> </sdncadapterworkflow:MsoCompletionResponse> diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy index 9732693f38..480dcd5e8f 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/FalloutHandler.groovy @@ -355,7 +355,7 @@ public class FalloutHandler extends AbstractServiceTaskProcessor { Boolean success = (Boolean) execution.getVariable("FH_success") String out = success ? "Fallout Handler Succeeded" : "Fallout Handler Failed"; - def falloutHandlerResponse = """ + String falloutHandlerResponse = """ <workflow:FalloutHandlerResponse xmlns:workflow="http://org.onap/so/workflow/schema/v1"> <workflow:out>${MsoUtils.xmlEscape(out)}</workflow:out> </workflow:FalloutHandlerResponse> diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtils.groovy index 32d1ee74bf..bed857dda8 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtils.groovy @@ -144,7 +144,7 @@ class SDNCAdapterUtils { def prefix = execution.getVariable('prefix') def request = taskProcessor.getVariable(execution, prefix+'Request') - def requestInformation = """<request-information> + String requestInformation = """<request-information> <request-id>${MsoUtils.xmlEscape(execution.getVariable("mso-request-id"))}</request-id> <request-action>torepl</request-action> <source>${MsoUtils.xmlEscape(execution.getVariable(prefix+"source"))}</source> @@ -172,7 +172,7 @@ class SDNCAdapterUtils { //Build Service Information // Send serviceName from CANOPI to sdnc for service-type - def serviceInformation = """<service-information> + String serviceInformation = """<service-information> <service-type>${MsoUtils.xmlEscape(execution.getVariable(prefix+"serviceName"))}</service-type> <service-instance-id>${MsoUtils.xmlEscape(svcInstanceId)}</service-instance-id> <subscriber-name>${MsoUtils.xmlEscape(execution.getVariable(prefix+"subscriberName"))}</subscriber-name> diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnf.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnf.groovy index 5eb72bb2f2..9fd16340b6 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnf.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/UpdateAAIGenericVnf.groovy @@ -183,7 +183,7 @@ public class UpdateAAIGenericVnf extends AbstractServiceTaskProcessor { } // Construct payload - personaModelVersionEntry = updateGenericVnfNode(origRequest, genericVnfNode, 'model-version-id') + personaModelVersionEntry = updateGenericVnfNode(origRequest, 'model-version-id') } // Handle ipv4-oam-address @@ -191,7 +191,7 @@ public class UpdateAAIGenericVnf extends AbstractServiceTaskProcessor { String ipv4OamAddressEntry = "" if (ipv4OamAddress != null) { // Construct payload - ipv4OamAddressEntry = updateGenericVnfNode(origRequest, genericVnfNode, 'ipv4-oam-address') + ipv4OamAddressEntry = updateGenericVnfNode(origRequest, 'ipv4-oam-address') } // Handle management-v6-address @@ -199,7 +199,7 @@ public class UpdateAAIGenericVnf extends AbstractServiceTaskProcessor { String managementV6AddressEntry = "" if (managementV6Address != null) { // Construct payload - managementV6AddressEntry = updateGenericVnfNode(origRequest, genericVnfNode, 'management-v6-address') + managementV6AddressEntry = updateGenericVnfNode(origRequest, 'management-v6-address') } // Handle orchestration-status @@ -207,10 +207,10 @@ public class UpdateAAIGenericVnf extends AbstractServiceTaskProcessor { String orchestrationStatusEntry = "" if (orchestrationStatus != null) { // Construct payload - orchestrationStatusEntry = updateGenericVnfNode(origRequest, genericVnfNode, 'orchestration-status') + orchestrationStatusEntry = updateGenericVnfNode(origRequest, 'orchestration-status') } - def payload = """ + String payload = """ { ${personaModelVersionEntry} ${ipv4OamAddressEntry} ${managementV6AddressEntry} @@ -243,7 +243,7 @@ public class UpdateAAIGenericVnf extends AbstractServiceTaskProcessor { * @param genericVnf Current Generic VNF retrieved from AAI. * @param element Name of element to be inserted. */ - public String updateGenericVnfNode(String origRequest, Node genericVnfNode, String elementName) { + public String updateGenericVnfNode(String origRequest, String elementName) { if (!utils.nodeExists(origRequest, elementName)) { return "" diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VidUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VidUtils.groovy index 6e09837274..40b0368eaa 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VidUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/VidUtils.groovy @@ -116,7 +116,7 @@ class VidUtils { } def modelCustomizationId = requestMap.requestDetails?.modelInfo?.modelCustomizationUuid ?: '' - def xmlReq = """ + String xmlReq = """ <volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>${MsoUtils.xmlEscape(action)}</action> @@ -251,7 +251,7 @@ class VidUtils { //'sdncVersion' = current, '1610' (non-RPC SDNC) or '1702' (RPC SDNC) def sdncVersion = execution.getVariable("sdncVersion") - def xmlReq = """ + String xmlReq = """ <network-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <request-id>${MsoUtils.xmlEscape(requestId)}</request-id> @@ -393,7 +393,7 @@ class VidUtils { userParamsNode = buildUserParams(userParams) } - def xmlReq = """ + String xmlReq = """ <network-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <request-id>${MsoUtils.xmlEscape(requestId)}</request-id> @@ -512,7 +512,7 @@ class VidUtils { def personaModelVersion = requestMap.requestDetails?.modelInfo?.modelUuid ?: '' def modelCustomizationId = requestMap.requestDetails?.modelInfo?.modelCustomizationUuid ?: '' - def xmlReq = """ + String xmlReq = """ <vnf-request> <request-info> <request-id>${MsoUtils.xmlEscape(requestId)}</request-id> diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/PostWorkflowValidator.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/PostWorkflowValidator.java new file mode 100644 index 0000000000..46b3c571d5 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/PostWorkflowValidator.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +public interface PostWorkflowValidator extends WorkflowValidator { + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/PreWorkflowValidator.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/PreWorkflowValidator.java new file mode 100644 index 0000000000..4dad1eafc4 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/PreWorkflowValidator.java @@ -0,0 +1,25 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +public interface PreWorkflowValidator extends WorkflowValidator { + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/WorkflowValidator.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/WorkflowValidator.java new file mode 100644 index 0000000000..348f91321c --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/WorkflowValidator.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +import java.util.Set; + +import org.camunda.bpm.engine.delegate.DelegateExecution; + +public interface WorkflowValidator { + + + /** + * Name of the workflow action to be validated + * @return + */ + public Set<String> forWorkflowAction(); + + /** + * Determines whether or not the workflow should be executed + * + * @param execution + * @return + */ + public boolean validate(DelegateExecution execution); + +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/WorkflowValidatorRunner.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/WorkflowValidatorRunner.java new file mode 100644 index 0000000000..44fbc6d629 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/validation/WorkflowValidatorRunner.java @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.annotation.PostConstruct; +import javax.annotation.Priority; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.javatuples.Pair; +import org.onap.so.client.exception.ExceptionBuilder; +import org.reflections.Reflections; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Component; + + +/** + * Controls running all pre and post validation for workflows. + * + * To define a validation you must make it a spring bean and implement either {@link org.onap.so.bpmn.common.validation.PreWorkflowValidator} or + * {@link org.onap.so.bpmn.common.validation.PostWorkflowValidator} your validation will automatically be + * run by this class. + * + */ +@Component +public class WorkflowValidatorRunner { + + private static Logger logger = LoggerFactory.getLogger(WorkflowValidatorRunner.class); + @Autowired + private ApplicationContext context; + + @Autowired + private ExceptionBuilder exceptionBuilder; + + private List<PreWorkflowValidator> preWorkflowValidators; + private List<PostWorkflowValidator> postWorkflowValidators; + + + @PostConstruct + protected void init() { + + preWorkflowValidators = new ArrayList<>( + Optional.ofNullable(context.getBeansOfType(PreWorkflowValidator.class)).orElse(new HashMap<>()).values()); + postWorkflowValidators = new ArrayList<>( + Optional.ofNullable(context.getBeansOfType(PostWorkflowValidator.class)).orElse(new HashMap<>()).values()); + } + + public boolean preValidate(String workflow, DelegateExecution execution) { + return validate(preWorkflowValidators, workflow, execution); + } + + + public boolean postValidate(String workflow, DelegateExecution execution) { + return validate(postWorkflowValidators, workflow, execution); + } + + + protected boolean validate(List<? extends WorkflowValidator> validators, String workflow, DelegateExecution execution) { + List<Pair<String, Boolean>> results = runValidations(validators, workflow, execution); + + if (!results.isEmpty()) { + exceptionBuilder.buildAndThrowWorkflowException(execution, 7000, + "Failed Validations:\n" + results.stream().map(item -> item.getValue0()).collect(Collectors.joining("\n"))); + } + + return true; + + } + protected List<Pair<String, Boolean>> runValidations(List<? extends WorkflowValidator> validators, String workflow, DelegateExecution execution) { + + List<WorkflowValidator> filtered = filterValidators(validators, workflow); + + List<Pair<String,Boolean>> results = new ArrayList<>(); + filtered.forEach(item -> results.add(new Pair<>(item.getClass().getName(), item.validate(execution)))); + + return results.stream().filter(item -> item.getValue1().equals(false)).collect(Collectors.toList()); + } + + protected List<WorkflowValidator> filterValidators(List<? extends WorkflowValidator> validators, String workflow) { + return validators.stream() + .filter(item -> { + return item.forWorkflowAction().contains(workflow); + }) + .sorted(Comparator.comparing(item -> { + Priority p = Optional.ofNullable(item.getClass().getAnnotation(Priority.class)).orElse(new Priority() { + public int value() { + return 1000; + } + + @Override + public Class<? extends Annotation> annotationType() { + return Priority.class; + } + }); + return p.value(); + })).collect(Collectors.toList()); + } + + protected <T> List<T> buildalidatorList(Reflections reflections, Class<T> clazz) { + List<T> result = new ArrayList<>(); + try { + for (Class<? extends T> klass : reflections.getSubTypesOf(clazz)) { + result.add(klass.newInstance()); + } + } catch (InstantiationException | IllegalAccessException e) { + logger.error("failed to build validator list for " + clazz.getName(), e); + throw new RuntimeException(e); + } + + return result; + } + + protected List<PreWorkflowValidator> getPreWorkflowValidators() { + return this.preWorkflowValidators; + } + + protected List<PostWorkflowValidator> getPostWorkflowValidators() { + return this.postWorkflowValidators; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy index 1fa10a56c5..55f68f665e 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/CreateAAIVfModuleTest.groovy @@ -57,7 +57,7 @@ class CreateAAIVfModuleTest extends MsoGroovyTest{ private static final String VNF_PERSONAL_MODEL_VER = "14" private static final String VF_MODULE_NAME = "modTestName" private static final String VF_MODULE_MODEL_NAME = "modModelNameTest" - private static final String DEFAULT_AAI_VERSION = "9" + private static final String DEFAULT_AAI_VERSION = "14" private static final String DEFAULT_AAI_NAMESPACE = "defaultTestNamespace" @Spy diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy index 510dcf665c..a920b22c71 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/NetworkUtilsTest.groovy @@ -30,7 +30,7 @@ import org.junit.Test; class NetworkUtilsTest { - def volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> + String volumeRequestXml = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>CREATE_VF_MODULE_VOL</action> <source>VID</source> diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy index e351210586..3438c7957c 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterTest.groovy @@ -424,7 +424,7 @@ public class SDNCAdapterTest { </rest:payload> </sdncadaptersc:RequestData></aetgt:SDNCAdapterRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>""" -def sdncAdapterResponse = """<sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> +String sdncAdapterResponse = """<sdncadapterworkflow:SDNCAdapterWorkflowResponse xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> <sdncadapterworkflow:response-data> <tag0:CallbackHeader xmlns:tag0="http://org.onap/workflow/sdnc/adapter/schema/v1"> <tag0:RequestId>39542e39-ccc3-4d1a-8b79-04ce88526613</tag0:RequestId> @@ -439,7 +439,7 @@ def sdncAdapterResponse = """<sdncadapterworkflow:SDNCAdapterWorkflowResponse xm </sdncadapterworkflow:SDNCAdapterWorkflowResponse> """ -def workflowErrorResponse = """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1"> +String workflowErrorResponse = """<aetgt:WorkflowException xmlns:aetgt="http://org.onap/so/workflow/schema/v1"> <aetgt:ErrorMessage>Received error from SDN-C: Error processing request to SDNC. Not Found. https://localhost:8443/restconf/config/L3SDN-API:services/layer3-service-list/MVM%2FVLXP%2F000855%2F%2FShakeout. SDNC Returned-[error-type:application, error-tag:data-missing, diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy index ef71e9073b..51dd77d383 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/SDNCAdapterUtilsTest.groovy @@ -180,7 +180,7 @@ public class SDNCAdapterUtilsTest { def rc = respcode def rm = respmsg - def output = """ + String output = """ <output xmlns="org:onap:sdnc:northbound:generic-resource"> <svc-request-id>8b46e36e-b44f-4085-9404-427be1bc8a3</svc-request-id> <response-code>${MsoUtils.xmlEscape(rc)}</response-code> diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy index 52f59a3fad..14fb60c245 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/TrinityExceptionUtilTest.groovy @@ -41,7 +41,7 @@ import org.junit.Test class TrinityExceptionUtilTest { - def aotsFault ="""<n1:Fault xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="http://csi.cingular.com/CSI/Namespaces/OneTicketingSystem/InfrastructureCommon/Types/Public/SoapFault.xsd" xmlns:cer="http://csi.cingular.com/CSI/Namespaces/OneTicketingSystem/InfrastructureCommon/Types/Public/ErrorResponse.xsd" xsi:schemaLocation="http://csi.cingular.com/CSI/Namespaces/OneTicketingSystem/InfrastructureCommon/Types/Public/SoapFault.xsd SoapFault-CDM.xsd"> + String aotsFault ="""<n1:Fault xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:n1="http://csi.cingular.com/CSI/Namespaces/OneTicketingSystem/InfrastructureCommon/Types/Public/SoapFault.xsd" xmlns:cer="http://csi.cingular.com/CSI/Namespaces/OneTicketingSystem/InfrastructureCommon/Types/Public/ErrorResponse.xsd" xsi:schemaLocation="http://csi.cingular.com/CSI/Namespaces/OneTicketingSystem/InfrastructureCommon/Types/Public/SoapFault.xsd SoapFault-CDM.xsd"> <n1:faultcode>xml:space</n1:faultcode> <n1:faultstring>String</n1:faultstring> <n1:faultactor>http://test.com</n1:faultactor> @@ -113,7 +113,7 @@ class TrinityExceptionUtilTest { </requestError> </Fault> """ - def errorString = """<requestError> + String errorString = """<requestError> <serviceException> <messageId>SVC3002</messageId> <text>Error writing output performing %1 on %2 (msg=%3) (ec=%4)</text> diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy index 1ab049571a..b80cb87c16 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VidUtilsTest.groovy @@ -53,7 +53,7 @@ import org.junit.Test; class VidUtilsTest { - def vfModuleReqJson = """ + String vfModuleReqJson = """ { "requestDetails": { "modelInfo": { @@ -153,7 +153,7 @@ class VidUtilsTest { } } """ - def bpmnReq1 = """ + String bpmnReq1 = """ { "requestDetails": { "modelInfo": { @@ -220,7 +220,7 @@ class VidUtilsTest { } """ - def vidUtilResp1 = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> + String vidUtilResp1 = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>CREATE_VF_MODULE_VOL</action> <source>VID</source> @@ -256,7 +256,7 @@ class VidUtilsTest { </volume-request> """ - def bpmnReq2 = """ + String bpmnReq2 = """ { "requestDetails": { "modelInfo": { @@ -305,7 +305,7 @@ class VidUtilsTest { } """ - def bpmnReqJsonVolumeSuppressRollbackTrue = """ + String bpmnReqJsonVolumeSuppressRollbackTrue = """ { "requestDetails": { "modelInfo": { @@ -354,7 +354,7 @@ class VidUtilsTest { } """ -def bpmnReqJsonVolumeSuppressRollbackFalse = """ +String bpmnReqJsonVolumeSuppressRollbackFalse = """ { "requestDetails": { "modelInfo": { @@ -403,7 +403,7 @@ def bpmnReqJsonVolumeSuppressRollbackFalse = """ } """ -def bpmnReqJsonVolumeSuppressRollbackNone = """ +String bpmnReqJsonVolumeSuppressRollbackNone = """ { "requestDetails": { "modelInfo": { @@ -451,7 +451,7 @@ def bpmnReqJsonVolumeSuppressRollbackNone = """ } """ - def bpmnReqJsonVfModuleSuppressRollbackTrue = """ + String bpmnReqJsonVfModuleSuppressRollbackTrue = """ { "requestDetails": { "modelInfo": { @@ -518,7 +518,7 @@ def bpmnReqJsonVolumeSuppressRollbackNone = """ } """ -def bpmnReqJsonVfModuleSuppressRollbackFalse = """ +String bpmnReqJsonVfModuleSuppressRollbackFalse = """ { "requestDetails": { "modelInfo": { @@ -585,7 +585,7 @@ def bpmnReqJsonVfModuleSuppressRollbackFalse = """ } """ -def bpmnReqJsonVfModuleSuppressRollbackNone = """ +String bpmnReqJsonVfModuleSuppressRollbackNone = """ { "requestDetails": { "modelInfo": { @@ -650,7 +650,7 @@ def bpmnReqJsonVfModuleSuppressRollbackNone = """ } } """ - def vidUtilResp2 = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> + String vidUtilResp2 = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>CREATE_VF_MODULE_VOL</action> <source>VID</source> @@ -672,7 +672,7 @@ def bpmnReqJsonVfModuleSuppressRollbackNone = """ </volume-request> """ -def vidUtilVolumeRespBackoutOnFailureFalse = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> +String vidUtilVolumeRespBackoutOnFailureFalse = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>CREATE_VF_MODULE_VOL</action> <source>VID</source> @@ -694,7 +694,7 @@ def vidUtilVolumeRespBackoutOnFailureFalse = """<volume-request xmlns="http://ww </volume-request> """ -def vidUtilVolumeRespBackoutOnFailureTrue = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> +String vidUtilVolumeRespBackoutOnFailureTrue = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>CREATE_VF_MODULE_VOL</action> <source>VID</source> @@ -716,7 +716,7 @@ def vidUtilVolumeRespBackoutOnFailureTrue = """<volume-request xmlns="http://www </volume-request> """ -def vidUtilVolumeRespBackoutOnFailureEmpty = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> +String vidUtilVolumeRespBackoutOnFailureEmpty = """<volume-request xmlns="http://www.w3.org/2001/XMLSchema"> <request-info> <action>CREATE_VF_MODULE_VOL</action> <source>VID</source> @@ -738,7 +738,7 @@ def vidUtilVolumeRespBackoutOnFailureEmpty = """<volume-request xmlns="http://ww </volume-request> """ -def vidUtilVfModuleRespBackoutOnFailureFalse = """<vnf-request> +String vidUtilVfModuleRespBackoutOnFailureFalse = """<vnf-request> <request-info> <request-id>test-request-id-123</request-id> <action>CREATE_VF_MODULE</action> @@ -767,7 +767,7 @@ def vidUtilVfModuleRespBackoutOnFailureFalse = """<vnf-request> </vnf-request> """ -def vidUtilVfModuleRespBackoutOnFailureTrue = """<vnf-request> +String vidUtilVfModuleRespBackoutOnFailureTrue = """<vnf-request> <request-info> <request-id>test-request-id-123</request-id> <action>CREATE_VF_MODULE</action> @@ -796,7 +796,7 @@ def vidUtilVfModuleRespBackoutOnFailureTrue = """<vnf-request> </vnf-request> """ -def vidUtilVfModuleRespBackoutOnFailureEmpty = """<vnf-request> +String vidUtilVfModuleRespBackoutOnFailureEmpty = """<vnf-request> <request-info> <request-id>test-request-id-123</request-id> <action>CREATE_VF_MODULE</action> diff --git a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy index 72cde00877..afc180e8a4 100644 --- a/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy +++ b/bpmn/MSOCommonBPMN/src/test/groovy/org/onap/so/bpmn/common/scripts/VnfAdapterRestV1Test.groovy @@ -79,7 +79,7 @@ public class VnfAdapterRestV1Test { } - def rollbackReq = """ + String rollbackReq = """ <rollbackVolumeGroupRequest> <volumeGroupRollback> <volumeGroupId>8a07b246-155e-4b08-b56e-76e98a3c2d66</volumeGroupId> diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowPreValidatorOne.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowPreValidatorOne.java new file mode 100644 index 0000000000..9ad87b5aeb --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowPreValidatorOne.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +import java.util.Collections; +import java.util.Set; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.springframework.stereotype.Component; + +@Component +public class WorkflowPreValidatorOne implements PreWorkflowValidator { + + @Override + public Set<String> forWorkflowAction() { + + return Collections.singleton("test"); + } + + @Override + public boolean validate(DelegateExecution exeuction) { + return false; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowPreValidatorTwo.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowPreValidatorTwo.java new file mode 100644 index 0000000000..2157c673dc --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowPreValidatorTwo.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +import java.util.Collections; +import java.util.Set; + +import javax.annotation.Priority; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.springframework.stereotype.Component; + +@Priority(1) +@Component +public class WorkflowPreValidatorTwo implements PreWorkflowValidator { + + @Override + public Set<String> forWorkflowAction() { + return Collections.singleton("test"); + } + + @Override + public boolean validate(DelegateExecution execution) { + return false; + } + +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowValidatorRunnerTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowValidatorRunnerTest.java new file mode 100644 index 0000000000..313fe6b0c3 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/common/validation/WorkflowValidatorRunnerTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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.so.bpmn.common.validation; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; + +import java.util.Arrays; +import java.util.List; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.common.DelegateExecutionImpl; +import org.onap.so.bpmn.core.WorkflowException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {ValidationConfig.class}) +public class WorkflowValidatorRunnerTest { + + @Rule + public ExpectedException thrown= ExpectedException.none(); + + @Autowired + private WorkflowValidatorRunner runner; + + @Test + public void filterValidatorTest() { + + WorkflowPreValidatorOne one = new WorkflowPreValidatorOne(); + WorkflowPreValidatorTwo two = new WorkflowPreValidatorTwo(); + List<WorkflowValidator> validators = Arrays.asList(one, two); + + List<WorkflowValidator> result = runner.filterValidators(validators, "test"); + + List<WorkflowValidator> expected = Arrays.asList(two, one); + + assertEquals(expected, result); + } + + @Test + public void testValidate() { + + DelegateExecution execution = new DelegateExecutionFake(); + execution.setVariable("testProcessKey", "1234"); + try { + runner.preValidate("test", execution); + fail("exception not thrown"); + } catch (BpmnError e) { + WorkflowException workflowException = (WorkflowException) execution.getVariable("WorkflowException"); + assertEquals("Failed Validations:\norg.onap.so.bpmn.common.validation.WorkflowPreValidatorTwo\norg.onap.so.bpmn.common.validation.WorkflowPreValidatorOne", workflowException.getErrorMessage()); + } + runner.preValidate("test2", mock(DelegateExecution.class)); + } + + @Test + public void testEmptyList() { + boolean result = runner.preValidate("test3", mock(DelegateExecution.class)); + + assertTrue(result); + } +} |