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.janusgraph.HealingJanusGraphGenericDao;
31 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
32 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
33 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
34 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
35 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
36 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
37 import org.openecomp.sdc.be.model.*;
38 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
39 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
40 import org.openecomp.sdc.be.model.tosca.ToscaType;
41 import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
42 import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
43 import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
44 import org.openecomp.sdc.be.resources.data.DataTypeData;
45 import org.openecomp.sdc.be.resources.data.PropertyData;
46 import org.openecomp.sdc.be.resources.data.PropertyValueData;
50 import static org.junit.Assert.*;
52 public class PropertyOperationTest extends ModelTestBase {
54 HealingJanusGraphGenericDao janusGraphGenericDao = Mockito.mock(HealingJanusGraphGenericDao.class);
56 PropertyOperation propertyOperation = new PropertyOperation(janusGraphGenericDao, null);
60 propertyOperation.setJanusGraphGenericDao(janusGraphGenericDao);
65 * @Test public void addPropertyToResourceTest() {
67 * String propName = "myProp"; PropertyDefinition property = buildPropertyDefinition(); List<PropertyConstraint> constraints = buildConstraints(); property.setConstraints(constraints);
69 * PropertyData propertyData = new PropertyData(property, propertyOperation.convertConstraintsToString(constraints));
71 * Either<PropertyData, JanusGraphOperationStatus> either = Either.left(propertyData); //when(propertyDao.create((GraphNeighbourTable)anyObject(), eq(PropertyData.class), eq(NodeTypeEnum.Property))).thenReturn(either); GraphRelation graphRelation =
72 * new GraphRelation(); Either<GraphRelation, JanusGraphOperationStatus> relationResult = Either.left(graphRelation);
74 * when(janusGraphGenericDao.createNode((PropertyData)anyObject(), eq(PropertyData.class))).thenReturn(either); when(janusGraphGenericDao.createRelation((GraphNode)anyObject(), (GraphNode)anyObject(), eq(GraphEdgeLabels.PROPERTY),
75 * anyMap())).thenReturn(relationResult);
77 * Either<PropertyDefinition, StorageOperationStatus> result = propertyOperation.addPropertyToResource(propName, property, NodeTypeEnum.Resource, "my-resource.1.0");
79 * assertTrue(result.isLeft()); System.out.println(result.left().value()); PropertyDefinition propertyDefinition = result.left().value();
81 * List<PropertyConstraint> originalConstraints = property.getConstraints(); List<PropertyConstraint> propertyConstraintsResult = propertyDefinition.getConstraints(); assertEquals(propertyConstraintsResult.size(), originalConstraints.size());
85 private PropertyDefinition buildPropertyDefinition() {
86 PropertyDefinition property = new PropertyDefinition();
87 property.setDefaultValue("10");
88 property.setDescription("Size of the local disk, in Gigabytes (GB), available to applications running on the Compute node.");
89 property.setType(ToscaType.INTEGER.name().toLowerCase());
94 public void addPropertiesToGraphTableTest() {
96 // Map<String, PropertyDefinition> properties = new HashMap<String,
97 // PropertyDefinition>();
98 // String propName = "myProp";
99 // PropertyDefinition property = buildPropertyDefinition();
101 // List<PropertyConstraint> constraints = buildConstraints();
102 // property.setConstraints(constraints);
104 // properties.put(propName, property);
106 // GraphNeighbourTable graphNeighbourTable = new GraphNeighbourTable();
107 // ResourceData resourceData = new ResourceData();
108 // String resourceName = "my-resource";
109 // String resourceVersion = "1.0";
110 // String resourceId = resourceName + "." + resourceVersion;
111 // resourceData.setUniqueId(resourceId);
112 // int resourceIndex = graphNeighbourTable.addNode(resourceData);
114 // heatParametersOperation.addPropertiesToGraphTable(properties,
115 // graphNeighbourTable, resourceIndex, resourceId);
117 // assertEquals(2, graphNeighbourTable.getNodes().size());
118 // assertEquals(1, graphNeighbourTable.getDirectedEdges().size());
119 // List<GraphNode> nodes = graphNeighbourTable.getNodes();
120 // boolean nodeFound = false;
121 // for (GraphNode neo4jNode : nodes) {
122 // if (neo4jNode instanceof PropertyData) {
123 // PropertyData propertyData = (PropertyData)neo4jNode;
124 // assertEquals("check property unique id", resourceId + "." + propName,
125 // propertyData.getUniqueId());
126 // assertEquals(property.getDescription(),
127 // propertyData.getPropertyDataDefinition().getDescription());
131 // assertEquals("looking for PropertyData object in table", true,
134 // NodeRelation nodeRelation =
135 // graphNeighbourTable.getDirectedEdges().get(0);
136 // assertEquals("check from index to index edge", 0,
137 // nodeRelation.getFromIndex());
138 // assertEquals("check from index to index edge", 1,
139 // nodeRelation.getToIndex());
140 // assertEquals("check edge type",
141 // GraphEdgePropertiesDictionary.PROPERTY,
142 // nodeRelation.getEdge().getEdgeType());
143 // assertEquals("check propert name on edge", true,
144 // nodeRelation.getEdge().getProperties().values().contains(propName));
148 public void convertConstraintsTest() {
150 List<PropertyConstraint> constraints = buildConstraints();
151 List<String> convertedStringConstraints = propertyOperation.convertConstraintsToString(constraints);
152 assertEquals("constraints size", constraints.size(), convertedStringConstraints.size());
154 List<PropertyConstraint> convertedConstraints = propertyOperation.convertConstraints(convertedStringConstraints);
155 assertEquals("check size of constraints", constraints.size(), convertedConstraints.size());
157 Set<String> constraintsClasses = new HashSet<>();
158 for (PropertyConstraint propertyConstraint : constraints) {
159 constraintsClasses.add(propertyConstraint.getClass().getName());
162 for (PropertyConstraint propertyConstraint : convertedConstraints) {
163 assertTrue("check all classes generated", constraintsClasses.contains(propertyConstraint.getClass().getName()));
168 public void testIsPropertyDefaultValueValid_NoDefault() {
169 PropertyDefinition property = new PropertyDefinition();
170 property.setName("myProperty");
171 property.setType(ToscaPropertyType.BOOLEAN.getType());
172 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
176 public void testIsPropertyDefaultValueValid_ValidDefault() {
177 PropertyDefinition property = new PropertyDefinition();
178 property.setName("myProperty");
179 property.setType(ToscaPropertyType.INTEGER.getType());
180 property.setDefaultValue("50");
181 assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
185 public void testIsPropertyDefaultValueValid_InvalidDefault() {
186 PropertyDefinition property = new PropertyDefinition();
187 property.setName("myProperty");
188 property.setType(ToscaPropertyType.BOOLEAN.getType());
189 property.setDefaultValue("50");
190 assertFalse(propertyOperation.isPropertyDefaultValueValid(property, null));
193 private List<PropertyConstraint> buildConstraints() {
194 List<PropertyConstraint> constraints = new ArrayList<>();
195 GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0");
196 LessOrEqualConstraint propertyConstraint2 = new LessOrEqualConstraint("10");
197 List<String> range = new ArrayList<>();
200 InRangeConstraint propertyConstraint3 = new InRangeConstraint(range);
201 constraints.add(propertyConstraint1);
202 constraints.add(propertyConstraint2);
203 constraints.add(propertyConstraint3);
208 public void findPropertyValueBestMatch1() {
210 String propertyUniqueId = "x1";
211 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
212 instanceProperty.setValue("v1");
213 instanceProperty.setDefaultValue("vv1");
214 List<String> path = new ArrayList<>();
218 instanceProperty.setPath(path);
220 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
221 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
222 instanceProperty1.setValue("v1node1");
223 instanceIdToValue.put("node1", instanceProperty1);
225 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
226 instanceProperty2.setValue("v1node2");
227 instanceIdToValue.put("node2", instanceProperty2);
229 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
230 instanceProperty3.setValue("v1node3");
231 instanceIdToValue.put("node3", instanceProperty3);
233 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
235 assertEquals("check value", "v1node1", instanceProperty.getValue());
236 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
241 public void findPropertyValueBestMatch2() {
243 String propertyUniqueId = "x1";
244 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
245 instanceProperty.setValue("v1");
246 instanceProperty.setDefaultValue("vv1");
247 List<String> path = new ArrayList<>();
251 instanceProperty.setPath(path);
253 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
255 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
256 instanceProperty2.setValue("v1node2");
257 instanceProperty2.setValueUniqueUid("aaaa");
258 instanceIdToValue.put("node2", instanceProperty2);
260 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
262 assertEquals("check value", "v1node2", instanceProperty.getValue());
263 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
264 assertNull("check value unique id is null", instanceProperty.getValueUniqueUid());
269 public void findPropertyValueBestMatch3() {
271 String propertyUniqueId = "x1";
272 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
273 instanceProperty.setValue("v1");
274 instanceProperty.setDefaultValue("vv1");
275 List<String> path = new ArrayList<>();
279 instanceProperty.setPath(path);
281 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
282 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
283 instanceProperty1.setValue("v1node1");
284 instanceProperty1.setValueUniqueUid("aaaa");
285 instanceIdToValue.put("node1", instanceProperty1);
287 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
288 instanceProperty3.setValue("v1node3");
289 instanceIdToValue.put("node3", instanceProperty3);
291 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
293 assertEquals("check value", "v1node1", instanceProperty.getValue());
294 assertEquals("check default value", "v1node3", instanceProperty.getDefaultValue());
295 assertEquals("check valid unique id", instanceProperty1.getValueUniqueUid(), instanceProperty.getValueUniqueUid());
300 public void findPropertyValueBestMatch1Rules() {
302 String propertyUniqueId = "x1";
303 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
304 instanceProperty.setValue("v1");
305 instanceProperty.setDefaultValue("vv1");
306 List<String> path = new ArrayList<>();
310 instanceProperty.setPath(path);
312 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
313 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
314 instanceProperty1.setValue("v1node1");
316 List<PropertyRule> rules = new ArrayList<>();
317 PropertyRule propertyRule = new PropertyRule();
318 String[] ruleArr = { "node1", ".+", "node3" };
319 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr));
320 propertyRule.setRule(rule1);
321 propertyRule.setValue("88");
322 rules.add(propertyRule);
323 instanceProperty1.setRules(rules);
325 instanceIdToValue.put("node1", instanceProperty1);
327 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
328 instanceProperty2.setValue("v1node2");
329 instanceIdToValue.put("node2", instanceProperty2);
331 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
332 instanceProperty3.setValue("v1node3");
333 instanceIdToValue.put("node3", instanceProperty3);
335 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
337 assertEquals("check value", propertyRule.getValue(), instanceProperty.getValue());
338 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
343 public void findPropertyValueBestMatch2Rules() {
345 String propertyUniqueId = "x1";
346 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
347 instanceProperty.setValue("v1");
348 instanceProperty.setDefaultValue("vv1");
349 List<String> path = new ArrayList<>();
353 instanceProperty.setPath(path);
355 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
356 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
357 instanceProperty1.setValue("v1node1");
359 List<PropertyRule> rules = new ArrayList<>();
360 PropertyRule propertyRule1 = new PropertyRule();
361 String[] ruleArr1 = { "node1", "node2", ".+" };
362 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
363 propertyRule1.setRule(rule1);
364 propertyRule1.setValue("88");
366 PropertyRule propertyRule2 = new PropertyRule();
367 String[] ruleArr2 = { "node1", "node2", "node3" };
368 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
369 propertyRule2.setRule(rule2);
370 propertyRule2.setValue("99");
372 rules.add(propertyRule2);
373 rules.add(propertyRule1);
375 instanceProperty1.setRules(rules);
377 instanceIdToValue.put("node1", instanceProperty1);
379 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
380 instanceProperty2.setValue("v1node2");
381 instanceIdToValue.put("node2", instanceProperty2);
383 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
384 instanceProperty3.setValue("v1node3");
385 instanceIdToValue.put("node3", instanceProperty3);
387 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
389 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
390 assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
395 public void findPropertyValueBestMatch1RuleLowLevel() {
397 String propertyUniqueId = "x1";
398 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
399 instanceProperty.setValue("v1");
400 instanceProperty.setDefaultValue("vv1");
401 List<String> path = new ArrayList<>();
405 instanceProperty.setPath(path);
407 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
408 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
409 instanceProperty1.setValue("v1node1");
411 List<PropertyRule> rules = new ArrayList<>();
412 PropertyRule propertyRule1 = new PropertyRule();
413 String[] ruleArr1 = { "node1", "node2", ".+" };
414 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
415 propertyRule1.setRule(rule1);
416 propertyRule1.setValue("88");
418 PropertyRule propertyRule2 = new PropertyRule();
419 String[] ruleArr2 = { "node1", "node2", "node3" };
420 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
421 propertyRule2.setRule(rule2);
422 propertyRule2.setValue("99");
424 rules.add(propertyRule2);
425 rules.add(propertyRule1);
427 instanceProperty1.setRules(rules);
429 instanceIdToValue.put("node1", instanceProperty1);
431 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
432 instanceProperty2.setValue("v1node2");
434 List<PropertyRule> rules3 = new ArrayList<>();
435 PropertyRule propertyRule3 = new PropertyRule();
436 String[] ruleArr3 = { "node2", "node3" };
437 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
438 propertyRule3.setRule(rule3);
439 propertyRule3.setValue("77");
440 rules3.add(propertyRule3);
442 instanceProperty2.setRules(rules3);
443 instanceIdToValue.put("node2", instanceProperty2);
445 ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
446 instanceProperty3.setValue("v1node3");
447 instanceIdToValue.put("node3", instanceProperty3);
449 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
451 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
452 assertEquals("check default value", propertyRule3.getValue(), instanceProperty.getDefaultValue());
457 public void findPropertyValueBestMatchDefaultValueNotChanged() {
459 String propertyUniqueId = "x1";
460 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
461 instanceProperty.setValue("v1");
462 instanceProperty.setDefaultValue("vv1");
463 List<String> path = new ArrayList<>();
467 instanceProperty.setPath(path);
469 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
470 ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
471 instanceProperty1.setValue("v1node1");
473 List<PropertyRule> rules = new ArrayList<>();
474 PropertyRule propertyRule1 = new PropertyRule();
475 String[] ruleArr1 = { "node1", "node2", ".+" };
476 List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
477 propertyRule1.setRule(rule1);
478 propertyRule1.setValue("88");
480 PropertyRule propertyRule2 = new PropertyRule();
481 String[] ruleArr2 = { "node1", "node2", "node3" };
482 List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
483 propertyRule2.setRule(rule2);
484 propertyRule2.setValue("99");
486 rules.add(propertyRule2);
487 rules.add(propertyRule1);
489 instanceProperty1.setRules(rules);
491 instanceIdToValue.put("node1", instanceProperty1);
493 ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
494 instanceProperty2.setValue("v1node2");
496 List<PropertyRule> rules3 = new ArrayList<>();
497 PropertyRule propertyRule3 = new PropertyRule();
498 String[] ruleArr3 = { "node2", "node333" };
499 List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
500 propertyRule3.setRule(rule3);
501 propertyRule3.setValue("77");
502 rules3.add(propertyRule3);
504 instanceProperty2.setRules(rules3);
505 instanceIdToValue.put("node2", instanceProperty2);
507 propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
509 assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
510 assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
514 private PropertyOperation createTestSubject() {
515 return new PropertyOperation(new HealingJanusGraphGenericDao(new JanusGraphClient()), null);
520 public void testMain() throws Exception {
521 String[] args = new String[] { "" };
524 PropertyOperation.main(args);
529 public void testConvertPropertyDataToPropertyDefinition() throws Exception {
530 PropertyOperation testSubject;
531 PropertyData propertyDataResult = new PropertyData();
532 String propertyName = "";
533 String resourceId = "";
534 PropertyDefinition result;
537 testSubject = createTestSubject();
538 result = testSubject.convertPropertyDataToPropertyDefinition(propertyDataResult, propertyName, resourceId);
542 public void testAddProperty() throws Exception {
543 PropertyOperation testSubject;
544 String propertyName = "";
545 PropertyDefinition propertyDefinition = new PropertyDefinition();
546 String resourceId = "";
547 Either<PropertyData, StorageOperationStatus> result;
550 testSubject = createTestSubject();
551 result = testSubject.addProperty(propertyName, propertyDefinition, resourceId);
556 public void testValidateAndUpdateProperty() throws Exception {
557 PropertyOperation testSubject;
558 IComplexDefaultValue propertyDefinition = new PropertyDefinition();
559 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
560 dataTypes.put("", new DataTypeDefinition());
561 StorageOperationStatus result;
564 testSubject = createTestSubject();
565 result = testSubject.validateAndUpdateProperty(propertyDefinition, dataTypes);
570 public void testAddPropertyToGraph() throws Exception {
571 PropertyOperation testSubject;
572 String propertyName = "";
573 PropertyDefinition propertyDefinition = new PropertyDefinition();
574 String resourceId = "";
575 Either<PropertyData, JanusGraphOperationStatus> result;
578 testSubject = createTestSubject();
579 result = testSubject.addPropertyToGraph(propertyName, propertyDefinition, resourceId);
584 public void testAddPropertyToGraphByVertex() throws Exception {
585 PropertyOperation testSubject;
586 JanusGraphVertex metadataVertex = null;
587 String propertyName = "";
588 PropertyDefinition propertyDefinition = new PropertyDefinition();
589 String resourceId = "";
590 JanusGraphOperationStatus result;
593 testSubject = createTestSubject();
594 result = testSubject.addPropertyToGraphByVertex(metadataVertex, propertyName, propertyDefinition, resourceId);
599 public void testGetJanusGraphGenericDao() throws Exception {
600 PropertyOperation testSubject;
601 JanusGraphGenericDao result;
604 testSubject = createTestSubject();
605 result = testSubject.getJanusGraphGenericDao();
609 public void testDeletePropertyFromGraph() throws Exception {
610 PropertyOperation testSubject;
611 String propertyId = "";
612 Either<PropertyData, JanusGraphOperationStatus> result;
615 testSubject = createTestSubject();
616 result = testSubject.deletePropertyFromGraph(propertyId);
621 public void testUpdateProperty() throws Exception {
622 PropertyOperation testSubject;
623 String propertyId = "";
624 PropertyDefinition newPropertyDefinition = new PropertyDefinition();
625 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
626 Either<PropertyData, StorageOperationStatus> result;
629 testSubject = createTestSubject();
630 result = testSubject.updateProperty(propertyId, newPropertyDefinition, dataTypes);
635 public void testUpdatePropertyFromGraph() throws Exception {
636 PropertyOperation testSubject;
637 String propertyId = "";
638 PropertyDefinition propertyDefinition = null;
639 Either<PropertyData, JanusGraphOperationStatus> result;
642 testSubject = createTestSubject();
643 result = testSubject.updatePropertyFromGraph(propertyId, propertyDefinition);
648 public void testSetJanusGraphGenericDao() {
650 PropertyOperation testSubject;
651 HealingJanusGraphGenericDao janusGraphGenericDao = null;
654 testSubject = createTestSubject();
655 testSubject.setJanusGraphGenericDao(janusGraphGenericDao);
660 public void testAddPropertyToNodeType() {
661 PropertyOperation testSubject;
662 String propertyName = "";
663 PropertyDefinition propertyDefinition = new PropertyDefinition();
664 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
665 String uniqueId = "";
666 Either<PropertyData, JanusGraphOperationStatus> result;
669 testSubject = createTestSubject();
670 result = testSubject.addPropertyToNodeType(propertyName, propertyDefinition, nodeType, uniqueId);
675 public void testFindPropertiesOfNode() throws Exception {
676 PropertyOperation testSubject;
677 NodeTypeEnum nodeType = null;
678 String uniqueId = "";
679 Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result;
682 testSubject = createTestSubject();
683 result = testSubject.findPropertiesOfNode(nodeType, uniqueId);
688 public void testDeletePropertiesAssociatedToNode() throws Exception {
689 PropertyOperation testSubject;
690 NodeTypeEnum nodeType = null;
691 String uniqueId = "";
692 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
695 testSubject = createTestSubject();
696 result = testSubject.deletePropertiesAssociatedToNode(nodeType, uniqueId);
701 public void testDeleteAllPropertiesAssociatedToNode() throws Exception {
702 PropertyOperation testSubject;
703 NodeTypeEnum nodeType = null;
704 String uniqueId = "";
705 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
708 testSubject = createTestSubject();
709 result = testSubject.deleteAllPropertiesAssociatedToNode(nodeType, uniqueId);
714 public void testIsPropertyExist() throws Exception {
715 PropertyOperation testSubject;
716 List<PropertyDefinition> properties = null;
717 String resourceUid = "";
718 String propertyName = "";
719 String propertyType = "";
723 testSubject = createTestSubject();
724 result = testSubject.isPropertyExist(properties, resourceUid, propertyName, propertyType);
729 public void testValidateAndUpdateRules() throws Exception {
730 PropertyOperation testSubject;
731 String propertyType = "";
732 List<PropertyRule> rules = null;
733 String innerType = "";
734 Map<String, DataTypeDefinition> dataTypes = null;
735 boolean isValidate = false;
736 ImmutablePair<String, Boolean> result;
739 testSubject = createTestSubject();
741 result = testSubject.validateAndUpdateRules(propertyType, rules, innerType, dataTypes, isValidate);
746 public void testAddRulesToNewPropertyValue() throws Exception {
747 PropertyOperation testSubject;
748 PropertyValueData propertyValueData = new PropertyValueData();
749 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
750 String resourceInstanceId = "";
753 testSubject = createTestSubject();
754 testSubject.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
759 public void testFindPropertyValue() throws Exception {
760 PropertyOperation testSubject;
761 String resourceInstanceId = "";
762 String propertyId = "";
763 ImmutablePair<JanusGraphOperationStatus, String> result;
766 testSubject = createTestSubject();
767 result = testSubject.findPropertyValue(resourceInstanceId, propertyId);
772 public void testUpdateRulesInPropertyValue() throws Exception {
773 PropertyOperation testSubject;
774 PropertyValueData propertyValueData = new PropertyValueData();
775 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
776 String resourceInstanceId = "";
779 testSubject = createTestSubject();
780 testSubject.updateRulesInPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
785 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId() throws Exception {
786 PropertyOperation testSubject;
787 String resourceInstanceUid = "";
788 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
791 testSubject = createTestSubject();
792 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid);
797 public void testRemovePropertyOfResourceInstance() throws Exception {
798 PropertyOperation testSubject;
799 String propertyValueUid = "";
800 String resourceInstanceId = "";
801 Either<PropertyValueData, JanusGraphOperationStatus> result;
804 testSubject = createTestSubject();
805 result = testSubject.removePropertyOfResourceInstance(propertyValueUid, resourceInstanceId);
810 public void testRemovePropertyValueFromResourceInstance() throws Exception {
811 PropertyOperation testSubject;
812 String propertyValueUid = "";
813 String resourceInstanceId = "";
814 boolean inTransaction = false;
815 Either<ComponentInstanceProperty, StorageOperationStatus> result;
818 testSubject = createTestSubject();
819 result = testSubject.removePropertyValueFromResourceInstance(propertyValueUid, resourceInstanceId,
825 public void testBuildResourceInstanceProperty() throws Exception {
826 PropertyOperation testSubject;
827 PropertyValueData propertyValueData = new PropertyValueData();
828 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
829 ComponentInstanceProperty result;
832 testSubject = createTestSubject();
833 result = testSubject.buildResourceInstanceProperty(propertyValueData, resourceInstanceProperty);
838 public void testIsPropertyDefaultValueValid() throws Exception {
839 PropertyOperation testSubject;
840 IComplexDefaultValue propertyDefinition = null;
841 Map<String, DataTypeDefinition> dataTypes = null;
845 testSubject = createTestSubject();
846 propertyDefinition = null;
847 result = testSubject.isPropertyDefaultValueValid(propertyDefinition, dataTypes);
848 Assert.assertEquals(false, result);
853 public void testIsPropertyTypeValid() throws Exception {
854 PropertyOperation testSubject;
855 IComplexDefaultValue property = null;
859 testSubject = createTestSubject();
861 result = testSubject.isPropertyTypeValid(property);
862 Assert.assertEquals(false, result);
867 public void testIsPropertyInnerTypeValid() throws Exception {
868 PropertyOperation testSubject;
869 IComplexDefaultValue property = null;
870 Map<String, DataTypeDefinition> dataTypes = null;
871 ImmutablePair<String, Boolean> result;
874 testSubject = createTestSubject();
876 result = testSubject.isPropertyInnerTypeValid(property, dataTypes);
881 public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId_1() throws Exception {
882 PropertyOperation testSubject;
883 String resourceInstanceUid = "";
884 NodeTypeEnum instanceNodeType = null;
885 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
888 testSubject = createTestSubject();
889 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid, instanceNodeType);
894 public void testFindDefaultValueFromSecondPosition() throws Exception {
895 PropertyOperation testSubject;
896 List<String> pathOfComponentInstances = null;
897 String propertyUniqueId = "";
898 String defaultValue = "";
899 Either<String, JanusGraphOperationStatus> result;
902 testSubject = createTestSubject();
903 pathOfComponentInstances = null;
904 result = testSubject.findDefaultValueFromSecondPosition(pathOfComponentInstances, propertyUniqueId,
910 public void testUpdatePropertyByBestMatch() throws Exception {
911 PropertyOperation testSubject;
912 String propertyUniqueId = "";
913 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
914 List<String> path = new ArrayList<>();
916 instanceProperty.setPath(path);
917 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
918 instanceIdToValue.put("123", instanceProperty);
921 testSubject = createTestSubject();
922 testSubject.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
927 public void testGetDataTypeByUid() throws Exception {
928 PropertyOperation testSubject;
929 String uniqueId = "";
930 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
933 testSubject = createTestSubject();
934 result = testSubject.getDataTypeByUid(uniqueId);
939 public void testAddDataType() throws Exception {
940 PropertyOperation testSubject;
941 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
942 Either<DataTypeDefinition, StorageOperationStatus> result;
945 testSubject = createTestSubject();
946 result = testSubject.addDataType(dataTypeDefinition);
951 public void testGetDataTypeByName() throws Exception {
952 PropertyOperation testSubject;
954 boolean inTransaction = false;
955 Either<DataTypeDefinition, StorageOperationStatus> result;
958 testSubject = createTestSubject();
959 result = testSubject.getDataTypeByName(name, inTransaction);
964 public void testGetDataTypeByName_1() throws Exception {
965 PropertyOperation testSubject;
967 Either<DataTypeDefinition, StorageOperationStatus> result;
970 testSubject = createTestSubject();
971 result = testSubject.getDataTypeByName(name);
976 public void testGetDataTypeByNameWithoutDerived() throws Exception {
977 PropertyOperation testSubject;
979 Either<DataTypeDefinition, StorageOperationStatus> result;
982 testSubject = createTestSubject();
983 result = testSubject.getDataTypeByNameWithoutDerived(name);
988 public void testGetDataTypeByUidWithoutDerivedDataTypes() throws Exception {
989 PropertyOperation testSubject;
990 String uniqueId = "";
991 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
994 testSubject = createTestSubject();
995 result = testSubject.getDataTypeByUidWithoutDerivedDataTypes(uniqueId);
1000 public void testIsDefinedInDataTypes() throws Exception {
1001 PropertyOperation testSubject;
1002 String propertyType = "";
1003 Either<Boolean, JanusGraphOperationStatus> result;
1006 testSubject = createTestSubject();
1007 result = testSubject.isDefinedInDataTypes(propertyType);
1012 public void testGetAllDataTypes() throws Exception {
1013 PropertyOperation testSubject;
1014 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> result;
1017 testSubject = createTestSubject();
1018 result = testSubject.getAllDataTypes();
1023 public void testCheckInnerType() throws Exception {
1024 PropertyOperation testSubject;
1025 PropertyDataDefinition propDataDef = new PropertyDataDefinition();
1026 Either<String, JanusGraphOperationStatus> result;
1029 testSubject = createTestSubject();
1030 result = testSubject.checkInnerType(propDataDef);
1035 public void testGetAllDataTypeNodes() throws Exception {
1036 PropertyOperation testSubject;
1037 Either<List<DataTypeData>, JanusGraphOperationStatus> result;
1040 testSubject = createTestSubject();
1041 result = testSubject.getAllDataTypeNodes();
1046 public void testValidateAndUpdatePropertyValue() throws Exception {
1047 PropertyOperation testSubject;
1048 String propertyType = "";
1050 boolean isValidate = false;
1051 String innerType = "";
1052 Map<String, DataTypeDefinition> dataTypes = null;
1053 Either<Object, Boolean> result;
1056 testSubject = createTestSubject();
1057 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, isValidate, innerType, dataTypes);
1062 public void testValidateAndUpdatePropertyValue_1() throws Exception {
1063 PropertyOperation testSubject;
1064 String propertyType = "";
1066 String innerType = "";
1067 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
1068 dataTypes.put("", new DataTypeDefinition());
1069 Either<Object, Boolean> result;
1072 testSubject = createTestSubject();
1073 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, innerType, dataTypes);
1081 public void testAddPropertiesToElementType() throws Exception {
1082 PropertyOperation testSubject;
1083 String uniqueId = "";
1084 NodeTypeEnum elementType = null;
1085 List<PropertyDefinition> properties = null;
1086 Either<Map<String, PropertyData>, JanusGraphOperationStatus> result;
1089 testSubject = createTestSubject();
1091 result = testSubject.addPropertiesToElementType(uniqueId, elementType, properties);
1096 public void testUpdateDataType() throws Exception {
1097 PropertyOperation testSubject;
1098 DataTypeDefinition newDataTypeDefinition = new DataTypeDefinition();
1099 DataTypeDefinition oldDataTypeDefinition = new DataTypeDefinition();
1100 Either<DataTypeDefinition, StorageOperationStatus> result;
1103 testSubject = createTestSubject();
1104 result = testSubject.updateDataType(newDataTypeDefinition, oldDataTypeDefinition);