Support for concat TOSCA function
[sdc.git] / common-be / src / test / java / org / openecomp / sdc / be / datatypes / elements / PropertyDataDefinitionTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T 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
21 package org.openecomp.sdc.be.datatypes.elements;
22
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.junit.jupiter.api.Assertions.assertEquals;
27 import static org.junit.jupiter.api.Assertions.assertFalse;
28 import static org.junit.jupiter.api.Assertions.assertNull;
29 import static org.junit.jupiter.api.Assertions.assertTrue;
30
31 import java.util.List;
32 import org.junit.jupiter.api.BeforeEach;
33 import org.junit.jupiter.api.Test;
34 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
35 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
36
37
38 class PropertyDataDefinitionTest {
39
40         private PropertyDataDefinition propDef;
41
42         @BeforeEach
43         public void setUp() {
44                 propDef = new PropertyDataDefinition();
45         }
46
47         @Test
48     void setStringField() {
49                 final String name = "name";
50                 assertNull(propDef.getName());
51                 assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.NAME));
52                 propDef.setToscaPresentationValue(JsonPresentationFields.NAME, name);
53                 assertEquals(name, propDef.getName());
54                 assertEquals(name, propDef.getToscaPresentationValue(JsonPresentationFields.NAME));
55         }
56
57         @Test
58     void setDefaultValue() {
59                 final String defaultValue = "text";
60                 assertNull(propDef.getDefaultValue());
61                 assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
62                 propDef.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, defaultValue);
63                 assertEquals(defaultValue, propDef.getDefaultValue());
64                 assertEquals(defaultValue, propDef.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
65         }
66
67         @Test
68     void setValueNotDefinedInPropDataDefinition() {
69                 final String defaultValue = "VF";
70                 assertNull(propDef.getToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE));
71                 propDef.setToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE, defaultValue);
72                 assertEquals(defaultValue, propDef.getToscaPresentationValue(JsonPresentationFields.COMPONENT_TYPE));
73         }
74
75         @Test
76     void setBooleanField() {
77                 assertFalse((Boolean) propDef.getToscaPresentationValue(JsonPresentationFields.PASSWORD));
78                 assertFalse(propDef.isPassword());
79                 propDef.setToscaPresentationValue(JsonPresentationFields.PASSWORD, Boolean.TRUE);
80                 assertTrue(propDef.isPassword());
81                 assertTrue((Boolean) propDef.getToscaPresentationValue(JsonPresentationFields.PASSWORD));
82         }
83
84         @Test
85     void mergeDefaultValueWhenItWasNullBeforeMerge() {
86                 final String defaultValue = "12345";
87                 final String type = "1";
88                 PropertyDataDefinition propForMerge = new PropertyDataDefinition();
89                 propForMerge.setType(type);
90
91                 propDef.setType(type);
92                 propDef.setDefaultValue(defaultValue);
93                 assertNull(propForMerge.getDefaultValue());
94                 assertNull(propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
95                 propDef.mergeFunction(propForMerge, true);
96                 assertEquals(defaultValue, propForMerge.getDefaultValue());
97                 assertEquals(defaultValue, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
98         }
99
100         @Test
101     void mergeDefaultValueAndOverrideIt() {
102                 final String defaultValue = "12345";
103                 final String defaultValueForOther = "7890";
104                 final String type = "1";
105                 PropertyDataDefinition propForMerge = new PropertyDataDefinition();
106                 propForMerge.setType(type);
107                 propForMerge.setDefaultValue(defaultValueForOther);
108
109                 propDef.setType(type);
110                 propDef.setDefaultValue(defaultValue);
111                 assertEquals(defaultValueForOther, propForMerge.getDefaultValue());
112                 assertEquals(defaultValueForOther, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
113                 propDef.mergeFunction(propForMerge, true);
114                 assertEquals(defaultValue, propForMerge.getDefaultValue());
115                 assertEquals(defaultValue, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
116         }
117
118         @Test
119     void mergeDefaultValueWhenOverridingIsNotAllowed() {
120                 final String defaultValue = "12345";
121                 final String defaultValueForOther = "7890";
122                 final String type = "1";
123                 PropertyDataDefinition propForMerge = new PropertyDataDefinition();
124                 propForMerge.setType(type);
125                 propForMerge.setDefaultValue(defaultValueForOther);
126
127                 propDef.setType(type);
128                 propDef.setDefaultValue(defaultValue);
129                 assertEquals(defaultValueForOther, propForMerge.getDefaultValue());
130                 assertEquals(defaultValueForOther, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
131                 propDef.mergeFunction(propForMerge, false);
132                 assertEquals(defaultValueForOther, propForMerge.getDefaultValue());
133                 assertEquals(defaultValueForOther, propForMerge.getToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE));
134         }
135
136         private PropertyDataDefinition createTestSubject() {
137                 return new PropertyDataDefinition();
138         }
139
140         @Test
141     void testConstructor() {
142                 PropertyDataDefinition testSubject;
143                 String result;
144
145                 // default test
146                 testSubject = createTestSubject();
147                 new PropertyDataDefinition(testSubject);
148         }
149
150         @Test
151     void testGetInputPath() {
152                 PropertyDataDefinition testSubject;
153                 String result;
154
155                 // default test
156                 testSubject = createTestSubject();
157                 result = testSubject.getInputPath();
158         }
159
160
161         @Test
162     void testSetInputPath() {
163                 PropertyDataDefinition testSubject;
164                 String inputPath = "";
165
166                 // default test
167                 testSubject = createTestSubject();
168                 testSubject.setInputPath(inputPath);
169         }
170
171
172         @Test
173     void testGetName() {
174                 PropertyDataDefinition testSubject;
175                 String result;
176
177                 // default test
178                 testSubject = createTestSubject();
179                 result = testSubject.getName();
180         }
181
182
183         @Test
184     void testSetName() {
185                 PropertyDataDefinition testSubject;
186                 String name = "";
187
188                 // default test
189                 testSubject = createTestSubject();
190                 testSubject.setName(name);
191         }
192
193
194         @Test
195     void testGetValue() {
196                 PropertyDataDefinition testSubject;
197                 String result;
198
199                 // default test
200                 testSubject = createTestSubject();
201                 result = testSubject.getValue();
202         }
203
204
205         @Test
206     void testSetValue() {
207                 PropertyDataDefinition testSubject;
208                 String value = "";
209
210                 // default test
211                 testSubject = createTestSubject();
212                 testSubject.setValue(value);
213         }
214
215
216         @Test
217     void testIsDefinition() {
218                 PropertyDataDefinition testSubject;
219                 boolean result;
220
221                 // default test
222                 testSubject = createTestSubject();
223                 result = testSubject.isDefinition();
224         }
225
226
227         @Test
228     void testSetDefinition() {
229                 PropertyDataDefinition testSubject;
230                 boolean definition = false;
231
232                 // default test
233                 testSubject = createTestSubject();
234                 testSubject.setDefinition(definition);
235         }
236
237
238         @Test
239     void testGetType() {
240                 PropertyDataDefinition testSubject;
241                 String result;
242
243                 // default test
244                 testSubject = createTestSubject();
245                 result = testSubject.getType();
246         }
247
248
249         @Test
250     void testGetDefaultValue() {
251                 PropertyDataDefinition testSubject;
252                 String result;
253
254                 // default test
255                 testSubject = createTestSubject();
256                 result = testSubject.getDefaultValue();
257         }
258
259
260         @Test
261     void testSetDefaultValue() {
262                 PropertyDataDefinition testSubject;
263                 String defaultValue = "";
264
265                 // default test
266                 testSubject = createTestSubject();
267                 testSubject.setDefaultValue(defaultValue);
268         }
269
270
271         @Test
272     void testSetType() {
273                 PropertyDataDefinition testSubject;
274                 String type = "";
275
276                 // default test
277                 testSubject = createTestSubject();
278                 testSubject.setType(type);
279         }
280
281
282         @Test
283     void testIsRequired() {
284                 PropertyDataDefinition testSubject;
285                 Boolean result;
286
287                 // default test
288                 testSubject = createTestSubject();
289                 result = testSubject.isRequired();
290         }
291
292
293         @Test
294     void testSetRequired() {
295                 PropertyDataDefinition testSubject;
296                 Boolean required = null;
297
298                 // default test
299                 testSubject = createTestSubject();
300                 testSubject.setRequired(required);
301         }
302
303
304         @Test
305     void testGetDescription() {
306                 PropertyDataDefinition testSubject;
307                 String result;
308
309                 // default test
310                 testSubject = createTestSubject();
311                 result = testSubject.getDescription();
312         }
313
314
315         @Test
316     void testSetDescription() {
317                 PropertyDataDefinition testSubject;
318                 String description = "";
319
320                 // default test
321                 testSubject = createTestSubject();
322                 testSubject.setDescription(description);
323         }
324
325
326         @Test
327     void testIsPassword() {
328                 PropertyDataDefinition testSubject;
329                 boolean result;
330
331                 // default test
332                 testSubject = createTestSubject();
333                 result = testSubject.isPassword();
334         }
335
336
337         @Test
338     void testSetPassword() {
339                 PropertyDataDefinition testSubject;
340                 boolean password = false;
341
342                 // default test
343                 testSubject = createTestSubject();
344                 testSubject.setPassword(password);
345         }
346
347
348         @Test
349     void testGetUniqueId() {
350                 PropertyDataDefinition testSubject;
351                 String result;
352
353                 // default test
354                 testSubject = createTestSubject();
355                 result = testSubject.getUniqueId();
356         }
357
358
359         @Test
360     void testSetUniqueId() {
361                 PropertyDataDefinition testSubject;
362                 String uniqueId = "";
363
364                 // default test
365                 testSubject = createTestSubject();
366                 testSubject.setUniqueId(uniqueId);
367         }
368
369
370         @Test
371     void testGetSchema() {
372                 PropertyDataDefinition testSubject;
373                 SchemaDefinition result;
374
375                 // default test
376                 testSubject = createTestSubject();
377                 result = testSubject.getSchema();
378         }
379
380
381         @Test
382     void testSetSchema() {
383                 PropertyDataDefinition testSubject;
384                 SchemaDefinition entrySchema = null;
385
386                 // default test
387                 testSubject = createTestSubject();
388                 testSubject.setSchema(entrySchema);
389         }
390
391
392         @Test
393     void testGetLabel() {
394                 PropertyDataDefinition testSubject;
395                 String result;
396
397                 // default test
398                 testSubject = createTestSubject();
399                 result = testSubject.getLabel();
400         }
401
402
403         @Test
404     void testSetLabel() {
405                 PropertyDataDefinition testSubject;
406                 String label = "";
407
408                 // default test
409                 testSubject = createTestSubject();
410                 testSubject.setLabel(label);
411         }
412
413
414         @Test
415     void testIsHidden() {
416                 PropertyDataDefinition testSubject;
417                 Boolean result;
418
419                 // default test
420                 testSubject = createTestSubject();
421                 result = testSubject.isHidden();
422         }
423
424
425         @Test
426     void testSetHidden() {
427                 PropertyDataDefinition testSubject;
428                 Boolean hidden = null;
429
430                 // default test
431                 testSubject = createTestSubject();
432                 testSubject.setHidden(hidden);
433         }
434
435
436         @Test
437     void testIsImmutable() {
438                 PropertyDataDefinition testSubject;
439                 Boolean result;
440
441                 // default test
442                 testSubject = createTestSubject();
443                 result = testSubject.isImmutable();
444         }
445
446
447         @Test
448     void testSetImmutable() {
449                 PropertyDataDefinition testSubject;
450                 Boolean immutable = null;
451
452                 // default test
453                 testSubject = createTestSubject();
454                 testSubject.setImmutable(immutable);
455         }
456
457
458         @Test
459     void testGetParentUniqueId() {
460                 PropertyDataDefinition testSubject;
461                 String result;
462
463                 // default test
464                 testSubject = createTestSubject();
465                 result = testSubject.getParentUniqueId();
466         }
467
468
469         @Test
470     void testSetParentUniqueId() {
471                 PropertyDataDefinition testSubject;
472                 String parentUniqueId = "";
473
474                 // default test
475                 testSubject = createTestSubject();
476                 testSubject.setParentUniqueId(parentUniqueId);
477         }
478
479
480         @Test
481     void testGetGetInputValues() {
482                 PropertyDataDefinition testSubject;
483                 List<GetInputValueDataDefinition> result;
484
485                 // default test
486                 testSubject = createTestSubject();
487                 result = testSubject.getGetInputValues();
488         }
489
490
491         @Test
492     void testSetGetInputValues() {
493                 PropertyDataDefinition testSubject;
494                 List<GetInputValueDataDefinition> getInputValues = null;
495
496                 // default test
497                 testSubject = createTestSubject();
498                 testSubject.setGetInputValues(getInputValues);
499         }
500
501
502         @Test
503     void testGetStatus() {
504                 PropertyDataDefinition testSubject;
505                 String result;
506
507                 // default test
508                 testSubject = createTestSubject();
509                 result = testSubject.getStatus();
510         }
511
512
513         @Test
514     void testSetStatus() {
515                 PropertyDataDefinition testSubject;
516                 String status = "";
517
518                 // default test
519                 testSubject = createTestSubject();
520                 testSubject.setStatus(status);
521         }
522
523
524         @Test
525     void testGetInputId() {
526                 PropertyDataDefinition testSubject;
527                 String result;
528
529                 // default test
530                 testSubject = createTestSubject();
531                 result = testSubject.getInputId();
532         }
533
534
535         @Test
536     void testSetInputId() {
537                 PropertyDataDefinition testSubject;
538                 String inputId = "";
539
540                 // default test
541                 testSubject = createTestSubject();
542                 testSubject.setInputId(inputId);
543         }
544
545
546         @Test
547     void testGetInstanceUniqueId() {
548                 PropertyDataDefinition testSubject;
549                 String result;
550
551                 // default test
552                 testSubject = createTestSubject();
553                 result = testSubject.getInstanceUniqueId();
554         }
555
556
557         @Test
558     void testSetInstanceUniqueId() {
559                 PropertyDataDefinition testSubject;
560                 String instanceUniqueId = "";
561
562                 // default test
563                 testSubject = createTestSubject();
564                 testSubject.setInstanceUniqueId(instanceUniqueId);
565         }
566
567
568         @Test
569     void testGetPropertyId() {
570                 PropertyDataDefinition testSubject;
571                 String result;
572
573                 // default test
574                 testSubject = createTestSubject();
575                 result = testSubject.getPropertyId();
576         }
577
578
579         @Test
580     void testSetPropertyId() {
581                 PropertyDataDefinition testSubject;
582                 String propertyId = "";
583
584                 // default test
585                 testSubject = createTestSubject();
586                 testSubject.setPropertyId(propertyId);
587         }
588
589
590         @Test
591     void testToString() {
592                 PropertyDataDefinition testSubject;
593                 String result;
594
595                 // default test
596                 testSubject = createTestSubject();
597                 result = testSubject.toString();
598         }
599
600
601         @Test
602     void testHashCode() {
603                 PropertyDataDefinition testSubject;
604                 int result;
605
606                 // default test
607                 testSubject = createTestSubject();
608                 result = testSubject.hashCode();
609         }
610
611
612         @Test
613     void testEquals() {
614                 PropertyDataDefinition testSubject;
615                 Object obj = null;
616                 boolean result;
617
618                 // test 1
619                 testSubject = createTestSubject();
620                 obj = null;
621                 result = testSubject.equals(obj);
622                 assertEquals(false, result);
623                 result = testSubject.equals(testSubject);
624                 assertEquals(true, result);
625                 PropertyDataDefinition other = createTestSubject();
626                 result = testSubject.equals(other);
627                 assertEquals(true, result);
628         }
629
630         @Test
631     void testConvertPropertyDataToInstancePropertyData() {
632                 PropertyDataDefinition testSubject;
633
634                 // default test
635                 testSubject = createTestSubject();
636                 testSubject.convertPropertyDataToInstancePropertyData();
637         }
638
639         @Test
640     void testTypeEquals() {
641                 PropertyDataDefinition testSubject;
642
643                 // default test
644                 testSubject = createTestSubject();
645                 testSubject.typeEquals(testSubject);
646                 testSubject.typeEquals(null);
647                 testSubject.typeEquals(createTestSubject());
648         }
649
650         @Test
651     void testMergeFunction() {
652                 PropertyDataDefinition testSubject;
653
654                 // default test
655                 testSubject = createTestSubject();
656                 testSubject.mergeFunction(createTestSubject(), false);
657
658         }
659
660         @Test
661     void schemaTypeNullWhenSchemaIsNull() {
662                 String sampleSchemaType = "sampleSchemaType";
663                 PropertyDataDefinition testSubject = createTestSubject();
664                 testSubject.setSchemaType(sampleSchemaType);
665                 assertNull(testSubject.getSchemaType());
666         }
667
668         @Test
669     void schemaTypeIsReturnedWhenSchemaIsPresent() {
670                 String sampleSchemaType = "sampleSchemaType";
671                 SchemaDefinition schemaDefinition = new SchemaDefinition();
672                 schemaDefinition.setProperty(new PropertyDataDefinition());
673
674                 PropertyDataDefinition testSubject = createTestSubject();
675                 testSubject.setSchema(schemaDefinition);
676                 testSubject.setSchemaType(sampleSchemaType);
677
678                 assertThat(testSubject.getSchemaType(), is(equalTo(sampleSchemaType)));
679         }
680
681         @Test
682     void getToscaGetFunctionTypeTest() {
683                 var propertyDataDefinition = new PropertyDataDefinition();
684                 assertNull(propertyDataDefinition.getToscaGetFunctionType());
685
686                 final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
687                 propertyDataDefinition.setToscaFunction(toscaGetFunction);
688
689                 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
690                 assertEquals(ToscaGetFunctionType.GET_INPUT, propertyDataDefinition.getToscaGetFunctionType());
691
692                 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_PROPERTY);
693                 assertEquals(ToscaGetFunctionType.GET_PROPERTY, propertyDataDefinition.getToscaGetFunctionType());
694
695                 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
696                 assertEquals(ToscaGetFunctionType.GET_ATTRIBUTE, propertyDataDefinition.getToscaGetFunctionType());
697
698                 propertyDataDefinition = new PropertyDataDefinition();
699                 propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_INPUT);
700                 assertEquals(ToscaGetFunctionType.GET_INPUT, propertyDataDefinition.getToscaGetFunctionType());
701
702                 propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
703                 assertEquals(ToscaGetFunctionType.GET_PROPERTY, propertyDataDefinition.getToscaGetFunctionType());
704
705                 propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
706                 assertEquals(ToscaGetFunctionType.GET_ATTRIBUTE, propertyDataDefinition.getToscaGetFunctionType());
707         }
708
709         @Test
710         void isToscaFunctionTest() {
711                 var propertyDataDefinition = new PropertyDataDefinition();
712                 assertFalse(propertyDataDefinition.isToscaFunction());
713
714                 propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
715                 assertTrue(propertyDataDefinition.isToscaFunction());
716
717                 propertyDataDefinition = new PropertyDataDefinition();
718                 propertyDataDefinition.setToscaFunction(new ToscaConcatFunction());
719                 assertTrue(propertyDataDefinition.isToscaFunction());
720         }
721
722         @Test
723         void isToscaGetFunctionTest() {
724                 var propertyDataDefinition = new PropertyDataDefinition();
725                 propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
726                 assertTrue(propertyDataDefinition.isToscaGetFunction());
727
728                 propertyDataDefinition = new PropertyDataDefinition();
729                 final ToscaGetFunctionDataDefinition toscaGetFunction = new ToscaGetFunctionDataDefinition();
730                 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
731                 propertyDataDefinition.setToscaFunction(toscaGetFunction);
732                 assertTrue(propertyDataDefinition.isToscaGetFunction());
733
734                 propertyDataDefinition.setToscaFunction(new ToscaConcatFunction());
735                 assertFalse(propertyDataDefinition.isToscaGetFunction());
736         }
737
738 }