Containerization feature of SO
[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.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;
42
43 public class AbstractBuilderTest {
44
45     AbstractBuilder<?, ?> abstractBuilder = new AbstractBuilder<Object, Object>() {
46         @Override
47         Object build(DelegateExecution execution, Object input) throws Exception {
48             return null;
49         }
50     };
51
52     DelegateExecution delegateExecution = new DelegateExecution() {
53         private String operType;
54                 private String resourceType;
55                 private String requestId;
56                 
57         @Override
58         public String getProcessInstanceId() {
59             return null;
60         }
61
62         @Override
63         public String getProcessBusinessKey() {
64             return null;
65         }
66
67         @Override
68         public String getProcessDefinitionId() {
69             return null;
70         }
71
72         @Override
73         public String getParentId() {
74             return null;
75         }
76
77         @Override
78         public String getCurrentActivityId() {
79             return null;
80         }
81
82         @Override
83         public String getCurrentActivityName() {
84             return null;
85         }
86
87         @Override
88         public String getActivityInstanceId() {
89             return null;
90         }
91
92         @Override
93         public String getParentActivityInstanceId() {
94             return null;
95         }
96
97         @Override
98         public String getCurrentTransitionId() {
99             return null;
100         }
101
102         @Override
103         public DelegateExecution getProcessInstance() {
104             return null;
105         }
106
107         @Override
108         public DelegateExecution getSuperExecution() {
109             return null;
110         }
111
112         @Override
113         public boolean isCanceled() {
114             return false;
115         }
116
117         @Override
118         public String getTenantId() {
119             return null;
120         }
121
122         @Override
123         public void setVariable(String s, Object o, String s1) {
124
125         }
126
127         @Override
128         public Incident createIncident(String s, String s1) {
129             return null;
130         }
131
132         @Override
133         public Incident createIncident(String s, String s1, String s2) {
134             return null;
135         }
136
137         @Override
138         public void resolveIncident(String s) {
139
140         }
141
142         @Override
143         public String getId() {
144             return null;
145         }
146
147         @Override
148         public String getEventName() {
149             return null;
150         }
151
152         @Override
153         public String getBusinessKey() {
154             return null;
155         }
156
157         @Override
158         public BpmnModelInstance getBpmnModelInstance() {
159             return null;
160         }
161
162         @Override
163         public FlowElement getBpmnModelElementInstance() {
164             return null;
165         }
166
167         @Override
168         public ProcessEngineServices getProcessEngineServices() {
169             return null;
170         }
171
172         @Override
173         public String getVariableScopeKey() {
174             return null;
175         }
176
177         @Override
178         public Map<String, Object> getVariables() {
179             return null;
180         }
181
182         @Override
183         public VariableMap getVariablesTyped() {
184             return null;
185         }
186
187         @Override
188         public VariableMap getVariablesTyped(boolean b) {
189             return null;
190         }
191
192         @Override
193         public Map<String, Object> getVariablesLocal() {
194             return null;
195         }
196
197         @Override
198         public VariableMap getVariablesLocalTyped() {
199             return null;
200         }
201
202         @Override
203         public VariableMap getVariablesLocalTyped(boolean b) {
204             return null;
205         }
206
207         @Override
208         public Object getVariable(String s) {
209                 if (AbstractBuilder.OPERATION_TYPE.equals(s)) {
210                         return operType;
211                 } else if (AbstractBuilder.RESOURCE_TYPE.equals(s)) {
212                         return resourceType;
213                 } else if ("msoRequestId".equals(s)) {
214                         return requestId;
215                 }
216                 return null;
217         }
218
219         @Override
220         public Object getVariableLocal(String s) {
221             return null;
222         }
223
224         @Override
225         public <T extends TypedValue> T getVariableTyped(String s) {
226             return null;
227         }
228
229         @Override
230         public <T extends TypedValue> T getVariableTyped(String s, boolean b) {
231             return null;
232         }
233
234         @Override
235         public <T extends TypedValue> T getVariableLocalTyped(String s) {
236             return null;
237         }
238
239         @Override
240         public <T extends TypedValue> T getVariableLocalTyped(String s, boolean b) {
241             return null;
242         }
243
244         @Override
245         public Set<String> getVariableNames() {
246             return null;
247         }
248
249         @Override
250         public Set<String> getVariableNamesLocal() {
251             return null;
252         }
253
254         @Override
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;
262                 }
263         }
264
265         @Override
266         public void setVariableLocal(String s, Object o) {
267
268         }
269
270         @Override
271         public void setVariables(Map<String, ?> map) {
272
273         }
274
275         @Override
276         public void setVariablesLocal(Map<String, ?> map) {
277
278         }
279
280         @Override
281         public boolean hasVariables() {
282             return false;
283         }
284
285         @Override
286         public boolean hasVariablesLocal() {
287             return false;
288         }
289
290         @Override
291         public boolean hasVariable(String s) {
292             return false;
293         }
294
295         @Override
296         public boolean hasVariableLocal(String s) {
297             return false;
298         }
299
300         @Override
301         public void removeVariable(String s) {
302
303         }
304
305         @Override
306         public void removeVariableLocal(String s) {
307
308         }
309
310         @Override
311         public void removeVariables(Collection<String> collection) {
312
313         }
314
315         @Override
316         public void removeVariablesLocal(Collection<String> collection) {
317
318         }
319
320         @Override
321         public void removeVariables() {
322
323         }
324
325         @Override
326         public void removeVariablesLocal() {
327
328         }
329     };
330
331     @Test
332     public void requestActionGetIntValueTest() {
333         assertEquals(0, RequestAction.CREATE_NETWORK_INSTANCE.getIntValue());
334     }
335     
336     @Test
337     public void svcActionGetIntValueTest() {
338         assertEquals(0, SvcAction.RESERVE.getIntValue());
339     }
340     
341     @Test
342     public void buildTest() throws Exception {
343         abstractBuilder.build(null, null);
344     }
345
346     @Test
347     public void getRequestActionBlankOperationTypeTest() throws Exception {
348         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
349     }
350     
351     @Test
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));
356     }
357     
358     @Test
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));
363     }
364     
365     @Test
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));
370     }
371     
372     @Test
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));
377     }
378     
379     @Test
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));
383     }
384        
385     @Test
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));
390     }
391     
392     @Test
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));
397     }
398     
399     @Test
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));
404     }
405     
406     @Test
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));
411     }
412     
413     @Test
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));
417     }
418     
419     @Test
420     public void getRequestActionBadOperationType() {
421         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
422         assertEquals(AbstractBuilder.RequestAction.CREATE_NETWORK_INSTANCE.getName(), abstractBuilder.getRequestAction(delegateExecution));
423     }
424
425     @Test
426     public void getSvcActionBlankOperationTypeTest() throws Exception {
427         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
428     }
429     
430     @Test
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));
435     }
436     
437     @Test
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));
442     }
443     
444     @Test
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));
449     }
450     
451     @Test
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));
456     }
457     
458     @Test
459     public void getSvcActionDeleteOperationTypeTest() throws Exception {
460         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.DELETE);
461         assertEquals(AbstractBuilder.SvcAction.UNASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
462     }
463        
464     @Test
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));
469     }
470     
471     @Test
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));
476     }
477     
478     @Test
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));
483     }
484     
485     @Test
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));
490     }
491     
492     @Test
493     public void getSvcActionCreateOperationTypeTest() throws Exception {
494         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, RequestsDbConstant.OperationType.CREATE);
495         assertEquals(AbstractBuilder.SvcAction.ASSIGN.getName(), abstractBuilder.getSvcAction(delegateExecution));
496     }
497     
498     @Test
499     public void getSvcActionBadOperationType() {
500         delegateExecution.setVariable(AbstractBuilder.OPERATION_TYPE, "bad");
501         assertEquals(AbstractBuilder.SvcAction.CREATE.getName(), abstractBuilder.getSvcAction(delegateExecution));
502     }
503
504     @Test
505     public void getRequestIdBlankNotOnExecutionTest() {
506         abstractBuilder.getRequestId(delegateExecution);
507     }
508     
509     @Test
510     public void getRequestIdBlankOnExecutionTest() {
511         String expected = "requestId";
512         delegateExecution.setVariable("msoRequestId", expected);
513         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
514     }
515     
516     @Test
517     public void getRequestIdTest() {
518         String expected = "requestId";
519         abstractBuilder.requestId = expected;
520         assertEquals(expected, abstractBuilder.getRequestId(delegateExecution));
521     }
522
523     @Test
524     public void getOnapServiceModelInformationEntityTest() throws Exception {
525         abstractBuilder.getOnapServiceModelInformationEntity(delegateExecution);
526     }
527
528     @Test
529     public void getOnapNetworkModelInformationEntityTest() throws Exception {
530         abstractBuilder.getOnapNetworkModelInformationEntity(delegateExecution);
531     }
532
533     @Test
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());
541     }
542     
543     @Test
544     public void getParamEntitiesNullInputsTest() {
545         List<ParamEntity> list = abstractBuilder.getParamEntities(null);
546         assertEquals(0, list.size());
547     }
548     
549     @Test
550     public void getParamEntitiesEmptyInputsTest() {
551         List<ParamEntity> list = abstractBuilder.getParamEntities(new HashMap<>());
552         assertEquals(0, list.size());
553     }
554
555     @Test
556     public void getRequestInformationEntityTest() throws Exception {
557         abstractBuilder.getRequestInformationEntity(delegateExecution);
558     }
559
560     @Test
561     public void getServiceInformationEntityTest() throws Exception {
562         abstractBuilder.getServiceInformationEntity(delegateExecution);
563     }
564
565     @Test
566     public void getServiceInstanceNameTest() throws Exception {
567         abstractBuilder.getServiceInstanceName(delegateExecution);
568     }
569
570 }