diff options
Diffstat (limited to 'bpmn/mso-infrastructure-bpmn')
17 files changed, 280 insertions, 260 deletions
diff --git a/bpmn/mso-infrastructure-bpmn/pom.xml b/bpmn/mso-infrastructure-bpmn/pom.xml index 25913eabba..c3c26ef5e7 100644 --- a/bpmn/mso-infrastructure-bpmn/pom.xml +++ b/bpmn/mso-infrastructure-bpmn/pom.xml @@ -93,10 +93,19 @@ <artifactId>maven-jar-plugin</artifactId> <executions> <execution> - <id>tests</id> + <id>tests-jar</id> + <goals> + <goal>test-jar</goal> + </goals> + <configuration> + <skip>false</skip> + </configuration> </execution> <execution> <id>original</id> + <configuration> + <skip>false</skip> + </configuration> </execution> </executions> </plugin> @@ -295,5 +304,16 @@ <version>1.7.0</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onap.aaf.authz</groupId> + <artifactId>aaf-cadi-aaf</artifactId> + <version>2.1.9</version> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> </project> diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java index 5f70ab5924..3a1e126fef 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImpl.java @@ -82,7 +82,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple String correlationValue = messageId; callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "queryVnfNotification") @@ -117,7 +117,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setOutputs(outputs); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "createVnfNotification") @@ -150,7 +150,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setRollback(rollback); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "updateVnfNotification") @@ -181,7 +181,7 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setRollback(rollback); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } @WebMethod(operationName = "deleteVnfNotification") @@ -208,6 +208,6 @@ public class VnfAdapterNotifyServiceImpl extends ProcessEngineAwareService imple message.setErrorMessage(errorMessage); callback.handleCallback(method, message, messageEventName, messageVariable, correlationVariable, - correlationValue, logMarker); + correlationValue, logMarker, null); } } diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java index ace6e1937d..4fb63651eb 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResource.java @@ -102,7 +102,11 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, getRequestId(inputVariables)); processor.startProcess(processKey, variableMap); WorkflowResponse response = waitForResponse(inputVariables); - return Response.status(202).entity(response).build(); + if (response.getMessageCode() == 500) { + return Response.status(500).entity(response).build(); + } else { + return Response.status(202).entity(response).build(); + } } catch (WorkflowProcessorException e) { WorkflowResponse response = e.getWorkflowResponse(); return Response.status(500).entity(response).build(); @@ -112,7 +116,7 @@ public class WorkflowAsyncResource extends ProcessEngineAwareService { } } - private WorkflowResponse waitForResponse(Map<String, Object> inputVariables) throws Exception { + protected WorkflowResponse waitForResponse(Map<String, Object> inputVariables) throws Exception { String requestId = getRequestId(inputVariables); long currentWaitTime = 0; long waitTime = getWaitTime(inputVariables); diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowProcessor.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowProcessor.java index d33e7aed0c..70365b744c 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowProcessor.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowProcessor.java @@ -85,12 +85,14 @@ public class WorkflowProcessor extends ProcessEngineAwareService { Map<String, Object> inputVariables = new HashMap<>(); @SuppressWarnings("unchecked") Map<String, Object> vMap = (Map<String, Object>) variableMap.get("variables"); - for (Map.Entry<String, Object> entry : vMap.entrySet()) { - String vName = entry.getKey(); - Object value = entry.getValue(); - @SuppressWarnings("unchecked") - Map<String, Object> valueMap = (Map<String, Object>) value; // value, type - inputVariables.put(vName, valueMap.get("value")); + if (vMap != null) { + for (Map.Entry<String, Object> entry : vMap.entrySet()) { + String vName = entry.getKey(); + Object value = entry.getValue(); + @SuppressWarnings("unchecked") + Map<String, Object> valueMap = (Map<String, Object>) value; // value, type + inputVariables.put(vName, valueMap.get("value")); + } } return inputVariables; } diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java index bcc3739c32..6debcfbff6 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/common/workflow/service/WorkflowResource.java @@ -333,8 +333,6 @@ public class WorkflowResource extends ProcessEngineAwareService { public void run() { setLogContext(processKey, inputVariables); - long startTime = System.currentTimeMillis(); - try { RuntimeService runtimeService = getProcessEngineServices().getRuntimeService(); @@ -557,7 +555,6 @@ public class WorkflowResource extends ProcessEngineAwareService { // TODO filter only set of variables WorkflowResponse response = new WorkflowResponse(); - long startTime = System.currentTimeMillis(); try { ProcessEngineServices engine = getProcessEngineServices(); List<HistoricVariableInstance> variables = engine.getHistoryService().createHistoricVariableInstanceQuery() diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java new file mode 100644 index 0000000000..94f4b313d4 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/AsyncTaskExecutorListener.java @@ -0,0 +1,42 @@ +package org.onap.so.bpmn.core.plugins; + +import org.camunda.bpm.engine.RepositoryService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.ExecutionListener; +import org.onap.so.bpmn.common.listener.validation.WorkflowActionListenerRunner; +import org.onap.so.spring.SpringContextHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AsyncTaskExecutorListener implements ExecutionListener { + private final Logger logger = LoggerFactory.getLogger(AsyncTaskExecutorListener.class); + + + private WorkflowActionListenerRunner listenerRunner; + + @Override + public void notify(DelegateExecution execution) throws Exception { + if (!isBlank(execution.getCurrentActivityName())) { + try { + String id = execution.getId(); + if (id != null) { + RepositoryService repositoryService = execution.getProcessEngineServices().getRepositoryService(); + String processName = repositoryService.createProcessDefinitionQuery() + .processDefinitionId(execution.getProcessDefinitionId()).singleResult().getName(); + logger.info("ProcessName : {}", processName); + if (processName != null) { + listenerRunner = + SpringContextHelper.getAppContext().getBean(WorkflowActionListenerRunner.class); + listenerRunner.executeAsyncListeners(processName, execution, ExecutionListener.EVENTNAME_END); + } + } + } catch (Exception e) { + logger.error("Error occured in executing Complete Task Listeners", e); + } + } + } + + private boolean isBlank(Object object) { + return object == null || "".equals(object.toString().trim()); + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java index 251464a34d..6de22825b7 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/core/plugins/LoggingAndURNMappingPlugin.java @@ -37,8 +37,10 @@ import org.camunda.bpm.engine.impl.pvm.process.ScopeImpl; import org.camunda.bpm.engine.impl.pvm.process.TransitionImpl; import org.camunda.bpm.engine.impl.util.xml.Element; import org.camunda.bpm.engine.impl.variable.VariableDeclaration; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.slf4j.MDC; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -50,6 +52,9 @@ import org.springframework.stereotype.Component; @Component public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin { + public static final String SERVICE_INSTANCE_ID = "ServiceInstanceId"; + public static final String SERVICE_NAME = "ServiceName"; + @Autowired private LoggingParseListener loggingParseListener; @@ -294,6 +299,13 @@ public class LoggingAndURNMappingPlugin extends AbstractProcessEnginePlugin { String requestId = (String) execution.getVariable("mso-request-id"); String svcid = (String) execution.getVariable("mso-service-instance-id"); + try { + MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId); + MDC.put(SERVICE_INSTANCE_ID, svcid); + MDC.put(SERVICE_NAME, processName); + } catch (Exception e) { + logger.error("Error trying to add variables to MDC", e); + } } } catch (Exception e) { logger.error("Exception occurred", e); diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CXFConfiguration.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CXFConfiguration.java index a049f81906..03feda6d0f 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CXFConfiguration.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/CXFConfiguration.java @@ -38,9 +38,7 @@ import org.onap.so.bpmn.common.workflow.service.WorkflowMessageResource; import org.onap.so.bpmn.common.workflow.service.WorkflowResource; import org.onap.so.logging.cxf.interceptor.SOAPLoggingInInterceptor; import org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor; -import org.onap.so.logging.jaxrs.filter.JaxRsFilterLogging; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; @@ -65,7 +63,7 @@ public class CXFConfiguration { private WorkflowAsyncResource workflowAsyncResource; @Autowired - private JaxRsFilterLogging jaxRsFilterLogging; + private SOAuditLogContainerFilter soAuditLogContainerFilter; @Autowired private ObjectMapper mapper; @@ -108,7 +106,7 @@ public class CXFConfiguration { endpoint.setServiceBeans(Arrays.<Object>asList(wmr, workflowResource, workflowAsyncResource)); endpoint.setAddress("/"); endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature())); - endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper), jaxRsFilterLogging)); + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper), soAuditLogContainerFilter)); return endpoint.create(); } diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java index 093fba089d..29fc4e93fc 100644 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java +++ b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/MSOInfrastructureApplication.java @@ -33,7 +33,7 @@ import org.camunda.bpm.engine.repository.DeploymentBuilder; import org.onap.so.bpmn.common.DefaultToShortClassNameBeanNameGenerator; import org.onap.so.db.catalog.beans.Workflow; import org.onap.so.db.catalog.client.CatalogDbClient; -import org.onap.so.logging.jaxrs.filter.MDCTaskDecorator; +import org.onap.logging.filter.spring.MDCTaskDecorator;; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -99,7 +99,7 @@ public class MSOInfrastructureApplication { DeploymentBuilder deploymentBuilder = processEngine.getRepositoryService().createDeployment(); deployCustomWorkflows(deploymentBuilder); } catch (Exception e) { - logger.warn("Unable to invoke deploymentBuilder: " + e.getMessage()); + logger.warn("Unable to invoke deploymentBuilder ", e); } } @@ -136,11 +136,11 @@ public class MSOInfrastructureApplication { deploymentBuilder.addString(workflowName, workflowBody); } deploymentBuilder.enableDuplicateFiltering(true); - deploymentBuilder.deploy(); } + deploymentBuilder.deploy(); } } catch (Exception e) { - logger.warn("Unable to deploy custom workflows, " + e.getMessage()); + logger.warn("Unable to deploy custom workflows ", e); } } } diff --git a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java b/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java deleted file mode 100644 index 1ed3214214..0000000000 --- a/bpmn/mso-infrastructure-bpmn/src/main/java/org/onap/so/bpmn/infrastructure/WebSecurityConfigImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * 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.infrastructure; - -import org.onap.so.security.MSOSpringFirewall; -import org.onap.so.security.WebSecurityConfig; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.builders.WebSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; - -@EnableWebSecurity -public class WebSecurityConfigImpl extends WebSecurityConfig { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() - .antMatchers("/async/services/**", "/workflow/services/*", "/SDNCAdapterCallbackService", - "/WorkflowMessage", "/vnfAdapterNotify", "/vnfAdapterRestNotify") - .hasAnyRole(StringUtils.collectionToDelimitedString(getRoles(), ",")).and().httpBasic(); - } - - @Override - public void configure(WebSecurity web) throws Exception { - super.configure(web); - StrictHttpFirewall firewall = new MSOSpringFirewall(); - web.httpFirewall(firewall); - } - -} diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/application-aaf.yaml b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-aaf.yaml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-aaf.yaml diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/application-basic.yaml b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-basic.yaml new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/application-basic.yaml diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java index a94713e9e0..7a50e5f9d3 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/BPMNUtil.java @@ -155,24 +155,11 @@ public class BPMNUtil { } } - private static String getProcessInstanceId(HistoryService historyService, String processDefinitionID) { - List<HistoricProcessInstance> historyList = historyService.createHistoricProcessInstanceQuery().list(); - String pID = null; - for (HistoricProcessInstance hInstance : historyList) { - if (hInstance.getProcessDefinitionKey().equals(processDefinitionID)) { - pID = hInstance.getId(); - break; - } - } - return pID; - } - public static boolean isProcessInstanceFinished(ProcessEngineServices processEngineServices, String pid) { return processEngineServices.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(pid) .finished().count() == 1 ? true : false; } - private static void buildVariable(String key, String value, Map<String, Object> variableValueType) { Map<String, Object> host = new HashMap<>(); host.put("value", value); diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java index e71404a2ff..93f98a34a6 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/WorkflowTest.java @@ -1384,172 +1384,6 @@ public abstract class WorkflowTest { } /** - * Runs a program to inject sniro workflow messages into the test environment. A program is essentially just a list - * of keys that identify event data to be injected, in sequence. For more details, see injectSNIROCallbacks(String - * contentType, String messageType, String content, long timeout) - * - * Errors are handled with junit assertions and will cause the test to fail. NOTE: Each callback must have a - * workflow message type associated with it. - * - * @param callbacks an object containing event data for the program - * @param program the program to execute - */ - protected void injectSNIROCallbacks(CallbackSet callbacks, String program) { - - String[] cmds = program.replaceAll("\\s+", "").split(","); - - for (String cmd : cmds) { - String action = cmd; - String modifier = "STD"; - - if (cmd.contains(":")) { - String[] parts = cmd.split(":"); - action = parts[0]; - modifier = parts[1]; - } - - String messageType = null; - String content = null; - String contentType = null; - - if ("STD".equals(modifier)) { - CallbackData callbackData = callbacks.get(action); - - if (callbackData == null) { - String msg = "No '" + action + "' workflow message callback is defined"; - logger.debug(msg); - fail(msg); - } - - messageType = callbackData.getMessageType(); - - if (messageType == null || messageType.trim().equals("")) { - String msg = "No workflow message type is defined in the '" + action + "' callback"; - logger.debug(msg); - fail(msg); - } - - content = callbackData.getContent(); - contentType = callbackData.getContentType(); - } else { - String msg = "Invalid workflow message program modifier: '" + modifier + "'"; - logger.debug(msg); - fail(msg); - } - - if (!injectSNIROCallbacks(contentType, messageType, content, 10000)) { - fail("Failed to inject '" + action + "' workflow message"); - } - - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - fail("Interrupted after injection of '" + action + "' workflow message"); - } - } - } - - /** - * Injects a sniro workflow message. The specified callback response may contain the placeholder strings - * ((CORRELATOR)) and ((SERVICE_RESOURCE_ID)) The ((CORRELATOR)) is replaced with the actual correlator value from - * the request. The ((SERVICE_RESOURCE_ID)) is replaced with the actual serviceResourceId value from the sniro - * request. Currently this only works with sniro request that contain only 1 resource. - * - * @param contentType the HTTP contentType for the message (possibly null) - * @param messageType the message type - * @param content the message content (possibly null) - * @param timeout the timeout in milliseconds - * @return true if the message could be injected, false otherwise - */ - protected boolean injectSNIROCallbacks(String contentType, String messageType, String content, long timeout) { - String correlator = (String) getProcessVariable("ReceiveWorkflowMessage", messageType + "_CORRELATOR", timeout); - - if (correlator == null) { - return false; - } - if (content != null) { - content = content.replace("((CORRELATOR))", correlator); - if (messageType.equalsIgnoreCase("SNIROResponse")) { - ServiceDecomposition decomp = - (ServiceDecomposition) getProcessVariable("Homing", "serviceDecomposition", timeout); - List<Resource> resourceList = decomp.getServiceResources(); - if (resourceList.size() == 1) { - String resourceId = ""; - for (Resource resource : resourceList) { - resourceId = resource.getResourceId(); - } - String homingList = getJsonValue(content, "solutionInfo.placementInfo"); - JSONArray placementArr = null; - try { - placementArr = new JSONArray(homingList); - } catch (Exception e) { - return false; - } - if (placementArr.length() == 1) { - content = content.replace("((SERVICE_RESOURCE_ID))", resourceId); - } - String licenseInfoList = getJsonValue(content, "solutionInfo.licenseInfo"); - JSONArray licenseArr = null; - try { - licenseArr = new JSONArray(licenseInfoList); - } catch (Exception e) { - return false; - } - if (licenseArr.length() == 1) { - content = content.replace("((SERVICE_RESOURCE_ID))", resourceId); - } - } else { - try { - String homingList = getJsonValue(content, "solutionInfo.placementInfo"); - String licenseInfoList = getJsonValue(content, "solutionInfo.licenseInfo"); - JSONArray placementArr = new JSONArray(homingList); - JSONArray licenseArr = new JSONArray(licenseInfoList); - for (Resource resource : resourceList) { - String resourceModuleName = resource.getModelInfo().getModelInstanceName(); - String resourceId = resource.getResourceId(); - - for (int i = 0; i < placementArr.length(); i++) { - JSONObject placementObj = placementArr.getJSONObject(i); - String placementModuleName = placementObj.getString("resourceModuleName"); - if (placementModuleName.equalsIgnoreCase(resourceModuleName)) { - String placementString = placementObj.toString(); - placementString = placementString.replace("((SERVICE_RESOURCE_ID))", resourceId); - JSONObject newPlacementObj = new JSONObject(placementString); - placementArr.put(i, newPlacementObj); - } - } - - for (int i = 0; i < licenseArr.length(); i++) { - JSONObject licenseObj = licenseArr.getJSONObject(i); - String licenseModuleName = licenseObj.getString("resourceModuleName"); - if (licenseModuleName.equalsIgnoreCase(resourceModuleName)) { - String licenseString = licenseObj.toString(); - licenseString = licenseString.replace("((SERVICE_RESOURCE_ID))", resourceId); - JSONObject newLicenseObj = new JSONObject(licenseString); - licenseArr.put(i, newLicenseObj); - } - } - } - String newPlacementInfos = placementArr.toString(); - String newLicenseInfos = licenseArr.toString(); - content = updJsonValue(content, "solutionInfo.placementInfo", newPlacementInfos); - content = updJsonValue(content, "solutionInfo.licenseInfo", newLicenseInfos); - } catch (Exception e) { - return false; - } - - } - } - } - logger.debug("Injecting " + messageType + " message"); - - Response response = workflowMessageResource.deliver(contentType, messageType, correlator, content); - logger.debug("Workflow response to {} message: {}", messageType, response); - return true; - } - - - /** * Wait for the process to end. * * @param businessKey the process business key diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImplTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImplTest.java new file mode 100644 index 0000000000..d15d71a9e9 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/VnfAdapterNotifyServiceImplTest.java @@ -0,0 +1,118 @@ +package org.onap.so.bpmn.common.workflow.service; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.adapter.vnf.CreateVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.DeleteVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.MsoExceptionCategory; +import org.onap.so.bpmn.common.adapter.vnf.QueryVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.RollbackVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.UpdateVnfNotification; +import org.onap.so.bpmn.common.adapter.vnf.VnfRollback; +import org.onap.so.bpmn.common.adapter.vnf.VnfStatus; +import org.onap.so.bpmn.common.workflow.service.CallbackHandlerService.CallbackResult; + +@RunWith(MockitoJUnitRunner.class) +public class VnfAdapterNotifyServiceImplTest { + + + @InjectMocks + @Spy + private VnfAdapterNotifyServiceImpl vnfAdapterNotifyServiceImpl; + + @Mock + private CallbackHandlerService callbackHandlerService; + + @Mock + private CallbackResult callbackResult; + + protected CreateVnfNotification.Outputs outputs = new CreateVnfNotification.Outputs(); + protected QueryVnfNotification.Outputs queryOutputs = new QueryVnfNotification.Outputs(); + protected UpdateVnfNotification.Outputs updateOutputs = new UpdateVnfNotification.Outputs(); + + protected VnfRollback vnfRollback = new VnfRollback(); + + @Test + public void rollbackVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("rollbackVnfNotification"), + any(RollbackVnfNotification.class), eq("rollbackVnfNotificationCallback"), + eq("rollbackVnfNotificationCallback"), eq("VNFRB_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + + vnfAdapterNotifyServiceImpl.rollbackVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, + "Error creating stack"); + + verify(callbackHandlerService, times(1)).handleCallback(eq("rollbackVnfNotification"), + any(RollbackVnfNotification.class), eq("rollbackVnfNotificationCallback"), + eq("rollbackVnfNotificationCallback"), eq("VNFRB_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + } + + @Test + public void queryVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("queryVnfNotification"), + any(QueryVnfNotification.class), eq("queryVnfNotificationCallback"), eq("queryVnfNotificationCallback"), + eq("VNFQ_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + + vnfAdapterNotifyServiceImpl.queryVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, "", + Boolean.TRUE, "vnfid", VnfStatus.ACTIVE, queryOutputs); + + verify(callbackHandlerService, times(1)).handleCallback(eq("queryVnfNotification"), + any(QueryVnfNotification.class), eq("queryVnfNotificationCallback"), eq("queryVnfNotificationCallback"), + eq("VNFQ_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + } + + @Test + public void createVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("createVnfNotification"), + any(CreateVnfNotification.class), eq("createVnfNotificationCallback"), + eq("createVnfNotificationCallback"), eq("VNFC_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + + vnfAdapterNotifyServiceImpl.createVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, "", + "vnfId", outputs, vnfRollback); + + verify(callbackHandlerService, times(1)).handleCallback(eq("createVnfNotification"), + any(CreateVnfNotification.class), eq("createVnfNotificationCallback"), + eq("createVnfNotificationCallback"), eq("VNFC_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + } + + @Test + public void updateVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("updateVnfNotification"), + any(UpdateVnfNotification.class), eq("updateVnfNotificationCallback"), + eq("updateVnfNotificationCallback"), eq("VNFU_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + + vnfAdapterNotifyServiceImpl.updateVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, "", + updateOutputs, vnfRollback); + + verify(callbackHandlerService, times(1)).handleCallback(eq("updateVnfNotification"), + any(UpdateVnfNotification.class), eq("updateVnfNotificationCallback"), + eq("updateVnfNotificationCallback"), eq("VNFU_messageId"), eq("messageId"), eq("[VNF-NOTIFY]"), + eq(null)); + } + + @Test + public void deleteVnfNotificationTest() { + doReturn(callbackResult).when(callbackHandlerService).handleCallback(eq("deleteVnfNotification"), + any(DeleteVnfNotification.class), eq("deleteVnfACallback"), eq("deleteVnfACallback"), eq("VNFDEL_uuid"), + eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + + vnfAdapterNotifyServiceImpl.deleteVnfNotification("messageId", true, MsoExceptionCategory.OPENSTACK, ""); + + verify(callbackHandlerService, times(1)).handleCallback(eq("deleteVnfNotification"), + any(DeleteVnfNotification.class), eq("deleteVnfACallback"), eq("deleteVnfACallback"), eq("VNFDEL_uuid"), + eq("messageId"), eq("[VNF-NOTIFY]"), eq(null)); + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java new file mode 100644 index 0000000000..df9a23019a --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/common/workflow/service/WorkflowAsyncResourceTest.java @@ -0,0 +1,59 @@ +package org.onap.so.bpmn.common.workflow.service; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import static org.mockito.ArgumentMatchers.anyMap; +import java.util.HashMap; +import java.util.Map; +import javax.ws.rs.core.Response; +import org.camunda.bpm.engine.variable.impl.VariableMapImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.common.workflow.context.WorkflowResponse; + +@RunWith(MockitoJUnitRunner.class) +public class WorkflowAsyncResourceTest { + + @InjectMocks + @Spy + private WorkflowAsyncResource workflowAsyncResource; + + @Mock + private WorkflowProcessor processor; + + private WorkflowResponse workflowResponse; + private VariableMapImpl varMap; + + @Before + public void before() { + workflowResponse = new WorkflowResponse(); + varMap = new VariableMapImpl(); + Map<String, Object> variables = new HashMap<String, Object>(); + Map<String, Object> requestIdMap = new HashMap<String, Object>(); + requestIdMap.put("value", "123"); + requestIdMap.put("type", "String"); + variables.put("mso-request-id", requestIdMap); + varMap.put("variables", variables); + } + + @Test + public void startProcessInstanceByKey200Test() throws Exception { + workflowResponse.setMessageCode(200); + doReturn(workflowResponse).when(workflowAsyncResource).waitForResponse(anyMap()); + Response response = workflowAsyncResource.startProcessInstanceByKey("123", varMap); + assertEquals(202, response.getStatus()); + } + + @Test + public void startProcessInstanceByKey500Test() throws Exception { + workflowResponse.setMessageCode(500); + doReturn(workflowResponse).when(workflowAsyncResource).waitForResponse(anyMap()); + Response response = workflowAsyncResource.startProcessInstanceByKey("123", varMap); + assertEquals(500, response.getStatus()); + } +} diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java index dd993bca51..43fbc59b3d 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/DmaapClientTestImpl.java @@ -20,9 +20,8 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; -import java.util.HashMap; +import java.util.Map; import java.util.Objects; -import java.util.Optional; import org.onap.so.bpmn.infrastructure.pnf.dmaap.DmaapClient; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @@ -35,8 +34,7 @@ public class DmaapClientTestImpl implements DmaapClient { private Runnable informConsumer; @Override - public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer, - Optional<HashMap<String, String>> updateInfo) { + public void registerForUpdate(String pnfCorrelationId, Runnable informConsumer) { this.pnfCorrelationId = pnfCorrelationId; this.informConsumer = informConsumer; } |