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 com.thinkaurelius.titan.core.TitanVertex;
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.titan.TitanGenericDao;
31 import org.openecomp.sdc.be.dao.titan.TitanGraphClient;
32 import org.openecomp.sdc.be.dao.titan.TitanOperationStatus;
33 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
34 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
35 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
36 import org.openecomp.sdc.be.model.*;
37 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
38 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
39 import org.openecomp.sdc.be.model.tosca.ToscaType;
40 import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
41 import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
42 import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
43 import org.openecomp.sdc.be.resources.data.DataTypeData;
44 import org.openecomp.sdc.be.resources.data.PropertyData;
45 import org.openecomp.sdc.be.resources.data.PropertyValueData;
49 import static org.junit.Assert.*;
51 public class PropertyOperationTest extends ModelTestBase {
53 TitanGenericDao titanGenericDao = Mockito.mock(TitanGenericDao.class);
55 PropertyOperation propertyOperation = new PropertyOperation(titanGenericDao, null);
59 propertyOperation.setTitanGenericDao(titanGenericDao);
64 * @Test public void addPropertyToResourceTest() {
66 * String propName = "myProp"; PropertyDefinition property = buildPropertyDefinition(); List<PropertyConstraint> constraints = buildConstraints(); property.setConstraints(constraints);
68 * PropertyData propertyData = new PropertyData(property, propertyOperation.convertConstraintsToString(constraints));
70 * Either<PropertyData, TitanOperationStatus> either = Either.left(propertyData); //when(propertyDao.create((GraphNeighbourTable)anyObject(), eq(PropertyData.class), eq(NodeTypeEnum.Property))).thenReturn(either); GraphRelation graphRelation =
71 * new GraphRelation(); Either<GraphRelation, TitanOperationStatus> relationResult = Either.left(graphRelation);
73 * when(titanGenericDao.createNode((PropertyData)anyObject(), eq(PropertyData.class))).thenReturn(either); when(titanGenericDao.createRelation((GraphNode)anyObject(), (GraphNode)anyObject(), eq(GraphEdgeLabels.PROPERTY),
74 * anyMap())).thenReturn(relationResult);
76 * Either<PropertyDefinition, StorageOperationStatus> result = propertyOperation.addPropertyToResource(propName, property, NodeTypeEnum.Resource, "my-resource.1.0");
78 * assertTrue(result.isLeft()); System.out.println(result.left().value()); PropertyDefinition propertyDefinition = result.left().value();
80 * List<PropertyConstraint> originalConstraints = property.getConstraints(); List<PropertyConstraint> propertyConstraintsResult = propertyDefinition.getConstraints(); assertEquals(propertyConstraintsResult.size(), originalConstraints.size());
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 addPropertiesToGraphTableTest() {
95 // Map<String, PropertyDefinition> properties = new HashMap<String,
96 // PropertyDefinition>();
97 // String propName = "myProp";
98 // PropertyDefinition property = buildPropertyDefinition();
100 // List<PropertyConstraint> constraints = buildConstraints();
101 // property.setConstraints(constraints);
103 // properties.put(propName, property);
105 // GraphNeighbourTable graphNeighbourTable = new GraphNeighbourTable();
106 // ResourceData resourceData = new ResourceData();
107 // String resourceName = "my-resource";
108 // String resourceVersion = "1.0";
109 // String resourceId = resourceName + "." + resourceVersion;
110 // resourceData.setUniqueId(resourceId);
111 // int resourceIndex = graphNeighbourTable.addNode(resourceData);
113 // heatParametersOperation.addPropertiesToGraphTable(properties,
114 // graphNeighbourTable, resourceIndex, resourceId);
116 // assertEquals(2, graphNeighbourTable.getNodes().size());
117 // assertEquals(1, graphNeighbourTable.getDirectedEdges().size());
118 // List<GraphNode> nodes = graphNeighbourTable.getNodes();
119 // boolean nodeFound = false;
120 // for (GraphNode neo4jNode : nodes) {
121 // if (neo4jNode instanceof PropertyData) {
122 // PropertyData propertyData = (PropertyData)neo4jNode;
123 // assertEquals("check property unique id", resourceId + "." + propName,
124 // propertyData.getUniqueId());
125 // assertEquals(property.getDescription(),
126 // propertyData.getPropertyDataDefinition().getDescription());
130 // assertEquals("looking for PropertyData object in table", true,
133 // NodeRelation nodeRelation =
134 // graphNeighbourTable.getDirectedEdges().get(0);
135 // assertEquals("check from index to index edge", 0,
136 // nodeRelation.getFromIndex());
137 // assertEquals("check from index to index edge", 1,
138 // nodeRelation.getToIndex());
139 // assertEquals("check edge type",
140 // GraphEdgePropertiesDictionary.PROPERTY,
141 // nodeRelation.getEdge().getEdgeType());
142 // assertEquals("check propert name on edge", true,
143 // nodeRelation.getEdge().getProperties().values().contains(propName));
147 public void convertConstraintsTest() {
149 List<PropertyConstraint> constraints = buildConstraints();
150 List<String> convertedStringConstraints = propertyOperation.convertConstraintsToString(constraints);
151 assertEquals("constraints size", constraints.size(), convertedStringConstraints.size());
153 List<PropertyConstraint> convertedConstraints = propertyOperation.convertConstraints(convertedStringConstraints);
154 assertEquals("check size of constraints", constraints.size(), convertedConstraints.size());
156 Set<String> constraintsClasses = new HashSet<>();
157 for (PropertyConstraint propertyConstraint : constraints) {
158 constraintsClasses.add(propertyConstraint.getClass().getName());
161 for (PropertyConstraint propertyConstraint : convertedConstraints) {
162 assertTrue("check all classes generated", constraintsClasses.contains(propertyConstraint.getClass().getName()));
167 public void testIsPropertyDefaultValueValid_NoDefault() {
168 PropertyDefinition property = new PropertyDefinition();
169 property.setName("myProperty");
170 property.setType(ToscaPropertyType.BOOLEAN.getType());
171 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
175 public void testIsPropertyDefaultValueValid_ValidDefault() {
176 PropertyDefinition property = new PropertyDefinition();
177 property.setName("myProperty");
178 property.setType(ToscaPropertyType.INTEGER.getType());
179 property.setDefaultValue("50");
180 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
184 public void testIsPropertyDefaultValueValid_InvalidDefault() {
185 PropertyDefinition property = new PropertyDefinition();
186 property.setName("myProperty");
187 property.setType(ToscaPropertyType.BOOLEAN.getType());
188 property.setDefaultValue("50");
189 assertFalse(propertyOperation.isPropertyDefaultValueValid(property, null));
192 private List<PropertyConstraint> buildConstraints() {
193 List<PropertyConstraint> constraints = new ArrayList<>();
194 GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0");
195 LessOrEqualConstraint propertyConstraint2 = new LessOrEqualConstraint("10");
196 List<String> range = new ArrayList<>();
199 InRangeConstraint propertyConstraint3 = new InRangeConstraint(range);
200 constraints.add(propertyConstraint1);
201 constraints.add(propertyConstraint2);
202 constraints.add(propertyConstraint3);
207 public void findPropertyValueBestMatch1() {
209 String propertyUniqueId = "x1";
210 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
211 instanceProperty.setValue("v1");
212 instanceProperty.setDefaultValue("vv1");
213 List<String> path = new ArrayList<>();
217 instanceProperty.setPath(path);
219 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
220 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
221 instanceProperty1.setValue("v1node1");
222 instanceIdToValue.put("node1", instanceProperty1);
224 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
225 instanceProperty2.setValue("v1node2");
226 instanceIdToValue.put("node2", instanceProperty2);
228 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
229 instanceProperty3.setValue("v1node3");
230 instanceIdToValue.put("node3", instanceProperty3);
232 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
234 assertEquals("check value", "v1node1", instanceProperty.getValue());
235 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
240 public void findPropertyValueBestMatch2() {
242 String propertyUniqueId = "x1";
243 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
244 instanceProperty.setValue("v1");
245 instanceProperty.setDefaultValue("vv1");
246 List<String> path = new ArrayList<>();
250 instanceProperty.setPath(path);
252 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
254 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
255 instanceProperty2.setValue("v1node2");
256 instanceProperty2.setValueUniqueUid("aaaa");
257 instanceIdToValue.put("node2", instanceProperty2);
259 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
261 assertEquals("check value", "v1node2", instanceProperty.getValue());
262 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
263 assertNull("check value unique id is null", instanceProperty.getValueUniqueUid());
268 public void findPropertyValueBestMatch3() {
270 String propertyUniqueId = "x1";
271 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
272 instanceProperty.setValue("v1");
273 instanceProperty.setDefaultValue("vv1");
274 List<String> path = new ArrayList<>();
278 instanceProperty.setPath(path);
280 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
281 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
282 instanceProperty1.setValue("v1node1");
283 instanceProperty1.setValueUniqueUid("aaaa");
284 instanceIdToValue.put("node1", instanceProperty1);
286 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
287 instanceProperty3.setValue("v1node3");
288 instanceIdToValue.put("node3", instanceProperty3);
290 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
292 assertEquals("check value", "v1node1", instanceProperty.getValue());
293 assertEquals("check default value", "v1node3", instanceProperty.getDefaultValue());
294 assertEquals("check valid unique id", instanceProperty1.getValueUniqueUid(), instanceProperty.getValueUniqueUid());
299 public void findPropertyValueBestMatch1Rules() {
301 String propertyUniqueId = "x1";
302 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
303 instanceProperty.setValue("v1");
304 instanceProperty.setDefaultValue("vv1");
305 List<String> path = new ArrayList<>();
309 instanceProperty.setPath(path);
311 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
312 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
313 instanceProperty1.setValue("v1node1");
315 List<PropertyRule> rules = new ArrayList<>();
316 PropertyRule propertyRule = new PropertyRule();
317 String[] ruleArr = { "node1", ".+", "node3" };
318 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr));
319 propertyRule.setRule(rule1);
320 propertyRule.setValue("88");
321 rules.add(propertyRule);
322 instanceProperty1.setRules(rules);
324 instanceIdToValue.put("node1", instanceProperty1);
326 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
327 instanceProperty2.setValue("v1node2");
328 instanceIdToValue.put("node2", instanceProperty2);
330 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
331 instanceProperty3.setValue("v1node3");
332 instanceIdToValue.put("node3", instanceProperty3);
334 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
336 assertEquals("check value", propertyRule.getValue(), instanceProperty.getValue());
337 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
342 public void findPropertyValueBestMatch2Rules() {
344 String propertyUniqueId = "x1";
345 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
346 instanceProperty.setValue("v1");
347 instanceProperty.setDefaultValue("vv1");
348 List<String> path = new ArrayList<>();
352 instanceProperty.setPath(path);
354 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
355 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
356 instanceProperty1.setValue("v1node1");
358 List<PropertyRule> rules = new ArrayList<>();
359 PropertyRule propertyRule1 = new PropertyRule();
360 String[] ruleArr1 = { "node1", "node2", ".+" };
361 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
362 propertyRule1.setRule(rule1);
363 propertyRule1.setValue("88");
365 PropertyRule propertyRule2 = new PropertyRule();
366 String[] ruleArr2 = { "node1", "node2", "node3" };
367 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
368 propertyRule2.setRule(rule2);
369 propertyRule2.setValue("99");
371 rules.add(propertyRule2);
372 rules.add(propertyRule1);
374 instanceProperty1.setRules(rules);
376 instanceIdToValue.put("node1", instanceProperty1);
378 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
379 instanceProperty2.setValue("v1node2");
380 instanceIdToValue.put("node2", instanceProperty2);
382 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
383 instanceProperty3.setValue("v1node3");
384 instanceIdToValue.put("node3", instanceProperty3);
386 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
388 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
389 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
394 public void findPropertyValueBestMatch1RuleLowLevel() {
396 String propertyUniqueId = "x1";
397 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
398 instanceProperty.setValue("v1");
399 instanceProperty.setDefaultValue("vv1");
400 List<String> path = new ArrayList<>();
404 instanceProperty.setPath(path);
406 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
407 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
408 instanceProperty1.setValue("v1node1");
410 List<PropertyRule> rules = new ArrayList<>();
411 PropertyRule propertyRule1 = new PropertyRule();
412 String[] ruleArr1 = { "node1", "node2", ".+" };
413 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
414 propertyRule1.setRule(rule1);
415 propertyRule1.setValue("88");
417 PropertyRule propertyRule2 = new PropertyRule();
418 String[] ruleArr2 = { "node1", "node2", "node3" };
419 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
420 propertyRule2.setRule(rule2);
421 propertyRule2.setValue("99");
423 rules.add(propertyRule2);
424 rules.add(propertyRule1);
426 instanceProperty1.setRules(rules);
428 instanceIdToValue.put("node1", instanceProperty1);
430 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
431 instanceProperty2.setValue("v1node2");
433 List<PropertyRule> rules3 = new ArrayList<>();
434 PropertyRule propertyRule3 = new PropertyRule();
435 String[] ruleArr3 = { "node2", "node3" };
436 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
437 propertyRule3.setRule(rule3);
438 propertyRule3.setValue("77");
439 rules3.add(propertyRule3);
441 instanceProperty2.setRules(rules3);
442 instanceIdToValue.put("node2", instanceProperty2);
444 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
445 instanceProperty3.setValue("v1node3");
446 instanceIdToValue.put("node3", instanceProperty3);
448 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
450 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
451 assertEquals("check default value", propertyRule3.getValue(), instanceProperty.getDefaultValue());
456 public void findPropertyValueBestMatchDefaultValueNotChanged() {
458 String propertyUniqueId = "x1";
459 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
460 instanceProperty.setValue("v1");
461 instanceProperty.setDefaultValue("vv1");
462 List<String> path = new ArrayList<>();
466 instanceProperty.setPath(path);
468 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
469 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
470 instanceProperty1.setValue("v1node1");
472 List<PropertyRule> rules = new ArrayList<>();
473 PropertyRule propertyRule1 = new PropertyRule();
474 String[] ruleArr1 = { "node1", "node2", ".+" };
475 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
476 propertyRule1.setRule(rule1);
477 propertyRule1.setValue("88");
479 PropertyRule propertyRule2 = new PropertyRule();
480 String[] ruleArr2 = { "node1", "node2", "node3" };
481 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
482 propertyRule2.setRule(rule2);
483 propertyRule2.setValue("99");
485 rules.add(propertyRule2);
486 rules.add(propertyRule1);
488 instanceProperty1.setRules(rules);
490 instanceIdToValue.put("node1", instanceProperty1);
492 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
493 instanceProperty2.setValue("v1node2");
495 List<PropertyRule> rules3 = new ArrayList<>();
496 PropertyRule propertyRule3 = new PropertyRule();
497 String[] ruleArr3 = { "node2", "node333" };
498 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
499 propertyRule3.setRule(rule3);
500 propertyRule3.setValue("77");
501 rules3.add(propertyRule3);
503 instanceProperty2.setRules(rules3);
504 instanceIdToValue.put("node2", instanceProperty2);
506 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
508 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
509 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
513 private PropertyOperation createTestSubject() {
514 return new PropertyOperation(new TitanGenericDao(new TitanGraphClient()), null);
519 public void testMain() throws Exception {
520 String[] args = new String[] { "" };
523 PropertyOperation.main(args);
528 public void testConvertPropertyDataToPropertyDefinition() throws Exception {
529 PropertyOperation testSubject;
530 PropertyData propertyDataResult = new PropertyData();
531 String propertyName = "";
532 String resourceId = "";
533 PropertyDefinition result;
536 testSubject = createTestSubject();
537 result = testSubject.convertPropertyDataToPropertyDefinition(propertyDataResult, propertyName, resourceId);
541 public void testAddProperty() throws Exception {
542 PropertyOperation testSubject;
543 String propertyName = "";
544 PropertyDefinition propertyDefinition = new PropertyDefinition();
545 String resourceId = "";
546 Either<PropertyData, StorageOperationStatus> result;
549 testSubject = createTestSubject();
550 result = testSubject.addProperty(propertyName, propertyDefinition, resourceId);
555 public void testValidateAndUpdateProperty() throws Exception {
556 PropertyOperation testSubject;
557 IComplexDefaultValue propertyDefinition = new PropertyDefinition();
558 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
559 dataTypes.put("", new DataTypeDefinition());
560 StorageOperationStatus result;
563 testSubject = createTestSubject();
564 result = testSubject.validateAndUpdateProperty(propertyDefinition, dataTypes);
569 public void testAddPropertyToGraph() throws Exception {
570 PropertyOperation testSubject;
571 String propertyName = "";
572 PropertyDefinition propertyDefinition = new PropertyDefinition();
573 String resourceId = "";
574 Either<PropertyData, TitanOperationStatus> result;
577 testSubject = createTestSubject();
578 result = testSubject.addPropertyToGraph(propertyName, propertyDefinition, resourceId);
583 public void testAddPropertyToGraphByVertex() throws Exception {
584 PropertyOperation testSubject;
585 TitanVertex metadataVertex = null;
586 String propertyName = "";
587 PropertyDefinition propertyDefinition = new PropertyDefinition();
588 String resourceId = "";
589 TitanOperationStatus result;
592 testSubject = createTestSubject();
593 result = testSubject.addPropertyToGraphByVertex(metadataVertex, propertyName, propertyDefinition, resourceId);
598 public void testGetTitanGenericDao() throws Exception {
599 PropertyOperation testSubject;
600 TitanGenericDao result;
603 testSubject = createTestSubject();
604 result = testSubject.getTitanGenericDao();
608 public void testDeletePropertyFromGraph() throws Exception {
609 PropertyOperation testSubject;
610 String propertyId = "";
611 Either<PropertyData, TitanOperationStatus> result;
614 testSubject = createTestSubject();
615 result = testSubject.deletePropertyFromGraph(propertyId);
620 public void testUpdateProperty() throws Exception {
621 PropertyOperation testSubject;
622 String propertyId = "";
623 PropertyDefinition newPropertyDefinition = new PropertyDefinition();
624 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
625 Either<PropertyData, StorageOperationStatus> result;
628 testSubject = createTestSubject();
629 result = testSubject.updateProperty(propertyId, newPropertyDefinition, dataTypes);
634 public void testUpdatePropertyFromGraph() throws Exception {
635 PropertyOperation testSubject;
636 String propertyId = "";
637 PropertyDefinition propertyDefinition = null;
638 Either<PropertyData, TitanOperationStatus> result;
641 testSubject = createTestSubject();
642 result = testSubject.updatePropertyFromGraph(propertyId, propertyDefinition);
647 public void testSetTitanGenericDao() throws Exception {
648 PropertyOperation testSubject;
649 TitanGenericDao titanGenericDao = null;
652 testSubject = createTestSubject();
653 testSubject.setTitanGenericDao(titanGenericDao);
658 public void testAddPropertyToNodeType() throws Exception {
659 PropertyOperation testSubject;
660 String propertyName = "";
661 PropertyDefinition propertyDefinition = new PropertyDefinition();
662 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
663 String uniqueId = "";
664 Either<PropertyData, TitanOperationStatus> result;
667 testSubject = createTestSubject();
668 result = testSubject.addPropertyToNodeType(propertyName, propertyDefinition, nodeType, uniqueId);
673 public void testFindPropertiesOfNode() throws Exception {
674 PropertyOperation testSubject;
675 NodeTypeEnum nodeType = null;
676 String uniqueId = "";
677 Either<Map<String, PropertyDefinition>, TitanOperationStatus> result;
680 testSubject = createTestSubject();
681 result = testSubject.findPropertiesOfNode(nodeType, uniqueId);
686 public void testDeletePropertiesAssociatedToNode() throws Exception {
687 PropertyOperation testSubject;
688 NodeTypeEnum nodeType = null;
689 String uniqueId = "";
690 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
693 testSubject = createTestSubject();
694 result = testSubject.deletePropertiesAssociatedToNode(nodeType, uniqueId);
699 public void testDeleteAllPropertiesAssociatedToNode() throws Exception {
700 PropertyOperation testSubject;
701 NodeTypeEnum nodeType = null;
702 String uniqueId = "";
703 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
706 testSubject = createTestSubject();
707 result = testSubject.deleteAllPropertiesAssociatedToNode(nodeType, uniqueId);
712 public void testIsPropertyExist() throws Exception {
713 PropertyOperation testSubject;
714 List<PropertyDefinition> properties = null;
715 String resourceUid = "";
716 String propertyName = "";
717 String propertyType = "";
721 testSubject = createTestSubject();
722 result = testSubject.isPropertyExist(properties, resourceUid, propertyName, propertyType);
727 public void testValidateAndUpdateRules() throws Exception {
728 PropertyOperation testSubject;
729 String propertyType = "";
730 List<PropertyRule> rules = null;
731 String innerType = "";
732 Map<String, DataTypeDefinition> dataTypes = null;
733 boolean isValidate = false;
734 ImmutablePair<String, Boolean> result;
737 testSubject = createTestSubject();
739 result = testSubject.validateAndUpdateRules(propertyType, rules, innerType, dataTypes, isValidate);
744 public void testAddRulesToNewPropertyValue() throws Exception {
745 PropertyOperation testSubject;
746 PropertyValueData propertyValueData = new PropertyValueData();
747 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
748 String resourceInstanceId = "";
751 testSubject = createTestSubject();
752 testSubject.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
757 public void testFindPropertyValue() throws Exception {
758 PropertyOperation testSubject;
759 String resourceInstanceId = "";
760 String propertyId = "";
761 ImmutablePair<TitanOperationStatus, String> result;
764 testSubject = createTestSubject();
765 result = testSubject.findPropertyValue(resourceInstanceId, propertyId);
770 public void testUpdateRulesInPropertyValue() throws Exception {
771 PropertyOperation testSubject;
772 PropertyValueData propertyValueData = new PropertyValueData();
773 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
774 String resourceInstanceId = "";
777 testSubject = createTestSubject();
778 testSubject.updateRulesInPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
783 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId() throws Exception {
784 PropertyOperation testSubject;
785 String resourceInstanceUid = "";
786 Either<List<ComponentInstanceProperty>, TitanOperationStatus> result;
789 testSubject = createTestSubject();
790 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid);
795 public void testRemovePropertyOfResourceInstance() throws Exception {
796 PropertyOperation testSubject;
797 String propertyValueUid = "";
798 String resourceInstanceId = "";
799 Either<PropertyValueData, TitanOperationStatus> result;
802 testSubject = createTestSubject();
803 result = testSubject.removePropertyOfResourceInstance(propertyValueUid, resourceInstanceId);
808 public void testRemovePropertyValueFromResourceInstance() throws Exception {
809 PropertyOperation testSubject;
810 String propertyValueUid = "";
811 String resourceInstanceId = "";
812 boolean inTransaction = false;
813 Either<ComponentInstanceProperty, StorageOperationStatus> result;
816 testSubject = createTestSubject();
817 result = testSubject.removePropertyValueFromResourceInstance(propertyValueUid, resourceInstanceId,
823 public void testBuildResourceInstanceProperty() throws Exception {
824 PropertyOperation testSubject;
825 PropertyValueData propertyValueData = new PropertyValueData();
826 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
827 ComponentInstanceProperty result;
830 testSubject = createTestSubject();
831 result = testSubject.buildResourceInstanceProperty(propertyValueData, resourceInstanceProperty);
836 public void testIsPropertyDefaultValueValid() throws Exception {
837 PropertyOperation testSubject;
838 IComplexDefaultValue propertyDefinition = null;
839 Map<String, DataTypeDefinition> dataTypes = null;
843 testSubject = createTestSubject();
844 propertyDefinition = null;
845 result = testSubject.isPropertyDefaultValueValid(propertyDefinition, dataTypes);
846 Assert.assertEquals(false, result);
851 public void testIsPropertyTypeValid() throws Exception {
852 PropertyOperation testSubject;
853 IComplexDefaultValue property = null;
857 testSubject = createTestSubject();
859 result = testSubject.isPropertyTypeValid(property);
860 Assert.assertEquals(false, result);
865 public void testIsPropertyInnerTypeValid() throws Exception {
866 PropertyOperation testSubject;
867 IComplexDefaultValue property = null;
868 Map<String, DataTypeDefinition> dataTypes = null;
869 ImmutablePair<String, Boolean> result;
872 testSubject = createTestSubject();
874 result = testSubject.isPropertyInnerTypeValid(property, dataTypes);
879 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId_1() throws Exception {
880 PropertyOperation testSubject;
881 String resourceInstanceUid = "";
882 NodeTypeEnum instanceNodeType = null;
883 Either<List<ComponentInstanceProperty>, TitanOperationStatus> result;
886 testSubject = createTestSubject();
887 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid, instanceNodeType);
892 public void testFindDefaultValueFromSecondPosition() throws Exception {
893 PropertyOperation testSubject;
894 List<String> pathOfComponentInstances = null;
895 String propertyUniqueId = "";
896 String defaultValue = "";
897 Either<String, TitanOperationStatus> result;
900 testSubject = createTestSubject();
901 pathOfComponentInstances = null;
902 result = testSubject.findDefaultValueFromSecondPosition(pathOfComponentInstances, propertyUniqueId,
908 public void testUpdatePropertyByBestMatch() throws Exception {
909 PropertyOperation testSubject;
910 String propertyUniqueId = "";
911 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
912 List<String> path = new ArrayList<>();
914 instanceProperty.setPath(path);
915 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
916 instanceIdToValue.put("123", instanceProperty);
919 testSubject = createTestSubject();
920 testSubject.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
925 public void testGetDataTypeByUid() throws Exception {
926 PropertyOperation testSubject;
927 String uniqueId = "";
928 Either<DataTypeDefinition, TitanOperationStatus> result;
931 testSubject = createTestSubject();
932 result = testSubject.getDataTypeByUid(uniqueId);
937 public void testAddDataType() throws Exception {
938 PropertyOperation testSubject;
939 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
940 Either<DataTypeDefinition, StorageOperationStatus> result;
943 testSubject = createTestSubject();
944 result = testSubject.addDataType(dataTypeDefinition);
949 public void testGetDataTypeByName() throws Exception {
950 PropertyOperation testSubject;
952 boolean inTransaction = false;
953 Either<DataTypeDefinition, StorageOperationStatus> result;
956 testSubject = createTestSubject();
957 result = testSubject.getDataTypeByName(name, inTransaction);
962 public void testGetDataTypeByName_1() throws Exception {
963 PropertyOperation testSubject;
965 Either<DataTypeDefinition, StorageOperationStatus> result;
968 testSubject = createTestSubject();
969 result = testSubject.getDataTypeByName(name);
974 public void testGetDataTypeByNameWithoutDerived() throws Exception {
975 PropertyOperation testSubject;
977 Either<DataTypeDefinition, StorageOperationStatus> result;
980 testSubject = createTestSubject();
981 result = testSubject.getDataTypeByNameWithoutDerived(name);
986 public void testGetDataTypeByUidWithoutDerivedDataTypes() throws Exception {
987 PropertyOperation testSubject;
988 String uniqueId = "";
989 Either<DataTypeDefinition, TitanOperationStatus> result;
992 testSubject = createTestSubject();
993 result = testSubject.getDataTypeByUidWithoutDerivedDataTypes(uniqueId);
998 public void testIsDefinedInDataTypes() throws Exception {
999 PropertyOperation testSubject;
1000 String propertyType = "";
1001 Either<Boolean, TitanOperationStatus> result;
1004 testSubject = createTestSubject();
1005 result = testSubject.isDefinedInDataTypes(propertyType);
1010 public void testGetAllDataTypes() throws Exception {
1011 PropertyOperation testSubject;
1012 Either<Map<String, DataTypeDefinition>, TitanOperationStatus> result;
1015 testSubject = createTestSubject();
1016 result = testSubject.getAllDataTypes();
1021 public void testCheckInnerType() throws Exception {
1022 PropertyOperation testSubject;
1023 PropertyDataDefinition propDataDef = new PropertyDataDefinition();
1024 Either<String, TitanOperationStatus> result;
1027 testSubject = createTestSubject();
1028 result = testSubject.checkInnerType(propDataDef);
1033 public void testGetAllDataTypeNodes() throws Exception {
1034 PropertyOperation testSubject;
1035 Either<List<DataTypeData>, TitanOperationStatus> result;
1038 testSubject = createTestSubject();
1039 result = testSubject.getAllDataTypeNodes();
1044 public void testValidateAndUpdatePropertyValue() throws Exception {
1045 PropertyOperation testSubject;
1046 String propertyType = "";
1048 boolean isValidate = false;
1049 String innerType = "";
1050 Map<String, DataTypeDefinition> dataTypes = null;
1051 Either<Object, Boolean> result;
1054 testSubject = createTestSubject();
1055 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, isValidate, innerType, dataTypes);
1060 public void testValidateAndUpdatePropertyValue_1() throws Exception {
1061 PropertyOperation testSubject;
1062 String propertyType = "";
1064 String innerType = "";
1065 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
1066 dataTypes.put("", new DataTypeDefinition());
1067 Either<Object, Boolean> result;
1070 testSubject = createTestSubject();
1071 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, innerType, dataTypes);
1079 public void testAddPropertiesToElementType() throws Exception {
1080 PropertyOperation testSubject;
1081 String uniqueId = "";
1082 NodeTypeEnum elementType = null;
1083 List<PropertyDefinition> properties = null;
1084 Either<Map<String, PropertyData>, TitanOperationStatus> result;
1087 testSubject = createTestSubject();
1089 result = testSubject.addPropertiesToElementType(uniqueId, elementType, properties);
1094 public void testUpdateDataType() throws Exception {
1095 PropertyOperation testSubject;
1096 DataTypeDefinition newDataTypeDefinition = new DataTypeDefinition();
1097 DataTypeDefinition oldDataTypeDefinition = new DataTypeDefinition();
1098 Either<DataTypeDefinition, StorageOperationStatus> result;
1101 testSubject = createTestSubject();
1102 result = testSubject.updateDataType(newDataTypeDefinition, oldDataTypeDefinition);