2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder;
22 import static org.junit.Assert.assertEquals;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
30 import org.camunda.bpm.engine.ProcessEngine;
31 import org.camunda.bpm.engine.ProcessEngineServices;
32 import org.camunda.bpm.engine.delegate.DelegateExecution;
33 import org.camunda.bpm.engine.runtime.Incident;
34 import org.camunda.bpm.engine.variable.VariableMap;
35 import org.camunda.bpm.engine.variable.value.TypedValue;
36 import org.camunda.bpm.model.bpmn.BpmnModelInstance;
37 import org.camunda.bpm.model.bpmn.instance.FlowElement;
38 import org.junit.Test;
39 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder.RequestAction;
40 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder.SvcAction;
41 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
42 import org.onap.so.requestsdb.RequestsDbConstant;
44 public class AbstractBuilderTest {
46 AbstractBuilder<?, ?> abstractBuilder = new AbstractBuilder<Object, Object>() {
48 Object build(DelegateExecution execution, Object input) throws Exception {
53 DelegateExecution delegateExecution = new DelegateExecution() {
54 private String operType;
55 private String resourceType;
56 private String requestId;
59 public String getProcessInstanceId() {
64 public String getProcessBusinessKey() {
69 public String getProcessDefinitionId() {
74 public String getParentId() {
79 public String getCurrentActivityId() {
84 public String getCurrentActivityName() {
89 public String getActivityInstanceId() {
94 public String getParentActivityInstanceId() {
99 public String getCurrentTransitionId() {
104 public DelegateExecution getProcessInstance() {
109 public DelegateExecution getSuperExecution() {
114 public boolean isCanceled() {
119 public String getTenantId() {
124 public void setVariable(String s, Object o, String s1) {
129 public Incident createIncident(String s, String s1) {
134 public Incident createIncident(String s, String s1, String s2) {
139 public void resolveIncident(String s) {
144 public String getId() {
149 public String getEventName() {
154 public String getBusinessKey() {
159 public BpmnModelInstance getBpmnModelInstance() {
164 public FlowElement getBpmnModelElementInstance() {
169 public ProcessEngineServices getProcessEngineServices() {
174 public String getVariableScopeKey() {
179 public Map<String, Object> getVariables() {
184 public VariableMap getVariablesTyped() {
189 public VariableMap getVariablesTyped(boolean b) {
194 public Map<String, Object> getVariablesLocal() {
199 public VariableMap getVariablesLocalTyped() {
204 public VariableMap getVariablesLocalTyped(boolean b) {
209 public Object getVariable(String s) {
210 if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
212 } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
214 } else if ("msoRequestId".equals(s)) {
221 public Object getVariableLocal(String s) {
226 public <T extends TypedValue> T getVariableTyped(String s) {
231 public <T extends TypedValue> T getVariableTyped(String s, boolean b) {
236 public <T extends TypedValue> T getVariableLocalTyped(String s) {
241 public <T extends TypedValue> T getVariableLocalTyped(String s, boolean b) {
246 public Set<String> getVariableNames() {
251 public Set<String> getVariableNamesLocal() {
256 public void setVariable(String s, Object o) {
257 if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
258 operType = (String) o;
259 } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
260 resourceType = (String) o;
261 } else if ("msoRequestId".equals(s)) {
262 requestId = (String) o;
267 public void setVariableLocal(String s, Object o) {
272 public void setVariables(Map<String, ?> map) {
277 public void setVariablesLocal(Map<String, ?> map) {
282 public boolean hasVariables() {
287 public boolean hasVariablesLocal() {
292 public boolean hasVariable(String s) {
297 public boolean hasVariableLocal(String s) {
302 public void removeVariable(String s) {
307 public void removeVariableLocal(String s) {
312 public void removeVariables(Collection<String> collection) {
317 public void removeVariablesLocal(Collection<String> collection) {
322 public void removeVariables() {
327 public void removeVariablesLocal() {
332 public ProcessEngine getProcessEngine(){
333 // TODO Auto-generated method stub
338 public void setProcessBusinessKey(String arg0){
339 // TODO Auto-generated method stub
345 public void requestActionGetIntValueTest() {
346 assertEquals(0, RequestAction.CREATE_NETWORK_INSTANCE.getIntValue());
350 public void svcActionGetIntValueTest() {
351 assertEquals(0, SvcAction.RESERVE.getIntValue());
355 public void buildTest() throws Exception {
356 abstractBuilder.build(null, null);
360 public void getRequestActionBlankOperationTypeTest() throws Exception {
361 assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
365 public void getRequestActionDeleteOperationTypeBlankResourceTypeTest() throws Exception {
366 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
367 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
368 assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
372 public void getRequestActionDeleteOperationTypeBadResourceTypeTest() throws Exception {
373 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
374 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
375 assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
379 public void getRequestActionDeleteOperationTypeOverlayResourceTypeTest() throws Exception {
380 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
381 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
382 assertEquals(AbstractBuilder.RequestAction.DEACTIVATE_DCI_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
386 public void getRequestActionDeleteOperationTypeUnderlayResourceTypeTest() throws Exception {
387 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
388 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
389 assertEquals(AbstractBuilder.RequestAction.DELETE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
393 public void getRequestActionDeleteOperationTypeTest() throws Exception {
394 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
395 assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
399 public void getRequestActionCreateOperationTypeBlankResourceTypeTest() throws Exception {
400 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
401 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
402 assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
406 public void getRequestActionCreateOperationTypeBadResourceTypeTest() throws Exception {
407 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
408 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
409 assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
413 public void getRequestActionCreateOperationTypeOverlayResourceTypeTest() throws Exception {
414 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
415 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
416 assertEquals(AbstractBuilder.RequestAction.ACTIVATE_DCI_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
420 public void getRequestActionCreateOperationTypeUnderlayResourceTypeTest() throws Exception {
421 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
422 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
423 assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
427 public void getRequestActionCreateOperationTypeTest() throws Exception {
428 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
429 assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
433 public void getRequestActionBadOperationType() {
434 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
435 assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
439 public void getSvcActionBlankOperationTypeTest() throws Exception {
440 assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
444 public void getSvcActionDeleteOperationTypeBlankResourceTypeTest() throws Exception {
445 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
446 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
447 assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
451 public void getSvcActionDeleteOperationTypeBadResourceTypeTest() throws Exception {
452 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
453 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
454 assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
458 public void getSvcActionDeleteOperationTypeOverlayResourceTypeTest() throws Exception {
459 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
460 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
461 assertEquals(AbstractBuilder.SvcAction.DEACTIVATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
465 public void getSvcActionDeleteOperationTypeUnderlayResourceTypeTest() throws Exception {
466 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
467 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
468 assertEquals(AbstractBuilder.SvcAction.DELETE.getName(), abstractBuilder.getSvcAction(delegateExecution));
472 public void getSvcActionDeleteOperationTypeTest() throws Exception {
473 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
474 assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
478 public void getSvcActionCreateOperationTypeBlankResourceTypeTest() throws Exception {
479 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
480 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
481 assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
485 public void getSvcActionCreateOperationTypeBadResourceTypeTest() throws Exception {
486 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
487 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
488 assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
492 public void getSvcActionCreateOperationTypeOverlayResourceTypeTest() throws Exception {
493 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
494 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
495 assertEquals(AbstractBuilder.SvcAction.ACTIVATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
499 public void getSvcActionCreateOperationTypeUnderlayResourceTypeTest() throws Exception {
500 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
501 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
502 assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
506 public void getSvcActionCreateOperationTypeTest() throws Exception {
507 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
508 assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
512 public void getSvcActionBadOperationType() {
513 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
514 assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
518 public void getRequestIdBlankNotOnExecutionTest() {
519 abstractBuilder.getRequestId(delegateExecution);
523 public void getRequestIdBlankOnExecutionTest() {
524 String expected = "requestId";
525 delegateExecution.setVariable("msoRequestId", expected);
526 assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
530 public void getRequestIdTest() {
531 String expected = "requestId";
532 abstractBuilder.requestId = expected;
533 assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
537 public void getOnapServiceModelInformationEntityTest() throws Exception {
538 abstractBuilder.getOnapServiceModelInformationEntity(delegateExecution);
542 public void getOnapNetworkModelInformationEntityTest() throws Exception {
543 abstractBuilder.getOnapNetworkModelInformationEntity(delegateExecution);
547 public void getParamEntitiesTest() throws Exception {
548 Map<String, String> inputs = new HashMap<>();
549 inputs.put("foo", "bar");
550 List<ParamEntity> list = abstractBuilder.getParamEntities(inputs);
551 assertEquals(1, list.size());
552 assertEquals("foo", list.get(0).getName());
553 assertEquals("bar", list.get(0).getValue());
557 public void getParamEntitiesNullInputsTest() {
558 List<ParamEntity> list = abstractBuilder.getParamEntities(null);
559 assertEquals(0, list.size());
563 public void getParamEntitiesEmptyInputsTest() {
564 List<ParamEntity> list = abstractBuilder.getParamEntities(new HashMap<>());
565 assertEquals(0, list.size());
569 public void getRequestInformationEntityTest() throws Exception {
570 abstractBuilder.getRequestInformationEntity(delegateExecution);
574 public void getServiceInformationEntityTest() throws Exception {
575 abstractBuilder.getServiceInformationEntity(delegateExecution);
579 public void getServiceInstanceNameTest() throws Exception {
580 abstractBuilder.getServiceInstanceName(delegateExecution);