Replaced all tabs with spaces in java and pom.xml
[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 import java.util.Collection;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.Set;
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;
41
42 public class AbstractBuilderTest {
43
44     AbstractBuilder<?, ?> abstractBuilder = new AbstractBuilder<Object, Object>() {
45         @Override
46         Object build(DelegateExecution execution, Object input) throws Exception {
47             return null;
48         }
49     };
50
51     DelegateExecution delegateExecution = new DelegateExecution() {
52         private String operType;
53         private String resourceType;
54         private String requestId;
55
56         @Override
57         public String getProcessInstanceId() {
58             return null;
59         }
60
61         @Override
62         public String getProcessBusinessKey() {
63             return null;
64         }
65
66         @Override
67         public String getProcessDefinitionId() {
68             return null;
69         }
70
71         @Override
72         public String getParentId() {
73             return null;
74         }
75
76         @Override
77         public String getCurrentActivityId() {
78             return null;
79         }
80
81         @Override
82         public String getCurrentActivityName() {
83             return null;
84         }
85
86         @Override
87         public String getActivityInstanceId() {
88             return null;
89         }
90
91         @Override
92         public String getParentActivityInstanceId() {
93             return null;
94         }
95
96         @Override
97         public String getCurrentTransitionId() {
98             return null;
99         }
100
101         @Override
102         public DelegateExecution getProcessInstance() {
103             return null;
104         }
105
106         @Override
107         public DelegateExecution getSuperExecution() {
108             return null;
109         }
110
111         @Override
112         public boolean isCanceled() {
113             return false;
114         }
115
116         @Override
117         public String getTenantId() {
118             return null;
119         }
120
121         @Override
122         public void setVariable(String s, Object o, String s1) {
123
124         }
125
126         @Override
127         public Incident createIncident(String s, String s1) {
128             return null;
129         }
130
131         @Override
132         public Incident createIncident(String s, String s1, String s2) {
133             return null;
134         }
135
136         @Override
137         public void resolveIncident(String s) {
138
139         }
140
141         @Override
142         public String getId() {
143             return null;
144         }
145
146         @Override
147         public String getEventName() {
148             return null;
149         }
150
151         @Override
152         public String getBusinessKey() {
153             return null;
154         }
155
156         @Override
157         public BpmnModelInstance getBpmnModelInstance() {
158             return null;
159         }
160
161         @Override
162         public FlowElement getBpmnModelElementInstance() {
163             return null;
164         }
165
166         @Override
167         public ProcessEngineServices getProcessEngineServices() {
168             return null;
169         }
170
171         @Override
172         public String getVariableScopeKey() {
173             return null;
174         }
175
176         @Override
177         public Map<String, Object> getVariables() {
178             return null;
179         }
180
181         @Override
182         public VariableMap getVariablesTyped() {
183             return null;
184         }
185
186         @Override
187         public VariableMap getVariablesTyped(boolean b) {
188             return null;
189         }
190
191         @Override
192         public Map<String, Object> getVariablesLocal() {
193             return null;
194         }
195
196         @Override
197         public VariableMap getVariablesLocalTyped() {
198             return null;
199         }
200
201         @Override
202         public VariableMap getVariablesLocalTyped(boolean b) {
203             return null;
204         }
205
206         @Override
207         public Object getVariable(String s) {
208             if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
209                 return operType;
210             } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
211                 return resourceType;
212             } else if ("msoRequestId".equals(s)) {
213                 return requestId;
214             }
215             return null;
216         }
217
218         @Override
219         public Object getVariableLocal(String s) {
220             return null;
221         }
222
223         @Override
224         public <T extends TypedValue> T getVariableTyped(String s) {
225             return null;
226         }
227
228         @Override
229         public <T extends TypedValue> T getVariableTyped(String s, boolean b) {
230             return null;
231         }
232
233         @Override
234         public <T extends TypedValue> T getVariableLocalTyped(String s) {
235             return null;
236         }
237
238         @Override
239         public <T extends TypedValue> T getVariableLocalTyped(String s, boolean b) {
240             return null;
241         }
242
243         @Override
244         public Set<String> getVariableNames() {
245             return null;
246         }
247
248         @Override
249         public Set<String> getVariableNamesLocal() {
250             return null;
251         }
252
253         @Override
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;
261             }
262         }
263
264         @Override
265         public void setVariableLocal(String s, Object o) {
266
267         }
268
269         @Override
270         public void setVariables(Map<String, ?> map) {
271
272         }
273
274         @Override
275         public void setVariablesLocal(Map<String, ?> map) {
276
277         }
278
279         @Override
280         public boolean hasVariables() {
281             return false;
282         }
283
284         @Override
285         public boolean hasVariablesLocal() {
286             return false;
287         }
288
289         @Override
290         public boolean hasVariable(String s) {
291             return false;
292         }
293
294         @Override
295         public boolean hasVariableLocal(String s) {
296             return false;
297         }
298
299         @Override
300         public void removeVariable(String s) {
301
302         }
303
304         @Override
305         public void removeVariableLocal(String s) {
306
307         }
308
309         @Override
310         public void removeVariables(Collection<String> collection) {
311
312         }
313
314         @Override
315         public void removeVariablesLocal(Collection<String> collection) {
316
317         }
318
319         @Override
320         public void removeVariables() {
321
322         }
323
324         @Override
325         public void removeVariablesLocal() {
326
327         }
328
329         @Override
330         public ProcessEngine getProcessEngine() {
331             // TODO Auto-generated method stub
332             return null;
333         }
334
335         @Override
336         public void setProcessBusinessKey(String arg0) {
337             // TODO Auto-generated method stub
338
339         }
340     };
341
342     @Test
343     public void requestActionGetIntValueTest() {
344         assertEquals(0, RequestAction.CREATE_NETWORK_INSTANCE.getIntValue());
345     }
346
347     @Test
348     public void svcActionGetIntValueTest() {
349         assertEquals(0, SvcAction.RESERVE.getIntValue());
350     }
351
352     @Test
353     public void buildTest() throws Exception {
354         abstractBuilder.build(null, null);
355     }
356
357     @Test
358     public void getRequestActionBlankOperationTypeTest() throws Exception {
359         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(),
360                 abstractBuilder.getRequestAction(delegateExecution));
361     }
362
363     @Test
364     public void getRequestActionDeleteOperationTypeBlankResourceTypeTest() throws Exception {
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));
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(),
376                 abstractBuilder.getRequestAction(delegateExecution));
377     }
378
379     @Test
380     public void getRequestActionDeleteOperationTypeOverlayResourceTypeTest() throws Exception {
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));
385     }
386
387     @Test
388     public void getRequestActionDeleteOperationTypeUnderlayResourceTypeTest() throws Exception {
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));
393     }
394
395     @Test
396     public void getRequestActionDeleteOperationTypeTest() throws Exception {
397         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
398         assertEquals(AbstractBuilder.RequestAction.DELETE_SERVICE_INSTANCE.getName(),
399                 abstractBuilder.getRequestAction(delegateExecution));
400     }
401
402     @Test
403     public void getRequestActionCreateOperationTypeBlankResourceTypeTest() throws Exception {
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));
408     }
409
410     @Test
411     public void getRequestActionCreateOperationTypeBadResourceTypeTest() throws Exception {
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));
416     }
417
418     @Test
419     public void getRequestActionCreateOperationTypeOverlayResourceTypeTest() throws Exception {
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));
424     }
425
426     @Test
427     public void getRequestActionCreateOperationTypeUnderlayResourceTypeTest() throws Exception {
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));
432     }
433
434     @Test
435     public void getRequestActionCreateOperationTypeTest() throws Exception {
436         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
437         assertEquals(AbstractBuilder.RequestAction.CREATE_SERVICE_INSTANCE.getName(),
438                 abstractBuilder.getRequestAction(delegateExecution));
439     }
440
441     @Test
442     public void getRequestActionBadOperationType() {
443         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
444         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(),
445                 abstractBuilder.getRequestAction(delegateExecution));
446     }
447
448     @Test
449     public void getSvcActionBlankOperationTypeTest() throws Exception {
450         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
451     }
452
453     @Test
454     public void getSvcActionDeleteOperationTypeBlankResourceTypeTest() throws Exception {
455         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
456         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
457         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
458     }
459
460     @Test
461     public void getSvcActionDeleteOperationTypeBadResourceTypeTest() throws Exception {
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));
465     }
466
467     @Test
468     public void getSvcActionDeleteOperationTypeOverlayResourceTypeTest() throws Exception {
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));
472     }
473
474     @Test
475     public void getSvcActionDeleteOperationTypeUnderlayResourceTypeTest() throws Exception {
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));
479     }
480
481     @Test
482     public void getSvcActionDeleteOperationTypeTest() throws Exception {
483         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
484         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
485     }
486
487     @Test
488     public void getSvcActionCreateOperationTypeBlankResourceTypeTest() throws Exception {
489         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
490         delegateExecution.setVariable(AbstractBuilder.RESOURCE_TYPE, "");
491         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
492     }
493
494     @Test
495     public void getSvcActionCreateOperationTypeBadResourceTypeTest() throws Exception {
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));
499     }
500
501     @Test
502     public void getSvcActionCreateOperationTypeOverlayResourceTypeTest() throws Exception {
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));
506     }
507
508     @Test
509     public void getSvcActionCreateOperationTypeUnderlayResourceTypeTest() throws Exception {
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));
513     }
514
515     @Test
516     public void getSvcActionCreateOperationTypeTest() throws Exception {
517         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
518         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
519     }
520
521     @Test
522     public void getSvcActionBadOperationType() {
523         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
524         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
525     }
526
527     @Test
528     public void getRequestIdBlankNotOnExecutionTest() {
529         abstractBuilder.getRequestId(delegateExecution);
530     }
531
532     @Test
533     public void getRequestIdBlankOnExecutionTest() {
534         String expected = "requestId";
535         delegateExecution.setVariable("msoRequestId", expected);
536         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
537     }
538
539     @Test
540     public void getRequestIdTest() {
541         String expected = "requestId";
542         abstractBuilder.requestId = expected;
543         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
544     }
545
546     @Test
547     public void getOnapServiceModelInformationEntityTest() throws Exception {
548         abstractBuilder.getOnapServiceModelInformationEntity(delegateExecution);
549     }
550
551     @Test
552     public void getOnapNetworkModelInformationEntityTest() throws Exception {
553         abstractBuilder.getOnapNetworkModelInformationEntity(delegateExecution);
554     }
555
556     @Test
557     public void getParamEntitiesTest() throws Exception {
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());
564     }
565
566     @Test
567     public void getParamEntitiesNullInputsTest() {
568         List<ParamEntity> list = abstractBuilder.getParamEntities(null);
569         assertEquals(0, list.size());
570     }
571
572     @Test
573     public void getParamEntitiesEmptyInputsTest() {
574         List<ParamEntity> list = abstractBuilder.getParamEntities(new HashMap<>());
575         assertEquals(0, list.size());
576     }
577
578     @Test
579     public void getRequestInformationEntityTest() throws Exception {
580         abstractBuilder.getRequestInformationEntity(delegateExecution);
581     }
582
583     @Test
584     public void getServiceInformationEntityTest() throws Exception {
585         abstractBuilder.getServiceInformationEntity(delegateExecution);
586     }
587
588     @Test
589     public void getServiceInstanceNameTest() throws Exception {
590         abstractBuilder.getServiceInstanceName(delegateExecution);
591     }
592
593 }