updated camunda springboot version
[so.git] / bpmn / so-bpmn-infrastructure-common / src / test / java / org / onap / so / bpmn / infrastructure / workflow / serviceTask / client / builder / AbstractBuilderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 package org.onap.so.bpmn.infrastructure.workflow.serviceTask.client.builder;
21
22 import static org.junit.Assert.assertEquals;
23
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29
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;
43
44 public class AbstractBuilderTest {
45
46     AbstractBuilder<?, ?> abstractBuilder = new AbstractBuilder<Object, Object>() {
47         @Override
48         Object build(DelegateExecution execution, Object input) throws Exception {
49             return null;
50         }
51     };
52
53     DelegateExecution delegateExecution = new DelegateExecution() {
54         private String operType;
55                 private String resourceType;
56                 private String requestId;
57
58         @Override
59         public String getProcessInstanceId() {
60             return null;
61         }
62
63         @Override
64         public String getProcessBusinessKey() {
65             return null;
66         }
67
68         @Override
69         public String getProcessDefinitionId() {
70             return null;
71         }
72
73         @Override
74         public String getParentId() {
75             return null;
76         }
77
78         @Override
79         public String getCurrentActivityId() {
80             return null;
81         }
82
83         @Override
84         public String getCurrentActivityName() {
85             return null;
86         }
87
88         @Override
89         public String getActivityInstanceId() {
90             return null;
91         }
92
93         @Override
94         public String getParentActivityInstanceId() {
95             return null;
96         }
97
98         @Override
99         public String getCurrentTransitionId() {
100             return null;
101         }
102
103         @Override
104         public DelegateExecution getProcessInstance() {
105             return null;
106         }
107
108         @Override
109         public DelegateExecution getSuperExecution() {
110             return null;
111         }
112
113         @Override
114         public boolean isCanceled() {
115             return false;
116         }
117
118         @Override
119         public String getTenantId() {
120             return null;
121         }
122
123         @Override
124         public void setVariable(String s, Object o, String s1) {
125
126         }
127
128         @Override
129         public Incident createIncident(String s, String s1) {
130             return null;
131         }
132
133         @Override
134         public Incident createIncident(String s, String s1, String s2) {
135             return null;
136         }
137
138         @Override
139         public void resolveIncident(String s) {
140
141         }
142
143         @Override
144         public String getId() {
145             return null;
146         }
147
148         @Override
149         public String getEventName() {
150             return null;
151         }
152
153         @Override
154         public String getBusinessKey() {
155             return null;
156         }
157
158         @Override
159         public BpmnModelInstance getBpmnModelInstance() {
160             return null;
161         }
162
163         @Override
164         public FlowElement getBpmnModelElementInstance() {
165             return null;
166         }
167
168         @Override
169         public ProcessEngineServices getProcessEngineServices() {
170             return null;
171         }
172
173         @Override
174         public String getVariableScopeKey() {
175             return null;
176         }
177
178         @Override
179         public Map<String, Object> getVariables() {
180             return null;
181         }
182
183         @Override
184         public VariableMap getVariablesTyped() {
185             return null;
186         }
187
188         @Override
189         public VariableMap getVariablesTyped(boolean b) {
190             return null;
191         }
192
193         @Override
194         public Map<String, Object> getVariablesLocal() {
195             return null;
196         }
197
198         @Override
199         public VariableMap getVariablesLocalTyped() {
200             return null;
201         }
202
203         @Override
204         public VariableMap getVariablesLocalTyped(boolean b) {
205             return null;
206         }
207
208         @Override
209         public Object getVariable(String s) {
210                 if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
211                         return operType;
212                 } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
213                         return resourceType;
214                 } else if ("msoRequestId".equals(s)) {
215                         return requestId;
216                 }
217                 return null;
218         }
219
220         @Override
221         public Object getVariableLocal(String s) {
222             return null;
223         }
224
225         @Override
226         public <T extends TypedValue> T getVariableTyped(String s) {
227             return null;
228         }
229
230         @Override
231         public <T extends TypedValue> T getVariableTyped(String s, boolean b) {
232             return null;
233         }
234
235         @Override
236         public <T extends TypedValue> T getVariableLocalTyped(String s) {
237             return null;
238         }
239
240         @Override
241         public <T extends TypedValue> T getVariableLocalTyped(String s, boolean b) {
242             return null;
243         }
244
245         @Override
246         public Set<String> getVariableNames() {
247             return null;
248         }
249
250         @Override
251         public Set<String> getVariableNamesLocal() {
252             return null;
253         }
254
255         @Override
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;
263                 }
264         }
265
266         @Override
267         public void setVariableLocal(String s, Object o) {
268
269         }
270
271         @Override
272         public void setVariables(Map<String, ?> map) {
273
274         }
275
276         @Override
277         public void setVariablesLocal(Map<String, ?> map) {
278
279         }
280
281         @Override
282         public boolean hasVariables() {
283             return false;
284         }
285
286         @Override
287         public boolean hasVariablesLocal() {
288             return false;
289         }
290
291         @Override
292         public boolean hasVariable(String s) {
293             return false;
294         }
295
296         @Override
297         public boolean hasVariableLocal(String s) {
298             return false;
299         }
300
301         @Override
302         public void removeVariable(String s) {
303
304         }
305
306         @Override
307         public void removeVariableLocal(String s) {
308
309         }
310
311         @Override
312         public void removeVariables(Collection<String> collection) {
313
314         }
315
316         @Override
317         public void removeVariablesLocal(Collection<String> collection) {
318
319         }
320
321         @Override
322         public void removeVariables() {
323
324         }
325
326         @Override
327         public void removeVariablesLocal() {
328
329         }
330
331                 @Override
332                 public ProcessEngine getProcessEngine(){
333                         // TODO Auto-generated method stub
334                         return null;
335                 }
336
337                 @Override
338                 public void setProcessBusinessKey(String arg0){
339                         // TODO Auto-generated method stub
340
341                 }
342     };
343
344     @Test
345     public void requestActionGetIntValueTest() {
346         assertEquals(0, RequestAction.CREATE_NETWORK_INSTANCE.getIntValue());
347     }
348
349     @Test
350     public void svcActionGetIntValueTest() {
351         assertEquals(0, SvcAction.RESERVE.getIntValue());
352     }
353
354     @Test
355     public void buildTest() throws Exception {
356         abstractBuilder.build(null, null);
357     }
358
359     @Test
360     public void getRequestActionBlankOperationTypeTest() throws Exception {
361         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
362     }
363
364     @Test
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));
369     }
370
371     @Test
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));
376     }
377
378     @Test
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));
383     }
384
385     @Test
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));
390     }
391
392     @Test
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));
396     }
397
398     @Test
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));
403     }
404
405     @Test
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));
410     }
411
412     @Test
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));
417     }
418
419     @Test
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));
424     }
425
426     @Test
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));
430     }
431
432     @Test
433     public void getRequestActionBadOperationType() {
434         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
435         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
436     }
437
438     @Test
439     public void getSvcActionBlankOperationTypeTest() throws Exception {
440         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
441     }
442
443     @Test
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));
448     }
449
450     @Test
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));
455     }
456
457     @Test
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));
462     }
463
464     @Test
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));
469     }
470
471     @Test
472     public void getSvcActionDeleteOperationTypeTest() throws Exception {
473         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
474         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
475     }
476
477     @Test
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));
482     }
483
484     @Test
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));
489     }
490
491     @Test
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));
496     }
497
498     @Test
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));
503     }
504
505     @Test
506     public void getSvcActionCreateOperationTypeTest() throws Exception {
507         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
508         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
509     }
510
511     @Test
512     public void getSvcActionBadOperationType() {
513         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
514         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
515     }
516
517     @Test
518     public void getRequestIdBlankNotOnExecutionTest() {
519         abstractBuilder.getRequestId(delegateExecution);
520     }
521
522     @Test
523     public void getRequestIdBlankOnExecutionTest() {
524         String expected = "requestId";
525         delegateExecution.setVariable("msoRequestId", expected);
526         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
527     }
528
529     @Test
530     public void getRequestIdTest() {
531         String expected = "requestId";
532         abstractBuilder.requestId = expected;
533         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
534     }
535
536     @Test
537     public void getOnapServiceModelInformationEntityTest() throws Exception {
538         abstractBuilder.getOnapServiceModelInformationEntity(delegateExecution);
539     }
540
541     @Test
542     public void getOnapNetworkModelInformationEntityTest() throws Exception {
543         abstractBuilder.getOnapNetworkModelInformationEntity(delegateExecution);
544     }
545
546     @Test
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());
554     }
555
556     @Test
557     public void getParamEntitiesNullInputsTest() {
558         List<ParamEntity> list = abstractBuilder.getParamEntities(null);
559         assertEquals(0, list.size());
560     }
561
562     @Test
563     public void getParamEntitiesEmptyInputsTest() {
564         List<ParamEntity> list = abstractBuilder.getParamEntities(new HashMap<>());
565         assertEquals(0, list.size());
566     }
567
568     @Test
569     public void getRequestInformationEntityTest() throws Exception {
570         abstractBuilder.getRequestInformationEntity(delegateExecution);
571     }
572
573     @Test
574     public void getServiceInformationEntityTest() throws Exception {
575         abstractBuilder.getServiceInformationEntity(delegateExecution);
576     }
577
578     @Test
579     public void getServiceInstanceNameTest() throws Exception {
580         abstractBuilder.getServiceInstanceName(delegateExecution);
581     }
582
583 }