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;
 
  23 import java.util.Collection;
 
  24 import java.util.HashMap;
 
  25 import java.util.List;
 
  28 import org.camunda.bpm.engine.ProcessEngine;
 
  29 import org.camunda.bpm.engine.ProcessEngineServices;
 
  30 import org.camunda.bpm.engine.delegate.DelegateExecution;
 
  31 import org.camunda.bpm.engine.runtime.Incident;
 
  32 import org.camunda.bpm.engine.variable.VariableMap;
 
  33 import org.camunda.bpm.engine.variable.value.TypedValue;
 
  34 import org.camunda.bpm.model.bpmn.BpmnModelInstance;
 
  35 import org.camunda.bpm.model.bpmn.instance.FlowElement;
 
  36 import org.junit.Test;
 
  37 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder.RequestAction;
 
  38 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder.AbstractBuilder.SvcAction;
 
  39 import org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
 
  40 import org.onap.so.requestsdb.RequestsDbConstant;
 
  42 public class AbstractBuilderTest {
 
  44     AbstractBuilder<?, ?> abstractBuilder = new AbstractBuilder<Object, Object>() {
 
  46         Object build(DelegateExecution execution, Object input) throws Exception {
 
  51     DelegateExecution delegateExecution = new DelegateExecution() {
 
  52         private String operType;
 
  53         private String resourceType;
 
  54         private String requestId;
 
  57         public String getProcessInstanceId() {
 
  62         public String getProcessBusinessKey() {
 
  67         public String getProcessDefinitionId() {
 
  72         public String getParentId() {
 
  77         public String getCurrentActivityId() {
 
  82         public String getCurrentActivityName() {
 
  87         public String getActivityInstanceId() {
 
  92         public String getParentActivityInstanceId() {
 
  97         public String getCurrentTransitionId() {
 
 102         public DelegateExecution getProcessInstance() {
 
 107         public DelegateExecution getSuperExecution() {
 
 112         public boolean isCanceled() {
 
 117         public String getTenantId() {
 
 122         public void setVariable(String s, Object o, String s1) {
 
 127         public Incident createIncident(String s, String s1) {
 
 132         public Incident createIncident(String s, String s1, String s2) {
 
 137         public void resolveIncident(String s) {
 
 142         public String getId() {
 
 147         public String getEventName() {
 
 152         public String getBusinessKey() {
 
 157         public BpmnModelInstance getBpmnModelInstance() {
 
 162         public FlowElement getBpmnModelElementInstance() {
 
 167         public ProcessEngineServices getProcessEngineServices() {
 
 172         public String getVariableScopeKey() {
 
 177         public Map<String, Object> getVariables() {
 
 182         public VariableMap getVariablesTyped() {
 
 187         public VariableMap getVariablesTyped(boolean b) {
 
 192         public Map<String, Object> getVariablesLocal() {
 
 197         public VariableMap getVariablesLocalTyped() {
 
 202         public VariableMap getVariablesLocalTyped(boolean b) {
 
 207         public Object getVariable(String s) {
 
 208             if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
 
 210             } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
 
 212             } else if ("msoRequestId".equals(s)) {
 
 219         public Object getVariableLocal(String s) {
 
 224         public <T extends TypedValue> T getVariableTyped(String s) {
 
 229         public <T extends TypedValue> T getVariableTyped(String s, boolean b) {
 
 234         public <T extends TypedValue> T getVariableLocalTyped(String s) {
 
 239         public <T extends TypedValue> T getVariableLocalTyped(String s, boolean b) {
 
 244         public Set<String> getVariableNames() {
 
 249         public Set<String> getVariableNamesLocal() {
 
 254         public void setVariable(String s, Object o) {
 
 255             if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
 
 256                 operType = (String) o;
 
 257             } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
 
 258                 resourceType = (String) o;
 
 259             } else if ("msoRequestId".equals(s)) {
 
 260                 requestId = (String) o;
 
 265         public void setVariableLocal(String s, Object o) {
 
 270         public void setVariables(Map<String, ?> map) {
 
 275         public void setVariablesLocal(Map<String, ?> map) {
 
 280         public boolean hasVariables() {
 
 285         public boolean hasVariablesLocal() {
 
 290         public boolean hasVariable(String s) {
 
 295         public boolean hasVariableLocal(String s) {
 
 300         public void removeVariable(String s) {
 
 305         public void removeVariableLocal(String s) {
 
 310         public void removeVariables(Collection<String> collection) {
 
 315         public void removeVariablesLocal(Collection<String> collection) {
 
 320         public void removeVariables() {
 
 325         public void removeVariablesLocal() {
 
 330         public ProcessEngine getProcessEngine() {
 
 331             // TODO Auto-generated method stub
 
 336         public void setProcessBusinessKey(String arg0) {
 
 337             // TODO Auto-generated method stub
 
 343     public void requestActionGetIntValueTest() {
 
 344         assertEquals(0, RequestAction.CREATE_NETWORK_INSTANCE.getIntValue());
 
 348     public void svcActionGetIntValueTest() {
 
 349         assertEquals(0, SvcAction.RESERVE.getIntValue());
 
 353     public void buildTest() throws Exception {
 
 354         abstractBuilder.build(null, null);
 
 358     public void getRequestActionBlankOperationTypeTest() {
 
 359         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(),
 
 360                 abstractBuilder.getRequestAction(delegateExecution));
 
 364     public void getRequestActionDeleteOperationTypeBlankResourceTypeTest() {
 
 365         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 366         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
 
 367         assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(),
 
 368                 abstractBuilder.getRequestAction(delegateExecution));
 
 372     public void getRequestActionDeleteOperationTypeBadResourceTypeTest() {
 
 373         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 374         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
 
 375         assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(),
 
 376                 abstractBuilder.getRequestAction(delegateExecution));
 
 380     public void getRequestActionDeleteOperationTypeOverlayResourceTypeTest() {
 
 381         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 382         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
 
 383         assertEquals(AbstractBuilder.RequestAction.DEACTIVATE_DCI_NETWORK_INSTANCE.getName(),
 
 384                 abstractBuilder.getRequestAction(delegateExecution));
 
 388     public void getRequestActionDeleteOperationTypeUnderlayResourceTypeTest() {
 
 389         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 390         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
 
 391         assertEquals(AbstractBuilder.RequestAction.DELETE_NETWORK_INSTANCE.getName(),
 
 392                 abstractBuilder.getRequestAction(delegateExecution));
 
 396     public void getRequestActionDeleteOperationTypeTest() {
 
 397         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 398         assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(),
 
 399                 abstractBuilder.getRequestAction(delegateExecution));
 
 403     public void getRequestActionCreateOperationTypeBlankResourceTypeTest() {
 
 404         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 405         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
 
 406         assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(),
 
 407                 abstractBuilder.getRequestAction(delegateExecution));
 
 411     public void getRequestActionCreateOperationTypeBadResourceTypeTest() {
 
 412         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 413         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
 
 414         assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(),
 
 415                 abstractBuilder.getRequestAction(delegateExecution));
 
 419     public void getRequestActionCreateOperationTypeOverlayResourceTypeTest() {
 
 420         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 421         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
 
 422         assertEquals(AbstractBuilder.RequestAction.ACTIVATE_DCI_NETWORK_INSTANCE.getName(),
 
 423                 abstractBuilder.getRequestAction(delegateExecution));
 
 427     public void getRequestActionCreateOperationTypeUnderlayResourceTypeTest() {
 
 428         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 429         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
 
 430         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(),
 
 431                 abstractBuilder.getRequestAction(delegateExecution));
 
 435     public void getRequestActionCreateOperationTypeTest() {
 
 436         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 437         assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(),
 
 438                 abstractBuilder.getRequestAction(delegateExecution));
 
 442     public void getRequestActionBadOperationType() {
 
 443         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
 
 444         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(),
 
 445                 abstractBuilder.getRequestAction(delegateExecution));
 
 449     public void getSvcActionBlankOperationTypeTest() {
 
 450         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 454     public void getSvcActionDeleteOperationTypeBlankResourceTypeTest() {
 
 455         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 456         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
 
 457         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 461     public void getSvcActionDeleteOperationTypeBadResourceTypeTest() {
 
 462         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 463         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
 
 464         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 468     public void getSvcActionDeleteOperationTypeOverlayResourceTypeTest() {
 
 469         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 470         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
 
 471         assertEquals(AbstractBuilder.SvcAction.DEACTIVATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 475     public void getSvcActionDeleteOperationTypeUnderlayResourceTypeTest() {
 
 476         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 477         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
 
 478         assertEquals(AbstractBuilder.SvcAction.DELETE.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 482     public void getSvcActionDeleteOperationTypeTest() {
 
 483         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
 
 484         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 488     public void getSvcActionCreateOperationTypeBlankResourceTypeTest() {
 
 489         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 490         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
 
 491         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 495     public void getSvcActionCreateOperationTypeBadResourceTypeTest() {
 
 496         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 497         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "bad");
 
 498         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 502     public void getSvcActionCreateOperationTypeOverlayResourceTypeTest() {
 
 503         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 504         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "overlay");
 
 505         assertEquals(AbstractBuilder.SvcAction.ACTIVATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 509     public void getSvcActionCreateOperationTypeUnderlayResourceTypeTest() {
 
 510         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 511         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "underlay");
 
 512         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 516     public void getSvcActionCreateOperationTypeTest() {
 
 517         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
 
 518         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 522     public void getSvcActionBadOperationType() {
 
 523         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
 
 524         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
 
 528     public void getRequestIdBlankNotOnExecutionTest() {
 
 529         abstractBuilder.getRequestId(delegateExecution);
 
 533     public void getRequestIdBlankOnExecutionTest() {
 
 534         String expected = "requestId";
 
 535         delegateExecution.setVariable("msoRequestId", expected);
 
 536         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
 
 540     public void getRequestIdTest() {
 
 541         String expected = "requestId";
 
 542         abstractBuilder.requestId = expected;
 
 543         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
 
 547     public void getOnapServiceModelInformationEntityTest() {
 
 548         abstractBuilder.getOnapServiceModelInformationEntity(delegateExecution);
 
 552     public void getOnapNetworkModelInformationEntityTest() {
 
 553         abstractBuilder.getOnapNetworkModelInformationEntity(delegateExecution);
 
 557     public void getParamEntitiesTest() {
 
 558         Map<String, String> inputs = new HashMap<>();
 
 559         inputs.put("foo", "bar");
 
 560         List<ParamEntity> list = abstractBuilder.getParamEntities(inputs);
 
 561         assertEquals(1, list.size());
 
 562         assertEquals("foo", list.get(0).getName());
 
 563         assertEquals("bar", list.get(0).getValue());
 
 567     public void getParamEntitiesNullInputsTest() {
 
 568         List<ParamEntity> list = abstractBuilder.getParamEntities(null);
 
 569         assertEquals(0, list.size());
 
 573     public void getParamEntitiesEmptyInputsTest() {
 
 574         List<ParamEntity> list = abstractBuilder.getParamEntities(new HashMap<>());
 
 575         assertEquals(0, list.size());
 
 579     public void getRequestInformationEntityTest() {
 
 580         abstractBuilder.getRequestInformationEntity(delegateExecution);
 
 584     public void getServiceInformationEntityTest() {
 
 585         abstractBuilder.getServiceInformationEntity(delegateExecution);
 
 589     public void getServiceInstanceNameTest() {
 
 590         abstractBuilder.getServiceInstanceName(delegateExecution);