2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.datatypes.elements;
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;
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;
38 class PropertyDataDefinitionTest {
40 private PropertyDataDefinition propDef;
44 propDef = new PropertyDataDefinition();
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));
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));
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));
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));
85 void mergeDefaultValueWhenItWasNullBeforeMerge() {
86 final String defaultValue = "12345";
87 final String type = "1";
88 PropertyDataDefinition propForMerge = new PropertyDataDefinition();
89 propForMerge.setType(type);
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));
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);
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));
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);
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));
136 private PropertyDataDefinition createTestSubject() {
137 return new PropertyDataDefinition();
141 void testConstructor() {
142 PropertyDataDefinition testSubject;
146 testSubject = createTestSubject();
147 new PropertyDataDefinition(testSubject);
151 void testGetInputPath() {
152 PropertyDataDefinition testSubject;
156 testSubject = createTestSubject();
157 result = testSubject.getInputPath();
162 void testSetInputPath() {
163 PropertyDataDefinition testSubject;
164 String inputPath = "";
167 testSubject = createTestSubject();
168 testSubject.setInputPath(inputPath);
174 PropertyDataDefinition testSubject;
178 testSubject = createTestSubject();
179 result = testSubject.getName();
185 PropertyDataDefinition testSubject;
189 testSubject = createTestSubject();
190 testSubject.setName(name);
195 void testGetValue() {
196 PropertyDataDefinition testSubject;
200 testSubject = createTestSubject();
201 result = testSubject.getValue();
206 void testSetValue() {
207 PropertyDataDefinition testSubject;
211 testSubject = createTestSubject();
212 testSubject.setValue(value);
217 void testIsDefinition() {
218 PropertyDataDefinition testSubject;
222 testSubject = createTestSubject();
223 result = testSubject.isDefinition();
228 void testSetDefinition() {
229 PropertyDataDefinition testSubject;
230 boolean definition = false;
233 testSubject = createTestSubject();
234 testSubject.setDefinition(definition);
240 PropertyDataDefinition testSubject;
244 testSubject = createTestSubject();
245 result = testSubject.getType();
250 void testGetDefaultValue() {
251 PropertyDataDefinition testSubject;
255 testSubject = createTestSubject();
256 result = testSubject.getDefaultValue();
261 void testSetDefaultValue() {
262 PropertyDataDefinition testSubject;
263 String defaultValue = "";
266 testSubject = createTestSubject();
267 testSubject.setDefaultValue(defaultValue);
273 PropertyDataDefinition testSubject;
277 testSubject = createTestSubject();
278 testSubject.setType(type);
283 void testIsRequired() {
284 PropertyDataDefinition testSubject;
288 testSubject = createTestSubject();
289 result = testSubject.isRequired();
294 void testSetRequired() {
295 PropertyDataDefinition testSubject;
296 Boolean required = null;
299 testSubject = createTestSubject();
300 testSubject.setRequired(required);
305 void testGetDescription() {
306 PropertyDataDefinition testSubject;
310 testSubject = createTestSubject();
311 result = testSubject.getDescription();
316 void testSetDescription() {
317 PropertyDataDefinition testSubject;
318 String description = "";
321 testSubject = createTestSubject();
322 testSubject.setDescription(description);
327 void testIsPassword() {
328 PropertyDataDefinition testSubject;
332 testSubject = createTestSubject();
333 result = testSubject.isPassword();
338 void testSetPassword() {
339 PropertyDataDefinition testSubject;
340 boolean password = false;
343 testSubject = createTestSubject();
344 testSubject.setPassword(password);
349 void testGetUniqueId() {
350 PropertyDataDefinition testSubject;
354 testSubject = createTestSubject();
355 result = testSubject.getUniqueId();
360 void testSetUniqueId() {
361 PropertyDataDefinition testSubject;
362 String uniqueId = "";
365 testSubject = createTestSubject();
366 testSubject.setUniqueId(uniqueId);
371 void testGetSchema() {
372 PropertyDataDefinition testSubject;
373 SchemaDefinition result;
376 testSubject = createTestSubject();
377 result = testSubject.getSchema();
382 void testSetSchema() {
383 PropertyDataDefinition testSubject;
384 SchemaDefinition entrySchema = null;
387 testSubject = createTestSubject();
388 testSubject.setSchema(entrySchema);
393 void testGetLabel() {
394 PropertyDataDefinition testSubject;
398 testSubject = createTestSubject();
399 result = testSubject.getLabel();
404 void testSetLabel() {
405 PropertyDataDefinition testSubject;
409 testSubject = createTestSubject();
410 testSubject.setLabel(label);
415 void testIsHidden() {
416 PropertyDataDefinition testSubject;
420 testSubject = createTestSubject();
421 result = testSubject.isHidden();
426 void testSetHidden() {
427 PropertyDataDefinition testSubject;
428 Boolean hidden = null;
431 testSubject = createTestSubject();
432 testSubject.setHidden(hidden);
437 void testIsImmutable() {
438 PropertyDataDefinition testSubject;
442 testSubject = createTestSubject();
443 result = testSubject.isImmutable();
448 void testSetImmutable() {
449 PropertyDataDefinition testSubject;
450 Boolean immutable = null;
453 testSubject = createTestSubject();
454 testSubject.setImmutable(immutable);
459 void testGetParentUniqueId() {
460 PropertyDataDefinition testSubject;
464 testSubject = createTestSubject();
465 result = testSubject.getParentUniqueId();
470 void testSetParentUniqueId() {
471 PropertyDataDefinition testSubject;
472 String parentUniqueId = "";
475 testSubject = createTestSubject();
476 testSubject.setParentUniqueId(parentUniqueId);
481 void testGetGetInputValues() {
482 PropertyDataDefinition testSubject;
483 List<GetInputValueDataDefinition> result;
486 testSubject = createTestSubject();
487 result = testSubject.getGetInputValues();
492 void testSetGetInputValues() {
493 PropertyDataDefinition testSubject;
494 List<GetInputValueDataDefinition> getInputValues = null;
497 testSubject = createTestSubject();
498 testSubject.setGetInputValues(getInputValues);
503 void testGetStatus() {
504 PropertyDataDefinition testSubject;
508 testSubject = createTestSubject();
509 result = testSubject.getStatus();
514 void testSetStatus() {
515 PropertyDataDefinition testSubject;
519 testSubject = createTestSubject();
520 testSubject.setStatus(status);
525 void testGetInputId() {
526 PropertyDataDefinition testSubject;
530 testSubject = createTestSubject();
531 result = testSubject.getInputId();
536 void testSetInputId() {
537 PropertyDataDefinition testSubject;
541 testSubject = createTestSubject();
542 testSubject.setInputId(inputId);
547 void testGetInstanceUniqueId() {
548 PropertyDataDefinition testSubject;
552 testSubject = createTestSubject();
553 result = testSubject.getInstanceUniqueId();
558 void testSetInstanceUniqueId() {
559 PropertyDataDefinition testSubject;
560 String instanceUniqueId = "";
563 testSubject = createTestSubject();
564 testSubject.setInstanceUniqueId(instanceUniqueId);
569 void testGetPropertyId() {
570 PropertyDataDefinition testSubject;
574 testSubject = createTestSubject();
575 result = testSubject.getPropertyId();
580 void testSetPropertyId() {
581 PropertyDataDefinition testSubject;
582 String propertyId = "";
585 testSubject = createTestSubject();
586 testSubject.setPropertyId(propertyId);
591 void testToString() {
592 PropertyDataDefinition testSubject;
596 testSubject = createTestSubject();
597 result = testSubject.toString();
602 void testHashCode() {
603 PropertyDataDefinition testSubject;
607 testSubject = createTestSubject();
608 result = testSubject.hashCode();
614 PropertyDataDefinition testSubject;
619 testSubject = createTestSubject();
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);
631 void testConvertPropertyDataToInstancePropertyData() {
632 PropertyDataDefinition testSubject;
635 testSubject = createTestSubject();
636 testSubject.convertPropertyDataToInstancePropertyData();
640 void testTypeEquals() {
641 PropertyDataDefinition testSubject;
644 testSubject = createTestSubject();
645 testSubject.typeEquals(testSubject);
646 testSubject.typeEquals(null);
647 testSubject.typeEquals(createTestSubject());
651 void testMergeFunction() {
652 PropertyDataDefinition testSubject;
655 testSubject = createTestSubject();
656 testSubject.mergeFunction(createTestSubject(), false);
661 void schemaTypeNullWhenSchemaIsNull() {
662 String sampleSchemaType = "sampleSchemaType";
663 PropertyDataDefinition testSubject = createTestSubject();
664 testSubject.setSchemaType(sampleSchemaType);
665 assertNull(testSubject.getSchemaType());
669 void schemaTypeIsReturnedWhenSchemaIsPresent() {
670 String sampleSchemaType = "sampleSchemaType";
671 SchemaDefinition schemaDefinition = new SchemaDefinition();
672 schemaDefinition.setProperty(new PropertyDataDefinition());
674 PropertyDataDefinition testSubject = createTestSubject();
675 testSubject.setSchema(schemaDefinition);
676 testSubject.setSchemaType(sampleSchemaType);
678 assertThat(testSubject.getSchemaType(), is(equalTo(sampleSchemaType)));
682 void getToscaGetFunctionTypeTest() {
683 var propertyDataDefinition = new PropertyDataDefinition();
684 assertNull(propertyDataDefinition.getToscaGetFunctionType());
686 final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
687 propertyDataDefinition.setToscaFunction(toscaGetFunction);
689 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
690 assertEquals(ToscaGetFunctionType.GET_INPUT, propertyDataDefinition.getToscaGetFunctionType());
692 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_PROPERTY);
693 assertEquals(ToscaGetFunctionType.GET_PROPERTY, propertyDataDefinition.getToscaGetFunctionType());
695 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_ATTRIBUTE);
696 assertEquals(ToscaGetFunctionType.GET_ATTRIBUTE, propertyDataDefinition.getToscaGetFunctionType());
700 void isToscaFunctionTest() {
701 var propertyDataDefinition = new PropertyDataDefinition();
702 assertFalse(propertyDataDefinition.isToscaFunction());
704 propertyDataDefinition.setToscaGetFunctionType(ToscaGetFunctionType.GET_PROPERTY);
705 assertTrue(propertyDataDefinition.isToscaFunction());
707 propertyDataDefinition = new PropertyDataDefinition();
708 propertyDataDefinition.setToscaFunction(new ToscaConcatFunction());
709 assertTrue(propertyDataDefinition.isToscaFunction());
713 void isToscaGetFunctionTest() {
714 final var propertyDataDefinition = new PropertyDataDefinition();
715 final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
716 toscaGetFunction.setFunctionType(ToscaGetFunctionType.GET_INPUT);
717 propertyDataDefinition.setToscaFunction(toscaGetFunction);
718 assertTrue(propertyDataDefinition.isToscaGetFunction());
720 propertyDataDefinition.setToscaFunction(new ToscaConcatFunction());
721 assertFalse(propertyDataDefinition.isToscaGetFunction());