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.ProcessEngineServices;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.camunda.bpm.engine.runtime.Incident;
33 import org.camunda.bpm.engine.variable.VariableMap;
34 import org.camunda.bpm.engine.variable.value.TypedValue;
35 import org.camunda.bpm.model.bpmn.BpmnModelInstance;
36 import org.camunda.bpm.model.bpmn.instance.FlowElement;
37 import org.junit.Test;
38 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder.RequestAction;
39 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder.SvcAction;
40 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
41 import org.onap.so.requestsdb.RequestsDbConstant;
43 public class AbstractBuilderTest {
45 AbstractBuilder<?, ?> abstractBuilder = new AbstractBuilder<Object, Object>() {
47 Object build(DelegateExecution execution, Object input) throws Exception {
52 DelegateExecution delegateExecution = new DelegateExecution() {
53 private String operType;
54 private String resourceType;
55 private String requestId;
58 public String getProcessInstanceId() {
63 public String getProcessBusinessKey() {
68 public String getProcessDefinitionId() {
73 public String getParentId() {
78 public String getCurrentActivityId() {
83 public String getCurrentActivityName() {
88 public String getActivityInstanceId() {
93 public String getParentActivityInstanceId() {
98 public String getCurrentTransitionId() {
103 public DelegateExecution getProcessInstance() {
108 public DelegateExecution getSuperExecution() {
113 public boolean isCanceled() {
118 public String getTenantId() {
123 public void setVariable(String s, Object o, String s1) {
128 public Incident createIncident(String s, String s1) {
133 public Incident createIncident(String s, String s1, String s2) {
138 public void resolveIncident(String s) {
143 public String getId() {
148 public String getEventName() {
153 public String getBusinessKey() {
158 public BpmnModelInstance getBpmnModelInstance() {
163 public FlowElement getBpmnModelElementInstance() {
168 public ProcessEngineServices getProcessEngineServices() {
173 public String getVariableScopeKey() {
178 public Map<String, Object> getVariables() {
183 public VariableMap getVariablesTyped() {
188 public VariableMap getVariablesTyped(boolean b) {
193 public Map<String, Object> getVariablesLocal() {
198 public VariableMap getVariablesLocalTyped() {
203 public VariableMap getVariablesLocalTyped(boolean b) {
208 public Object getVariable(String s) {
209 if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
211 } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
213 } else if ("msoRequestId".equals(s)) {
220 public Object getVariableLocal(String s) {
225 public <T extends TypedValue> T getVariableTyped(String s) {
230 public <T extends TypedValue> T getVariableTyped(String s, boolean b) {
235 public <T extends TypedValue> T getVariableLocalTyped(String s) {
240 public <T extends TypedValue> T getVariableLocalTyped(String s, boolean b) {
245 public Set<String> getVariableNames() {
250 public Set<String> getVariableNamesLocal() {
255 public void setVariable(String s, Object o) {
256 if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
257 operType = (String) o;
258 } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
259 resourceType = (String) o;
260 } else if ("msoRequestId".equals(s)) {
261 requestId = (String) o;
266 public void setVariableLocal(String s, Object o) {
271 public void setVariables(Map<String, ?> map) {
276 public void setVariablesLocal(Map<String, ?> map) {
281 public boolean hasVariables() {
286 public boolean hasVariablesLocal() {
291 public boolean hasVariable(String s) {
296 public boolean hasVariableLocal(String s) {
301 public void removeVariable(String s) {
306 public void removeVariableLocal(String s) {
311 public void removeVariables(Collection<String> collection) {
316 public void removeVariablesLocal(Collection<String> collection) {
321 public void removeVariables() {
326 public void removeVariablesLocal() {
332 public void requestActionGetIntValueTest() {
333 assertEquals(0, RequestAction.CREATE_NETWORK_INSTANCE.getIntValue());
337 public void svcActionGetIntValueTest() {
338 assertEquals(0, SvcAction.RESERVE.getIntValue());
342 public void buildTest() throws Exception {
343 abstractBuilder.build(null, null);
347 public void getRequestActionBlankOperationTypeTest() throws Exception {
348 assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
352 public void getRequestActionDeleteOperationTypeBlankResourceTypeTest() throws Exception {
353 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
354 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
355 assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
359 public void getRequestActionDeleteOperationTypeBadResourceTypeTest() throws Exception {
360 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
361 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
362 assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
366 public void getRequestActionDeleteOperationTypeOverlayResourceTypeTest() throws Exception {
367 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
368 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
369 assertEquals(AbstractBuilder.RequestAction.DEACTIVATE_DCI_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
373 public void getRequestActionDeleteOperationTypeUnderlayResourceTypeTest() throws Exception {
374 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
375 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
376 assertEquals(AbstractBuilder.RequestAction.DELETE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
380 public void getRequestActionDeleteOperationTypeTest() throws Exception {
381 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
382 assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
386 public void getRequestActionCreateOperationTypeBlankResourceTypeTest() throws Exception {
387 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
388 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
389 assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
393 public void getRequestActionCreateOperationTypeBadResourceTypeTest() throws Exception {
394 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
395 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
396 assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
400 public void getRequestActionCreateOperationTypeOverlayResourceTypeTest() throws Exception {
401 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
402 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
403 assertEquals(AbstractBuilder.RequestAction.ACTIVATE_DCI_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
407 public void getRequestActionCreateOperationTypeUnderlayResourceTypeTest() throws Exception {
408 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
409 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
410 assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
414 public void getRequestActionCreateOperationTypeTest() throws Exception {
415 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
416 assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
420 public void getRequestActionBadOperationType() {
421 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
422 assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
426 public void getSvcActionBlankOperationTypeTest() throws Exception {
427 assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
431 public void getSvcActionDeleteOperationTypeBlankResourceTypeTest() throws Exception {
432 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
433 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
434 assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
438 public void getSvcActionDeleteOperationTypeBadResourceTypeTest() throws Exception {
439 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
440 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
441 assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
445 public void getSvcActionDeleteOperationTypeOverlayResourceTypeTest() throws Exception {
446 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
447 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
448 assertEquals(AbstractBuilder.SvcAction.DEACTIVATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
452 public void getSvcActionDeleteOperationTypeUnderlayResourceTypeTest() throws Exception {
453 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
454 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
455 assertEquals(AbstractBuilder.SvcAction.DELETE.getName(), abstractBuilder.getSvcAction(delegateExecution));
459 public void getSvcActionDeleteOperationTypeTest() throws Exception {
460 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
461 assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
465 public void getSvcActionCreateOperationTypeBlankResourceTypeTest() throws Exception {
466 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
467 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
468 assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
472 public void getSvcActionCreateOperationTypeBadResourceTypeTest() throws Exception {
473 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
474 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
475 assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
479 public void getSvcActionCreateOperationTypeOverlayResourceTypeTest() throws Exception {
480 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
481 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
482 assertEquals(AbstractBuilder.SvcAction.ACTIVATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
486 public void getSvcActionCreateOperationTypeUnderlayResourceTypeTest() throws Exception {
487 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
488 delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
489 assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
493 public void getSvcActionCreateOperationTypeTest() throws Exception {
494 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
495 assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
499 public void getSvcActionBadOperationType() {
500 delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
501 assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
505 public void getRequestIdBlankNotOnExecutionTest() {
506 abstractBuilder.getRequestId(delegateExecution);
510 public void getRequestIdBlankOnExecutionTest() {
511 String expected = "requestId";
512 delegateExecution.setVariable("msoRequestId", expected);
513 assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
517 public void getRequestIdTest() {
518 String expected = "requestId";
519 abstractBuilder.requestId = expected;
520 assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
524 public void getOnapServiceModelInformationEntityTest() throws Exception {
525 abstractBuilder.getOnapServiceModelInformationEntity(delegateExecution);
529 public void getOnapNetworkModelInformationEntityTest() throws Exception {
530 abstractBuilder.getOnapNetworkModelInformationEntity(delegateExecution);
534 public void getParamEntitiesTest() throws Exception {
535 Map<String, String> inputs = new HashMap<>();
536 inputs.put("foo", "bar");
537 List<ParamEntity> list = abstractBuilder.getParamEntities(inputs);
538 assertEquals(1, list.size());
539 assertEquals("foo", list.get(0).getName());
540 assertEquals("bar", list.get(0).getValue());
544 public void getParamEntitiesNullInputsTest() {
545 List<ParamEntity> list = abstractBuilder.getParamEntities(null);
546 assertEquals(0, list.size());
550 public void getParamEntitiesEmptyInputsTest() {
551 List<ParamEntity> list = abstractBuilder.getParamEntities(new HashMap<>());
552 assertEquals(0, list.size());
556 public void getRequestInformationEntityTest() throws Exception {
557 abstractBuilder.getRequestInformationEntity(delegateExecution);
561 public void getServiceInformationEntityTest() throws Exception {
562 abstractBuilder.getServiceInformationEntity(delegateExecution);
566 public void getServiceInstanceNameTest() throws Exception {
567 abstractBuilder.getServiceInstanceName(delegateExecution);