2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.model.operations.impl;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.mock;
29 import fj.data.Either;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.List;
38 import org.apache.commons.lang3.tuple.ImmutablePair;
39 import org.janusgraph.core.JanusGraphVertex;
40 import org.junit.Assert;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.mockito.Mockito;
44 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
45 import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
46 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
47 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
48 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
49 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
50 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
51 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
53 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
54 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
55 import org.openecomp.sdc.be.model.DataTypeDefinition;
56 import org.openecomp.sdc.be.model.IComplexDefaultValue;
57 import org.openecomp.sdc.be.model.ModelTestBase;
58 import org.openecomp.sdc.be.model.PropertyConstraint;
59 import org.openecomp.sdc.be.model.PropertyDefinition;
60 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
61 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
62 import org.openecomp.sdc.be.model.tosca.ToscaType;
63 import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
64 import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
65 import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
66 import org.openecomp.sdc.be.resources.data.DataTypeData;
67 import org.openecomp.sdc.be.resources.data.PropertyData;
68 import org.openecomp.sdc.be.resources.data.PropertyValueData;
70 public class PropertyOperationTest extends ModelTestBase {
72 HealingJanusGraphGenericDao janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
74 final DataTypeOperation dataTypeOperation = mock(DataTypeOperation.class);
76 PropertyOperation propertyOperation = new PropertyOperation(janusGraphGenericDao, null);
80 propertyOperation.setDataTypeOperation(dataTypeOperation);
81 propertyOperation.setJanusGraphGenericDao(janusGraphGenericDao);
84 private PropertyDefinition buildPropertyDefinition() {
85 PropertyDefinition property = new PropertyDefinition();
86 property.setDefaultValue("10");
87 property.setDescription("Size of the local disk, in Gigabytes (GB), available to applications running on the Compute node.");
88 property.setType(ToscaType.INTEGER.name().toLowerCase());
93 public void convertConstraintsTest() {
95 List<PropertyConstraint> constraints = buildConstraints();
96 List<String> convertedStringConstraints = propertyOperation.convertConstraintsToString(constraints);
97 assertEquals("constraints size", constraints.size(), convertedStringConstraints.size());
99 List<PropertyConstraint> convertedConstraints = propertyOperation.convertConstraints(convertedStringConstraints);
100 assertEquals("check size of constraints", constraints.size(), convertedConstraints.size());
102 Set<String> constraintsClasses = new HashSet<>();
103 for (PropertyConstraint propertyConstraint : constraints) {
104 constraintsClasses.add(propertyConstraint.getClass().getName());
107 for (PropertyConstraint propertyConstraint : convertedConstraints) {
108 assertTrue("check all classes generated", constraintsClasses.contains(propertyConstraint.getClass().getName()));
113 public void testIsPropertyDefaultValueValid_NoDefault() {
114 PropertyDefinition property = new PropertyDefinition();
115 property.setName("myProperty");
116 property.setType(ToscaPropertyType.BOOLEAN.getType());
117 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
121 public void testIsPropertyDefaultValueValid_ValidDefault() {
122 PropertyDefinition property = new PropertyDefinition();
123 property.setName("myProperty");
124 property.setType(ToscaPropertyType.INTEGER.getType());
125 property.setDefaultValue("50");
126 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
130 public void testIsPropertyDefaultValueValid_InvalidDefault() {
131 PropertyDefinition property = new PropertyDefinition();
132 property.setName("myProperty");
133 property.setType(ToscaPropertyType.BOOLEAN.getType());
134 property.setDefaultValue("50");
135 assertFalse(propertyOperation.isPropertyDefaultValueValid(property, null));
138 private List<PropertyConstraint> buildConstraints() {
139 List<PropertyConstraint> constraints = new ArrayList<>();
140 GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0");
141 LessOrEqualConstraint propertyConstraint2 = new LessOrEqualConstraint("10");
142 List<String> range = new ArrayList<>();
145 InRangeConstraint propertyConstraint3 = new InRangeConstraint(range);
146 constraints.add(propertyConstraint1);
147 constraints.add(propertyConstraint2);
148 constraints.add(propertyConstraint3);
153 public void findPropertyValueBestMatch1() {
155 String propertyUniqueId = "x1";
156 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
157 instanceProperty.setValue("v1");
158 instanceProperty.setDefaultValue("vv1");
159 List<String> path = new ArrayList<>();
163 instanceProperty.setPath(path);
165 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
166 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
167 instanceProperty1.setValue("v1node1");
168 instanceIdToValue.put("node1", instanceProperty1);
170 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
171 instanceProperty2.setValue("v1node2");
172 instanceIdToValue.put("node2", instanceProperty2);
174 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
175 instanceProperty3.setValue("v1node3");
176 instanceIdToValue.put("node3", instanceProperty3);
178 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
180 assertEquals("check value", "v1node1", instanceProperty.getValue());
181 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
186 public void findPropertyValueBestMatch2() {
188 String propertyUniqueId = "x1";
189 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
190 instanceProperty.setValue("v1");
191 instanceProperty.setDefaultValue("vv1");
192 List<String> path = new ArrayList<>();
196 instanceProperty.setPath(path);
198 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
200 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
201 instanceProperty2.setValue("v1node2");
202 instanceProperty2.setValueUniqueUid("aaaa");
203 instanceIdToValue.put("node2", instanceProperty2);
205 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
207 assertEquals("check value", "v1node2", instanceProperty.getValue());
208 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
209 assertNull("check value unique id is null", instanceProperty.getValueUniqueUid());
214 public void findPropertyValueBestMatch3() {
216 String propertyUniqueId = "x1";
217 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
218 instanceProperty.setValue("v1");
219 instanceProperty.setDefaultValue("vv1");
220 List<String> path = new ArrayList<>();
224 instanceProperty.setPath(path);
226 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
227 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
228 instanceProperty1.setValue("v1node1");
229 instanceProperty1.setValueUniqueUid("aaaa");
230 instanceIdToValue.put("node1", instanceProperty1);
232 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
233 instanceProperty3.setValue("v1node3");
234 instanceIdToValue.put("node3", instanceProperty3);
236 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
238 assertEquals("check value", "v1node1", instanceProperty.getValue());
239 assertEquals("check default value", "v1node3", instanceProperty.getDefaultValue());
240 assertEquals("check valid unique id", instanceProperty1.getValueUniqueUid(), instanceProperty.getValueUniqueUid());
245 public void findPropertyValueBestMatch1Rules() {
247 String propertyUniqueId = "x1";
248 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
249 instanceProperty.setValue("v1");
250 instanceProperty.setDefaultValue("vv1");
251 List<String> path = new ArrayList<>();
255 instanceProperty.setPath(path);
257 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
258 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
259 instanceProperty1.setValue("v1node1");
261 List<PropertyRule> rules = new ArrayList<>();
262 PropertyRule propertyRule = new PropertyRule();
263 String[] ruleArr = { "node1", ".+", "node3" };
264 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr));
265 propertyRule.setRule(rule1);
266 propertyRule.setValue("88");
267 rules.add(propertyRule);
268 instanceProperty1.setRules(rules);
270 instanceIdToValue.put("node1", instanceProperty1);
272 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
273 instanceProperty2.setValue("v1node2");
274 instanceIdToValue.put("node2", instanceProperty2);
276 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
277 instanceProperty3.setValue("v1node3");
278 instanceIdToValue.put("node3", instanceProperty3);
280 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
282 assertEquals("check value", propertyRule.getValue(), instanceProperty.getValue());
283 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
288 public void findPropertyValueBestMatch2Rules() {
290 String propertyUniqueId = "x1";
291 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
292 instanceProperty.setValue("v1");
293 instanceProperty.setDefaultValue("vv1");
294 List<String> path = new ArrayList<>();
298 instanceProperty.setPath(path);
300 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
301 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
302 instanceProperty1.setValue("v1node1");
304 List<PropertyRule> rules = new ArrayList<>();
305 PropertyRule propertyRule1 = new PropertyRule();
306 String[] ruleArr1 = { "node1", "node2", ".+" };
307 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
308 propertyRule1.setRule(rule1);
309 propertyRule1.setValue("88");
311 PropertyRule propertyRule2 = new PropertyRule();
312 String[] ruleArr2 = { "node1", "node2", "node3" };
313 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
314 propertyRule2.setRule(rule2);
315 propertyRule2.setValue("99");
317 rules.add(propertyRule2);
318 rules.add(propertyRule1);
320 instanceProperty1.setRules(rules);
322 instanceIdToValue.put("node1", instanceProperty1);
324 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
325 instanceProperty2.setValue("v1node2");
326 instanceIdToValue.put("node2", instanceProperty2);
328 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
329 instanceProperty3.setValue("v1node3");
330 instanceIdToValue.put("node3", instanceProperty3);
332 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
334 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
335 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
340 public void findPropertyValueBestMatch1RuleLowLevel() {
342 String propertyUniqueId = "x1";
343 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
344 instanceProperty.setValue("v1");
345 instanceProperty.setDefaultValue("vv1");
346 List<String> path = new ArrayList<>();
350 instanceProperty.setPath(path);
352 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
353 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
354 instanceProperty1.setValue("v1node1");
356 List<PropertyRule> rules = new ArrayList<>();
357 PropertyRule propertyRule1 = new PropertyRule();
358 String[] ruleArr1 = { "node1", "node2", ".+" };
359 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
360 propertyRule1.setRule(rule1);
361 propertyRule1.setValue("88");
363 PropertyRule propertyRule2 = new PropertyRule();
364 String[] ruleArr2 = { "node1", "node2", "node3" };
365 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
366 propertyRule2.setRule(rule2);
367 propertyRule2.setValue("99");
369 rules.add(propertyRule2);
370 rules.add(propertyRule1);
372 instanceProperty1.setRules(rules);
374 instanceIdToValue.put("node1", instanceProperty1);
376 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
377 instanceProperty2.setValue("v1node2");
379 List<PropertyRule> rules3 = new ArrayList<>();
380 PropertyRule propertyRule3 = new PropertyRule();
381 String[] ruleArr3 = { "node2", "node3" };
382 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
383 propertyRule3.setRule(rule3);
384 propertyRule3.setValue("77");
385 rules3.add(propertyRule3);
387 instanceProperty2.setRules(rules3);
388 instanceIdToValue.put("node2", instanceProperty2);
390 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
391 instanceProperty3.setValue("v1node3");
392 instanceIdToValue.put("node3", instanceProperty3);
394 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
396 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
397 assertEquals("check default value", propertyRule3.getValue(), instanceProperty.getDefaultValue());
402 public void findPropertyValueBestMatchDefaultValueNotChanged() {
404 String propertyUniqueId = "x1";
405 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
406 instanceProperty.setValue("v1");
407 instanceProperty.setDefaultValue("vv1");
408 List<String> path = new ArrayList<>();
412 instanceProperty.setPath(path);
414 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
415 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
416 instanceProperty1.setValue("v1node1");
418 List<PropertyRule> rules = new ArrayList<>();
419 PropertyRule propertyRule1 = new PropertyRule();
420 String[] ruleArr1 = { "node1", "node2", ".+" };
421 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
422 propertyRule1.setRule(rule1);
423 propertyRule1.setValue("88");
425 PropertyRule propertyRule2 = new PropertyRule();
426 String[] ruleArr2 = { "node1", "node2", "node3" };
427 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
428 propertyRule2.setRule(rule2);
429 propertyRule2.setValue("99");
431 rules.add(propertyRule2);
432 rules.add(propertyRule1);
434 instanceProperty1.setRules(rules);
436 instanceIdToValue.put("node1", instanceProperty1);
438 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
439 instanceProperty2.setValue("v1node2");
441 List<PropertyRule> rules3 = new ArrayList<>();
442 PropertyRule propertyRule3 = new PropertyRule();
443 String[] ruleArr3 = { "node2", "node333" };
444 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
445 propertyRule3.setRule(rule3);
446 propertyRule3.setValue("77");
447 rules3.add(propertyRule3);
449 instanceProperty2.setRules(rules3);
450 instanceIdToValue.put("node2", instanceProperty2);
452 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
454 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
455 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
459 private PropertyOperation createTestSubject() {
460 final var propertyOperation = new PropertyOperation(new HealingJanusGraphGenericDao(new JanusGraphClient()), null);
461 propertyOperation.setDataTypeOperation(dataTypeOperation);
462 return propertyOperation;
466 public void testConvertPropertyDataToPropertyDefinition() throws Exception {
467 PropertyOperation testSubject;
468 PropertyData propertyDataResult = new PropertyData();
469 String propertyName = "";
470 String resourceId = "";
471 PropertyDefinition result;
474 testSubject = createTestSubject();
475 result = testSubject.convertPropertyDataToPropertyDefinition(propertyDataResult, propertyName, resourceId);
479 public void testAddProperty() throws Exception {
480 PropertyOperation testSubject;
481 String propertyName = "";
482 PropertyDefinition propertyDefinition = new PropertyDefinition();
483 String resourceId = "";
484 Either<PropertyData, StorageOperationStatus> result;
487 testSubject = createTestSubject();
488 result = testSubject.addProperty(propertyName, propertyDefinition, resourceId);
493 public void testValidateAndUpdateProperty() throws Exception {
494 PropertyOperation testSubject;
495 IComplexDefaultValue propertyDefinition = new PropertyDefinition();
496 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
497 dataTypes.put("", new DataTypeDefinition());
498 StorageOperationStatus result;
501 testSubject = createTestSubject();
502 result = testSubject.validateAndUpdateProperty(propertyDefinition, dataTypes);
507 public void testAddPropertyToGraph() throws Exception {
508 PropertyOperation testSubject;
509 String propertyName = "";
510 PropertyDefinition propertyDefinition = new PropertyDefinition();
511 String resourceId = "";
512 Either<PropertyData, JanusGraphOperationStatus> result;
515 testSubject = createTestSubject();
516 result = testSubject.addPropertyToGraph(propertyName, propertyDefinition, resourceId);
521 public void testAddPropertyToGraphByVertex() throws Exception {
522 PropertyOperation testSubject;
523 JanusGraphVertex metadataVertex = null;
524 String propertyName = "";
525 PropertyDefinition propertyDefinition = new PropertyDefinition();
526 String resourceId = "";
527 JanusGraphOperationStatus result;
530 testSubject = createTestSubject();
531 result = testSubject.addPropertyToGraphByVertex(metadataVertex, propertyName, propertyDefinition, resourceId);
536 public void testGetJanusGraphGenericDao() throws Exception {
537 PropertyOperation testSubject;
538 JanusGraphGenericDao result;
541 testSubject = createTestSubject();
542 result = testSubject.getJanusGraphGenericDao();
546 public void testDeletePropertyFromGraph() throws Exception {
547 PropertyOperation testSubject;
548 String propertyId = "";
549 Either<PropertyData, JanusGraphOperationStatus> result;
552 testSubject = createTestSubject();
553 result = testSubject.deletePropertyFromGraph(propertyId);
558 public void testUpdateProperty() throws Exception {
559 PropertyOperation testSubject;
560 String propertyId = "";
561 PropertyDefinition newPropertyDefinition = new PropertyDefinition();
562 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
563 Either<PropertyData, StorageOperationStatus> result;
566 testSubject = createTestSubject();
567 result = testSubject.updateProperty(propertyId, newPropertyDefinition, dataTypes);
572 public void testUpdatePropertyFromGraph() throws Exception {
573 PropertyOperation testSubject;
574 String propertyId = "";
575 PropertyDefinition propertyDefinition = null;
576 Either<PropertyData, JanusGraphOperationStatus> result;
579 testSubject = createTestSubject();
580 result = testSubject.updatePropertyFromGraph(propertyId, propertyDefinition);
585 public void testSetJanusGraphGenericDao() {
587 PropertyOperation testSubject;
588 HealingJanusGraphGenericDao janusGraphGenericDao = null;
591 testSubject = createTestSubject();
592 testSubject.setJanusGraphGenericDao(janusGraphGenericDao);
597 public void testAddPropertyToNodeType() {
598 PropertyOperation testSubject;
599 String propertyName = "";
600 PropertyDefinition propertyDefinition = new PropertyDefinition();
601 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
602 String uniqueId = "";
603 Either<PropertyData, JanusGraphOperationStatus> result;
606 testSubject = createTestSubject();
607 result = testSubject.addPropertyToNodeType(propertyName, propertyDefinition, nodeType, uniqueId);
612 public void testFindPropertiesOfNode() throws Exception {
613 PropertyOperation testSubject;
614 NodeTypeEnum nodeType = null;
615 String uniqueId = "";
616 Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result;
619 testSubject = createTestSubject();
620 result = testSubject.findPropertiesOfNode(nodeType, uniqueId);
625 public void testDeletePropertiesAssociatedToNode() throws Exception {
626 PropertyOperation testSubject;
627 NodeTypeEnum nodeType = null;
628 String uniqueId = "";
629 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
632 testSubject = createTestSubject();
633 result = testSubject.deletePropertiesAssociatedToNode(nodeType, uniqueId);
638 public void testDeleteAllPropertiesAssociatedToNode() throws Exception {
639 PropertyOperation testSubject;
640 NodeTypeEnum nodeType = null;
641 String uniqueId = "";
642 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
645 testSubject = createTestSubject();
646 result = testSubject.deleteAllPropertiesAssociatedToNode(nodeType, uniqueId);
651 public void testIsPropertyExist() throws Exception {
652 PropertyOperation testSubject;
653 List<PropertyDefinition> properties = null;
654 String resourceUid = "";
655 String propertyName = "";
656 String propertyType = "";
660 testSubject = createTestSubject();
661 result = testSubject.isPropertyExist(properties, resourceUid, propertyName, propertyType);
666 public void testValidateAndUpdateRules() throws Exception {
667 PropertyOperation testSubject;
668 String propertyType = "";
669 List<PropertyRule> rules = null;
670 String innerType = "";
671 Map<String, DataTypeDefinition> dataTypes = null;
672 boolean isValidate = false;
673 ImmutablePair<String, Boolean> result;
676 testSubject = createTestSubject();
678 result = testSubject.validateAndUpdateRules(propertyType, rules, innerType, dataTypes, isValidate);
683 public void testAddRulesToNewPropertyValue() throws Exception {
684 PropertyOperation testSubject;
685 PropertyValueData propertyValueData = new PropertyValueData();
686 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
687 String resourceInstanceId = "";
690 testSubject = createTestSubject();
691 testSubject.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
696 public void testFindPropertyValue() throws Exception {
697 PropertyOperation testSubject;
698 String resourceInstanceId = "";
699 String propertyId = "";
700 ImmutablePair<JanusGraphOperationStatus, String> result;
703 testSubject = createTestSubject();
704 result = testSubject.findPropertyValue(resourceInstanceId, propertyId);
709 public void testUpdateRulesInPropertyValue() throws Exception {
710 PropertyOperation testSubject;
711 PropertyValueData propertyValueData = new PropertyValueData();
712 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
713 String resourceInstanceId = "";
716 testSubject = createTestSubject();
717 testSubject.updateRulesInPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
722 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId() throws Exception {
723 PropertyOperation testSubject;
724 String resourceInstanceUid = "";
725 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
728 testSubject = createTestSubject();
729 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid);
734 public void testRemovePropertyOfResourceInstance() throws Exception {
735 PropertyOperation testSubject;
736 String propertyValueUid = "";
737 String resourceInstanceId = "";
738 Either<PropertyValueData, JanusGraphOperationStatus> result;
741 testSubject = createTestSubject();
742 result = testSubject.removePropertyOfResourceInstance(propertyValueUid, resourceInstanceId);
747 public void testRemovePropertyValueFromResourceInstance() throws Exception {
748 PropertyOperation testSubject;
749 String propertyValueUid = "";
750 String resourceInstanceId = "";
751 boolean inTransaction = false;
752 Either<ComponentInstanceProperty, StorageOperationStatus> result;
755 testSubject = createTestSubject();
756 result = testSubject.removePropertyValueFromResourceInstance(propertyValueUid, resourceInstanceId,
762 public void testBuildResourceInstanceProperty() throws Exception {
763 PropertyOperation testSubject;
764 PropertyValueData propertyValueData = new PropertyValueData();
765 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
766 ComponentInstanceProperty result;
769 testSubject = createTestSubject();
770 result = testSubject.buildResourceInstanceProperty(propertyValueData, resourceInstanceProperty);
775 public void testIsPropertyDefaultValueValid() throws Exception {
776 PropertyOperation testSubject;
777 IComplexDefaultValue propertyDefinition = null;
778 Map<String, DataTypeDefinition> dataTypes = null;
782 testSubject = createTestSubject();
783 propertyDefinition = null;
784 result = testSubject.isPropertyDefaultValueValid(propertyDefinition, dataTypes);
785 Assert.assertEquals(false, result);
790 public void testIsPropertyTypeValid() throws Exception {
791 PropertyOperation testSubject;
792 IComplexDefaultValue property = null;
796 testSubject = createTestSubject();
798 result = testSubject.isPropertyTypeValid(property, (String)null);
799 Assert.assertEquals(false, result);
804 public void testIsPropertyInnerTypeValid() throws Exception {
805 PropertyOperation testSubject;
806 IComplexDefaultValue property = null;
807 Map<String, DataTypeDefinition> dataTypes = null;
808 ImmutablePair<String, Boolean> result;
811 testSubject = createTestSubject();
813 result = testSubject.isPropertyInnerTypeValid(property, dataTypes);
818 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId_1() throws Exception {
819 PropertyOperation testSubject;
820 String resourceInstanceUid = "";
821 NodeTypeEnum instanceNodeType = null;
822 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
825 testSubject = createTestSubject();
826 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid, instanceNodeType);
831 public void testFindDefaultValueFromSecondPosition() throws Exception {
832 PropertyOperation testSubject;
833 List<String> pathOfComponentInstances = null;
834 String propertyUniqueId = "";
835 String defaultValue = "";
836 Either<String, JanusGraphOperationStatus> result;
839 testSubject = createTestSubject();
840 pathOfComponentInstances = null;
841 result = testSubject.findDefaultValueFromSecondPosition(pathOfComponentInstances, propertyUniqueId,
847 public void testUpdatePropertyByBestMatch() throws Exception {
848 PropertyOperation testSubject;
849 String propertyUniqueId = "";
850 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
851 List<String> path = new ArrayList<>();
853 instanceProperty.setPath(path);
854 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
855 instanceIdToValue.put("123", instanceProperty);
858 testSubject = createTestSubject();
859 testSubject.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
864 public void testGetDataTypeByUid() throws Exception {
865 PropertyOperation testSubject;
866 String uniqueId = "";
867 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
870 testSubject = createTestSubject();
871 result = testSubject.getDataTypeByUid(uniqueId);
876 public void testAddAndGetDataType() throws Exception {
877 final String dataTypeName = "myDataType";
878 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
879 dataTypeDefinition.setName("myDataType");
880 Either<DataTypeDefinition, StorageOperationStatus> result;
882 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
883 .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
885 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
886 .getNode(GraphPropertiesDictionary.NAME.getProperty(), dataTypeName, DataTypeData.class, null);
888 Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
889 .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
891 result = propertyOperation.addDataType(dataTypeDefinition);
892 assertTrue(result.isLeft());
894 Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
895 .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
897 result = propertyOperation.getDataTypeByName(dataTypeName, null, false);
898 assertTrue(result.isLeft());
900 result = propertyOperation.getDataTypeByName(dataTypeName, null);
901 assertTrue(result.isLeft());
903 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
904 .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), dataTypeName + ".datatype", DataTypeData.class);
906 Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("myDataType.datatype");
907 assertTrue(resultGetByUid.isLeft());
909 Either<Boolean, JanusGraphOperationStatus> resultIsDefinedDataType = propertyOperation.isDefinedInDataTypes(dataTypeName, null);
910 assertTrue(resultIsDefinedDataType.isLeft());
914 public void testAddDataTypeToModel() throws Exception {
915 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
916 dataTypeDefinition.setName("testName");
917 dataTypeDefinition.setModel("testModel");
918 Either<DataTypeDefinition, StorageOperationStatus> result;
920 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
921 .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
923 Mockito.doReturn(Either.left(new GraphRelation())).when(janusGraphGenericDao)
924 .createRelation(Mockito.any(), Mockito.any(), Mockito.eq(GraphEdgeLabels.MODEL_ELEMENT), Mockito.any());
926 result = propertyOperation.addDataType(dataTypeDefinition);
927 assertTrue(result.isLeft());
929 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
930 .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "testModel.testName.datatype", DataTypeData.class);
932 Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
933 .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
935 Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
936 .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
938 Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("testModel.testName.datatype");
939 assertTrue(resultGetByUid.isLeft());
944 public void testGetDataTypeByUidWithoutDerivedDataTypes() throws Exception {
945 PropertyOperation testSubject;
946 String uniqueId = "";
947 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
950 testSubject = createTestSubject();
951 result = testSubject.getDataTypeByUidWithoutDerivedDataTypes(uniqueId);
956 public void testGetAllDataTypes() throws Exception {
957 PropertyOperation testSubject;
958 Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> result;
961 testSubject = createTestSubject();
962 result = testSubject.getAllDataTypes();
967 public void testCheckInnerType() throws Exception {
968 PropertyOperation testSubject;
969 PropertyDataDefinition propDataDef = new PropertyDataDefinition();
970 Either<String, JanusGraphOperationStatus> result;
973 testSubject = createTestSubject();
974 result = testSubject.checkInnerType(propDataDef);
978 public void testValidateAndUpdatePropertyValue() throws Exception {
979 PropertyOperation testSubject;
980 String propertyType = "";
982 boolean isValidate = false;
983 String innerType = "";
984 Map<String, DataTypeDefinition> dataTypes = null;
985 Either<Object, Boolean> result;
988 testSubject = createTestSubject();
989 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, isValidate, innerType, dataTypes);
994 public void testValidateAndUpdatePropertyValue_1() throws Exception {
995 PropertyOperation testSubject;
996 String propertyType = "";
998 String innerType = "";
999 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
1000 dataTypes.put("", new DataTypeDefinition());
1001 Either<Object, Boolean> result;
1004 testSubject = createTestSubject();
1005 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, innerType, dataTypes);
1013 public void testAddPropertiesToElementType() throws Exception {
1014 PropertyOperation testSubject;
1015 String uniqueId = "";
1016 NodeTypeEnum elementType = null;
1017 List<PropertyDefinition> properties = null;
1018 Either<Map<String, PropertyData>, JanusGraphOperationStatus> result;
1021 testSubject = createTestSubject();
1023 result = testSubject.addPropertiesToElementType(uniqueId, elementType, properties);
1028 public void testUpdateDataType() throws Exception {
1029 PropertyOperation testSubject;
1030 DataTypeDefinition newDataTypeDefinition = new DataTypeDefinition();
1031 DataTypeDefinition oldDataTypeDefinition = new DataTypeDefinition();
1032 Either<DataTypeDefinition, StorageOperationStatus> result;
1035 testSubject = createTestSubject();
1036 result = testSubject.updateDataType(newDataTypeDefinition, oldDataTypeDefinition);