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 org.janusgraph.core.JanusGraphVertex;
24 import fj.data.Either;
25 import org.apache.commons.lang3.tuple.ImmutablePair;
26 import org.junit.Assert;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.mockito.Mockito;
30 import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
31 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
32 import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
33 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
34 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
35 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
36 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
37 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
38 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
40 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
41 import org.openecomp.sdc.be.model.*;
42 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
43 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
44 import org.openecomp.sdc.be.model.tosca.ToscaType;
45 import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
46 import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
47 import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
48 import org.openecomp.sdc.be.resources.data.DataTypeData;
49 import org.openecomp.sdc.be.resources.data.PropertyData;
50 import org.openecomp.sdc.be.resources.data.PropertyValueData;
53 import static org.junit.Assert.*;
54 import static org.mockito.Mockito.mock;
56 public class PropertyOperationTest extends ModelTestBase {
58 HealingJanusGraphGenericDao janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
60 PropertyOperation propertyOperation = new PropertyOperation(janusGraphGenericDao, null);
64 propertyOperation.setJanusGraphGenericDao(janusGraphGenericDao);
68 private PropertyDefinition buildPropertyDefinition() {
69 PropertyDefinition property = new PropertyDefinition();
70 property.setDefaultValue("10");
71 property.setDescription("Size of the local disk, in Gigabytes (GB), available to applications running on the Compute node.");
72 property.setType(ToscaType.INTEGER.name().toLowerCase());
77 public void convertConstraintsTest() {
79 List<PropertyConstraint> constraints = buildConstraints();
80 List<String> convertedStringConstraints = propertyOperation.convertConstraintsToString(constraints);
81 assertEquals("constraints size", constraints.size(), convertedStringConstraints.size());
83 List<PropertyConstraint> convertedConstraints = propertyOperation.convertConstraints(convertedStringConstraints);
84 assertEquals("check size of constraints", constraints.size(), convertedConstraints.size());
86 Set<String> constraintsClasses = new HashSet<>();
87 for (PropertyConstraint propertyConstraint : constraints) {
88 constraintsClasses.add(propertyConstraint.getClass().getName());
91 for (PropertyConstraint propertyConstraint : convertedConstraints) {
92 assertTrue("check all classes generated", constraintsClasses.contains(propertyConstraint.getClass().getName()));
97 public void testIsPropertyDefaultValueValid_NoDefault() {
98 PropertyDefinition property = new PropertyDefinition();
99 property.setName("myProperty");
100 property.setType(ToscaPropertyType.BOOLEAN.getType());
101 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
105 public void testIsPropertyDefaultValueValid_ValidDefault() {
106 PropertyDefinition property = new PropertyDefinition();
107 property.setName("myProperty");
108 property.setType(ToscaPropertyType.INTEGER.getType());
109 property.setDefaultValue("50");
110 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
114 public void testIsPropertyDefaultValueValid_InvalidDefault() {
115 PropertyDefinition property = new PropertyDefinition();
116 property.setName("myProperty");
117 property.setType(ToscaPropertyType.BOOLEAN.getType());
118 property.setDefaultValue("50");
119 assertFalse(propertyOperation.isPropertyDefaultValueValid(property, null));
122 private List<PropertyConstraint> buildConstraints() {
123 List<PropertyConstraint> constraints = new ArrayList<>();
124 GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0");
125 LessOrEqualConstraint propertyConstraint2 = new LessOrEqualConstraint("10");
126 List<String> range = new ArrayList<>();
129 InRangeConstraint propertyConstraint3 = new InRangeConstraint(range);
130 constraints.add(propertyConstraint1);
131 constraints.add(propertyConstraint2);
132 constraints.add(propertyConstraint3);
137 public void findPropertyValueBestMatch1() {
139 String propertyUniqueId = "x1";
140 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
141 instanceProperty.setValue("v1");
142 instanceProperty.setDefaultValue("vv1");
143 List<String> path = new ArrayList<>();
147 instanceProperty.setPath(path);
149 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
150 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
151 instanceProperty1.setValue("v1node1");
152 instanceIdToValue.put("node1", instanceProperty1);
154 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
155 instanceProperty2.setValue("v1node2");
156 instanceIdToValue.put("node2", instanceProperty2);
158 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
159 instanceProperty3.setValue("v1node3");
160 instanceIdToValue.put("node3", instanceProperty3);
162 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
164 assertEquals("check value", "v1node1", instanceProperty.getValue());
165 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
170 public void findPropertyValueBestMatch2() {
172 String propertyUniqueId = "x1";
173 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
174 instanceProperty.setValue("v1");
175 instanceProperty.setDefaultValue("vv1");
176 List<String> path = new ArrayList<>();
180 instanceProperty.setPath(path);
182 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
184 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
185 instanceProperty2.setValue("v1node2");
186 instanceProperty2.setValueUniqueUid("aaaa");
187 instanceIdToValue.put("node2", instanceProperty2);
189 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
191 assertEquals("check value", "v1node2", instanceProperty.getValue());
192 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
193 assertNull("check value unique id is null", instanceProperty.getValueUniqueUid());
198 public void findPropertyValueBestMatch3() {
200 String propertyUniqueId = "x1";
201 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
202 instanceProperty.setValue("v1");
203 instanceProperty.setDefaultValue("vv1");
204 List<String> path = new ArrayList<>();
208 instanceProperty.setPath(path);
210 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
211 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
212 instanceProperty1.setValue("v1node1");
213 instanceProperty1.setValueUniqueUid("aaaa");
214 instanceIdToValue.put("node1", instanceProperty1);
216 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
217 instanceProperty3.setValue("v1node3");
218 instanceIdToValue.put("node3", instanceProperty3);
220 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
222 assertEquals("check value", "v1node1", instanceProperty.getValue());
223 assertEquals("check default value", "v1node3", instanceProperty.getDefaultValue());
224 assertEquals("check valid unique id", instanceProperty1.getValueUniqueUid(), instanceProperty.getValueUniqueUid());
229 public void findPropertyValueBestMatch1Rules() {
231 String propertyUniqueId = "x1";
232 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
233 instanceProperty.setValue("v1");
234 instanceProperty.setDefaultValue("vv1");
235 List<String> path = new ArrayList<>();
239 instanceProperty.setPath(path);
241 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
242 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
243 instanceProperty1.setValue("v1node1");
245 List<PropertyRule> rules = new ArrayList<>();
246 PropertyRule propertyRule = new PropertyRule();
247 String[] ruleArr = { "node1", ".+", "node3" };
248 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr));
249 propertyRule.setRule(rule1);
250 propertyRule.setValue("88");
251 rules.add(propertyRule);
252 instanceProperty1.setRules(rules);
254 instanceIdToValue.put("node1", instanceProperty1);
256 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
257 instanceProperty2.setValue("v1node2");
258 instanceIdToValue.put("node2", instanceProperty2);
260 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
261 instanceProperty3.setValue("v1node3");
262 instanceIdToValue.put("node3", instanceProperty3);
264 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
266 assertEquals("check value", propertyRule.getValue(), instanceProperty.getValue());
267 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
272 public void findPropertyValueBestMatch2Rules() {
274 String propertyUniqueId = "x1";
275 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
276 instanceProperty.setValue("v1");
277 instanceProperty.setDefaultValue("vv1");
278 List<String> path = new ArrayList<>();
282 instanceProperty.setPath(path);
284 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
285 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
286 instanceProperty1.setValue("v1node1");
288 List<PropertyRule> rules = new ArrayList<>();
289 PropertyRule propertyRule1 = new PropertyRule();
290 String[] ruleArr1 = { "node1", "node2", ".+" };
291 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
292 propertyRule1.setRule(rule1);
293 propertyRule1.setValue("88");
295 PropertyRule propertyRule2 = new PropertyRule();
296 String[] ruleArr2 = { "node1", "node2", "node3" };
297 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
298 propertyRule2.setRule(rule2);
299 propertyRule2.setValue("99");
301 rules.add(propertyRule2);
302 rules.add(propertyRule1);
304 instanceProperty1.setRules(rules);
306 instanceIdToValue.put("node1", instanceProperty1);
308 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
309 instanceProperty2.setValue("v1node2");
310 instanceIdToValue.put("node2", instanceProperty2);
312 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
313 instanceProperty3.setValue("v1node3");
314 instanceIdToValue.put("node3", instanceProperty3);
316 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
318 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
319 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
324 public void findPropertyValueBestMatch1RuleLowLevel() {
326 String propertyUniqueId = "x1";
327 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
328 instanceProperty.setValue("v1");
329 instanceProperty.setDefaultValue("vv1");
330 List<String> path = new ArrayList<>();
334 instanceProperty.setPath(path);
336 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
337 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
338 instanceProperty1.setValue("v1node1");
340 List<PropertyRule> rules = new ArrayList<>();
341 PropertyRule propertyRule1 = new PropertyRule();
342 String[] ruleArr1 = { "node1", "node2", ".+" };
343 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
344 propertyRule1.setRule(rule1);
345 propertyRule1.setValue("88");
347 PropertyRule propertyRule2 = new PropertyRule();
348 String[] ruleArr2 = { "node1", "node2", "node3" };
349 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
350 propertyRule2.setRule(rule2);
351 propertyRule2.setValue("99");
353 rules.add(propertyRule2);
354 rules.add(propertyRule1);
356 instanceProperty1.setRules(rules);
358 instanceIdToValue.put("node1", instanceProperty1);
360 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
361 instanceProperty2.setValue("v1node2");
363 List<PropertyRule> rules3 = new ArrayList<>();
364 PropertyRule propertyRule3 = new PropertyRule();
365 String[] ruleArr3 = { "node2", "node3" };
366 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
367 propertyRule3.setRule(rule3);
368 propertyRule3.setValue("77");
369 rules3.add(propertyRule3);
371 instanceProperty2.setRules(rules3);
372 instanceIdToValue.put("node2", instanceProperty2);
374 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
375 instanceProperty3.setValue("v1node3");
376 instanceIdToValue.put("node3", instanceProperty3);
378 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
380 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
381 assertEquals("check default value", propertyRule3.getValue(), instanceProperty.getDefaultValue());
386 public void findPropertyValueBestMatchDefaultValueNotChanged() {
388 String propertyUniqueId = "x1";
389 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
390 instanceProperty.setValue("v1");
391 instanceProperty.setDefaultValue("vv1");
392 List<String> path = new ArrayList<>();
396 instanceProperty.setPath(path);
398 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
399 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
400 instanceProperty1.setValue("v1node1");
402 List<PropertyRule> rules = new ArrayList<>();
403 PropertyRule propertyRule1 = new PropertyRule();
404 String[] ruleArr1 = { "node1", "node2", ".+" };
405 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
406 propertyRule1.setRule(rule1);
407 propertyRule1.setValue("88");
409 PropertyRule propertyRule2 = new PropertyRule();
410 String[] ruleArr2 = { "node1", "node2", "node3" };
411 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
412 propertyRule2.setRule(rule2);
413 propertyRule2.setValue("99");
415 rules.add(propertyRule2);
416 rules.add(propertyRule1);
418 instanceProperty1.setRules(rules);
420 instanceIdToValue.put("node1", instanceProperty1);
422 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
423 instanceProperty2.setValue("v1node2");
425 List<PropertyRule> rules3 = new ArrayList<>();
426 PropertyRule propertyRule3 = new PropertyRule();
427 String[] ruleArr3 = { "node2", "node333" };
428 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
429 propertyRule3.setRule(rule3);
430 propertyRule3.setValue("77");
431 rules3.add(propertyRule3);
433 instanceProperty2.setRules(rules3);
434 instanceIdToValue.put("node2", instanceProperty2);
436 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
438 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
439 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
443 private PropertyOperation createTestSubject() {
444 return new PropertyOperation(new HealingJanusGraphGenericDao(new JanusGraphClient()), null);
448 public void testConvertPropertyDataToPropertyDefinition() throws Exception {
449 PropertyOperation testSubject;
450 PropertyData propertyDataResult = new PropertyData();
451 String propertyName = "";
452 String resourceId = "";
453 PropertyDefinition result;
456 testSubject = createTestSubject();
457 result = testSubject.convertPropertyDataToPropertyDefinition(propertyDataResult, propertyName, resourceId);
461 public void testAddProperty() throws Exception {
462 PropertyOperation testSubject;
463 String propertyName = "";
464 PropertyDefinition propertyDefinition = new PropertyDefinition();
465 String resourceId = "";
466 Either<PropertyData, StorageOperationStatus> result;
469 testSubject = createTestSubject();
470 result = testSubject.addProperty(propertyName, propertyDefinition, resourceId);
475 public void testValidateAndUpdateProperty() throws Exception {
476 PropertyOperation testSubject;
477 IComplexDefaultValue propertyDefinition = new PropertyDefinition();
478 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
479 dataTypes.put("", new DataTypeDefinition());
480 StorageOperationStatus result;
483 testSubject = createTestSubject();
484 result = testSubject.validateAndUpdateProperty(propertyDefinition, dataTypes);
489 public void testAddPropertyToGraph() throws Exception {
490 PropertyOperation testSubject;
491 String propertyName = "";
492 PropertyDefinition propertyDefinition = new PropertyDefinition();
493 String resourceId = "";
494 Either<PropertyData, JanusGraphOperationStatus> result;
497 testSubject = createTestSubject();
498 result = testSubject.addPropertyToGraph(propertyName, propertyDefinition, resourceId);
503 public void testAddPropertyToGraphByVertex() throws Exception {
504 PropertyOperation testSubject;
505 JanusGraphVertex metadataVertex = null;
506 String propertyName = "";
507 PropertyDefinition propertyDefinition = new PropertyDefinition();
508 String resourceId = "";
509 JanusGraphOperationStatus result;
512 testSubject = createTestSubject();
513 result = testSubject.addPropertyToGraphByVertex(metadataVertex, propertyName, propertyDefinition, resourceId);
518 public void testGetJanusGraphGenericDao() throws Exception {
519 PropertyOperation testSubject;
520 JanusGraphGenericDao result;
523 testSubject = createTestSubject();
524 result = testSubject.getJanusGraphGenericDao();
528 public void testDeletePropertyFromGraph() throws Exception {
529 PropertyOperation testSubject;
530 String propertyId = "";
531 Either<PropertyData, JanusGraphOperationStatus> result;
534 testSubject = createTestSubject();
535 result = testSubject.deletePropertyFromGraph(propertyId);
540 public void testUpdateProperty() throws Exception {
541 PropertyOperation testSubject;
542 String propertyId = "";
543 PropertyDefinition newPropertyDefinition = new PropertyDefinition();
544 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
545 Either<PropertyData, StorageOperationStatus> result;
548 testSubject = createTestSubject();
549 result = testSubject.updateProperty(propertyId, newPropertyDefinition, dataTypes);
554 public void testUpdatePropertyFromGraph() throws Exception {
555 PropertyOperation testSubject;
556 String propertyId = "";
557 PropertyDefinition propertyDefinition = null;
558 Either<PropertyData, JanusGraphOperationStatus> result;
561 testSubject = createTestSubject();
562 result = testSubject.updatePropertyFromGraph(propertyId, propertyDefinition);
567 public void testSetJanusGraphGenericDao() {
569 PropertyOperation testSubject;
570 HealingJanusGraphGenericDao janusGraphGenericDao = null;
573 testSubject = createTestSubject();
574 testSubject.setJanusGraphGenericDao(janusGraphGenericDao);
579 public void testAddPropertyToNodeType() {
580 PropertyOperation testSubject;
581 String propertyName = "";
582 PropertyDefinition propertyDefinition = new PropertyDefinition();
583 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
584 String uniqueId = "";
585 Either<PropertyData, JanusGraphOperationStatus> result;
588 testSubject = createTestSubject();
589 result = testSubject.addPropertyToNodeType(propertyName, propertyDefinition, nodeType, uniqueId);
594 public void testFindPropertiesOfNode() throws Exception {
595 PropertyOperation testSubject;
596 NodeTypeEnum nodeType = null;
597 String uniqueId = "";
598 Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result;
601 testSubject = createTestSubject();
602 result = testSubject.findPropertiesOfNode(nodeType, uniqueId);
607 public void testDeletePropertiesAssociatedToNode() throws Exception {
608 PropertyOperation testSubject;
609 NodeTypeEnum nodeType = null;
610 String uniqueId = "";
611 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
614 testSubject = createTestSubject();
615 result = testSubject.deletePropertiesAssociatedToNode(nodeType, uniqueId);
620 public void testDeleteAllPropertiesAssociatedToNode() throws Exception {
621 PropertyOperation testSubject;
622 NodeTypeEnum nodeType = null;
623 String uniqueId = "";
624 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
627 testSubject = createTestSubject();
628 result = testSubject.deleteAllPropertiesAssociatedToNode(nodeType, uniqueId);
633 public void testIsPropertyExist() throws Exception {
634 PropertyOperation testSubject;
635 List<PropertyDefinition> properties = null;
636 String resourceUid = "";
637 String propertyName = "";
638 String propertyType = "";
642 testSubject = createTestSubject();
643 result = testSubject.isPropertyExist(properties, resourceUid, propertyName, propertyType);
648 public void testValidateAndUpdateRules() throws Exception {
649 PropertyOperation testSubject;
650 String propertyType = "";
651 List<PropertyRule> rules = null;
652 String innerType = "";
653 Map<String, DataTypeDefinition> dataTypes = null;
654 boolean isValidate = false;
655 ImmutablePair<String, Boolean> result;
658 testSubject = createTestSubject();
660 result = testSubject.validateAndUpdateRules(propertyType, rules, innerType, dataTypes, isValidate);
665 public void testAddRulesToNewPropertyValue() throws Exception {
666 PropertyOperation testSubject;
667 PropertyValueData propertyValueData = new PropertyValueData();
668 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
669 String resourceInstanceId = "";
672 testSubject = createTestSubject();
673 testSubject.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
678 public void testFindPropertyValue() throws Exception {
679 PropertyOperation testSubject;
680 String resourceInstanceId = "";
681 String propertyId = "";
682 ImmutablePair<JanusGraphOperationStatus, String> result;
685 testSubject = createTestSubject();
686 result = testSubject.findPropertyValue(resourceInstanceId, propertyId);
691 public void testUpdateRulesInPropertyValue() throws Exception {
692 PropertyOperation testSubject;
693 PropertyValueData propertyValueData = new PropertyValueData();
694 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
695 String resourceInstanceId = "";
698 testSubject = createTestSubject();
699 testSubject.updateRulesInPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
704 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId() throws Exception {
705 PropertyOperation testSubject;
706 String resourceInstanceUid = "";
707 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
710 testSubject = createTestSubject();
711 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid);
716 public void testRemovePropertyOfResourceInstance() throws Exception {
717 PropertyOperation testSubject;
718 String propertyValueUid = "";
719 String resourceInstanceId = "";
720 Either<PropertyValueData, JanusGraphOperationStatus> result;
723 testSubject = createTestSubject();
724 result = testSubject.removePropertyOfResourceInstance(propertyValueUid, resourceInstanceId);
729 public void testRemovePropertyValueFromResourceInstance() throws Exception {
730 PropertyOperation testSubject;
731 String propertyValueUid = "";
732 String resourceInstanceId = "";
733 boolean inTransaction = false;
734 Either<ComponentInstanceProperty, StorageOperationStatus> result;
737 testSubject = createTestSubject();
738 result = testSubject.removePropertyValueFromResourceInstance(propertyValueUid, resourceInstanceId,
744 public void testBuildResourceInstanceProperty() throws Exception {
745 PropertyOperation testSubject;
746 PropertyValueData propertyValueData = new PropertyValueData();
747 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
748 ComponentInstanceProperty result;
751 testSubject = createTestSubject();
752 result = testSubject.buildResourceInstanceProperty(propertyValueData, resourceInstanceProperty);
757 public void testIsPropertyDefaultValueValid() throws Exception {
758 PropertyOperation testSubject;
759 IComplexDefaultValue propertyDefinition = null;
760 Map<String, DataTypeDefinition> dataTypes = null;
764 testSubject = createTestSubject();
765 propertyDefinition = null;
766 result = testSubject.isPropertyDefaultValueValid(propertyDefinition, dataTypes);
767 Assert.assertEquals(false, result);
772 public void testIsPropertyTypeValid() throws Exception {
773 PropertyOperation testSubject;
774 IComplexDefaultValue property = null;
778 testSubject = createTestSubject();
780 result = testSubject.isPropertyTypeValid(property, null);
781 Assert.assertEquals(false, result);
786 public void testIsPropertyInnerTypeValid() throws Exception {
787 PropertyOperation testSubject;
788 IComplexDefaultValue property = null;
789 Map<String, DataTypeDefinition> dataTypes = null;
790 ImmutablePair<String, Boolean> result;
793 testSubject = createTestSubject();
795 result = testSubject.isPropertyInnerTypeValid(property, dataTypes);
800 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId_1() throws Exception {
801 PropertyOperation testSubject;
802 String resourceInstanceUid = "";
803 NodeTypeEnum instanceNodeType = null;
804 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
807 testSubject = createTestSubject();
808 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid, instanceNodeType);
813 public void testFindDefaultValueFromSecondPosition() throws Exception {
814 PropertyOperation testSubject;
815 List<String> pathOfComponentInstances = null;
816 String propertyUniqueId = "";
817 String defaultValue = "";
818 Either<String, JanusGraphOperationStatus> result;
821 testSubject = createTestSubject();
822 pathOfComponentInstances = null;
823 result = testSubject.findDefaultValueFromSecondPosition(pathOfComponentInstances, propertyUniqueId,
829 public void testUpdatePropertyByBestMatch() throws Exception {
830 PropertyOperation testSubject;
831 String propertyUniqueId = "";
832 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
833 List<String> path = new ArrayList<>();
835 instanceProperty.setPath(path);
836 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
837 instanceIdToValue.put("123", instanceProperty);
840 testSubject = createTestSubject();
841 testSubject.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
846 public void testGetDataTypeByUid() throws Exception {
847 PropertyOperation testSubject;
848 String uniqueId = "";
849 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
852 testSubject = createTestSubject();
853 result = testSubject.getDataTypeByUid(uniqueId);
858 public void testAddAndGetDataType() throws Exception {
859 final String dataTypeName = "myDataType";
860 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
861 dataTypeDefinition.setName("myDataType");
862 Either<DataTypeDefinition, StorageOperationStatus> result;
864 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
865 .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
867 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
868 .getNode(GraphPropertiesDictionary.NAME.getProperty(), dataTypeName, DataTypeData.class, null);
870 Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
871 .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
873 result = propertyOperation.addDataType(dataTypeDefinition);
874 assertTrue(result.isLeft());
876 Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
877 .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
879 result = propertyOperation.getDataTypeByName(dataTypeName, null, false);
880 assertTrue(result.isLeft());
882 result = propertyOperation.getDataTypeByName(dataTypeName, null);
883 assertTrue(result.isLeft());
885 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
886 .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), dataTypeName + ".datatype", DataTypeData.class);
888 Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("myDataType.datatype");
889 assertTrue(resultGetByUid.isLeft());
891 Either<Boolean, JanusGraphOperationStatus> resultIsDefinedDataType = propertyOperation.isDefinedInDataTypes(dataTypeName, null);
892 assertTrue(resultIsDefinedDataType.isLeft());
896 public void testAddDataTypeToModel() throws Exception {
897 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
898 dataTypeDefinition.setName("testName");
899 dataTypeDefinition.setModel("testModel");
900 Either<DataTypeDefinition, StorageOperationStatus> result;
902 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
903 .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
905 Mockito.doReturn(Either.left(new GraphRelation())).when(janusGraphGenericDao)
906 .createRelation(Mockito.any(), Mockito.any(), Mockito.eq(GraphEdgeLabels.MODEL_ELEMENT), Mockito.any());
908 result = propertyOperation.addDataType(dataTypeDefinition);
909 assertTrue(result.isLeft());
911 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
912 .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "testModel.testName.datatype", DataTypeData.class);
914 Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
915 .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
917 Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
918 .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
920 Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("testModel.testName.datatype");
921 assertTrue(resultGetByUid.isLeft());
926 public void testGetDataTypeByUidWithoutDerivedDataTypes() throws Exception {
927 PropertyOperation testSubject;
928 String uniqueId = "";
929 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
932 testSubject = createTestSubject();
933 result = testSubject.getDataTypeByUidWithoutDerivedDataTypes(uniqueId);
938 public void testGetAllDataTypes() throws Exception {
939 PropertyOperation testSubject;
940 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> result;
943 testSubject = createTestSubject();
944 result = testSubject.getAllDataTypes();
949 public void testCheckInnerType() throws Exception {
950 PropertyOperation testSubject;
951 PropertyDataDefinition propDataDef = new PropertyDataDefinition();
952 Either<String, JanusGraphOperationStatus> result;
955 testSubject = createTestSubject();
956 result = testSubject.checkInnerType(propDataDef);
961 public void testGetAllDataTypeNodes() throws Exception {
962 PropertyOperation testSubject;
963 Either<List<DataTypeData>, JanusGraphOperationStatus> result;
966 testSubject = createTestSubject();
967 result = testSubject.getAllDataTypeNodes();
972 public void testValidateAndUpdatePropertyValue() throws Exception {
973 PropertyOperation testSubject;
974 String propertyType = "";
976 boolean isValidate = false;
977 String innerType = "";
978 Map<String, DataTypeDefinition> dataTypes = null;
979 Either<Object, Boolean> result;
982 testSubject = createTestSubject();
983 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, isValidate, innerType, dataTypes);
988 public void testValidateAndUpdatePropertyValue_1() throws Exception {
989 PropertyOperation testSubject;
990 String propertyType = "";
992 String innerType = "";
993 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
994 dataTypes.put("", new DataTypeDefinition());
995 Either<Object, Boolean> result;
998 testSubject = createTestSubject();
999 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, innerType, dataTypes);
1007 public void testAddPropertiesToElementType() throws Exception {
1008 PropertyOperation testSubject;
1009 String uniqueId = "";
1010 NodeTypeEnum elementType = null;
1011 List<PropertyDefinition> properties = null;
1012 Either<Map<String, PropertyData>, JanusGraphOperationStatus> result;
1015 testSubject = createTestSubject();
1017 result = testSubject.addPropertiesToElementType(uniqueId, elementType, properties);
1022 public void testUpdateDataType() throws Exception {
1023 PropertyOperation testSubject;
1024 DataTypeDefinition newDataTypeDefinition = new DataTypeDefinition();
1025 DataTypeDefinition oldDataTypeDefinition = new DataTypeDefinition();
1026 Either<DataTypeDefinition, StorageOperationStatus> result;
1029 testSubject = createTestSubject();
1030 result = testSubject.updateDataType(newDataTypeDefinition, oldDataTypeDefinition);