Fix property validation for data type in model
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / operations / impl / PropertyOperationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.model.operations.impl;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.Mockito.mock;
28
29 import fj.data.Either;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.HashSet;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Set;
38 import org.apache.commons.lang3.tuple.ImmutablePair;
39 import org.janusgraph.core.JanusGraphVertex;
40 import org.junit.Assert;
41 import org.junit.Before;
42 import org.junit.Test;
43 import org.mockito.Mockito;
44 import org.openecomp.sdc.be.dao.graph.datatype.GraphRelation;
45 import org.openecomp.sdc.be.dao.janusgraph.HealingJanusGraphGenericDao;
46 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphClient;
47 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphGenericDao;
48 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
49 import org.openecomp.sdc.be.dao.neo4j.GraphEdgeLabels;
50 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
51 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
52 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
53 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
54 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
55 import org.openecomp.sdc.be.model.DataTypeDefinition;
56 import org.openecomp.sdc.be.model.IComplexDefaultValue;
57 import org.openecomp.sdc.be.model.ModelTestBase;
58 import org.openecomp.sdc.be.model.PropertyConstraint;
59 import org.openecomp.sdc.be.model.PropertyDefinition;
60 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
61 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
62 import org.openecomp.sdc.be.model.tosca.ToscaType;
63 import org.openecomp.sdc.be.model.tosca.constraints.GreaterThanConstraint;
64 import org.openecomp.sdc.be.model.tosca.constraints.InRangeConstraint;
65 import org.openecomp.sdc.be.model.tosca.constraints.LessOrEqualConstraint;
66 import org.openecomp.sdc.be.resources.data.DataTypeData;
67 import org.openecomp.sdc.be.resources.data.PropertyData;
68 import org.openecomp.sdc.be.resources.data.PropertyValueData;
69
70 public class PropertyOperationTest extends ModelTestBase {
71
72     HealingJanusGraphGenericDao janusGraphGenericDao = mock(HealingJanusGraphGenericDao.class);
73
74     final DataTypeOperation dataTypeOperation = mock(DataTypeOperation.class);
75
76     PropertyOperation propertyOperation = new PropertyOperation(janusGraphGenericDao, null);
77
78     @Before
79     public void setup() {
80         propertyOperation.setDataTypeOperation(dataTypeOperation);
81         propertyOperation.setJanusGraphGenericDao(janusGraphGenericDao);
82     }
83
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());
89         return property;
90     }
91
92     @Test
93     public void convertConstraintsTest() {
94
95         List<PropertyConstraint> constraints = buildConstraints();
96         List<String> convertedStringConstraints = propertyOperation.convertConstraintsToString(constraints);
97         assertEquals("constraints size", constraints.size(), convertedStringConstraints.size());
98
99         List<PropertyConstraint> convertedConstraints = propertyOperation.convertConstraints(convertedStringConstraints);
100         assertEquals("check size of constraints", constraints.size(), convertedConstraints.size());
101
102         Set<String> constraintsClasses = new HashSet<>();
103         for (PropertyConstraint propertyConstraint : constraints) {
104             constraintsClasses.add(propertyConstraint.getClass().getName());
105         }
106
107         for (PropertyConstraint propertyConstraint : convertedConstraints) {
108             assertTrue("check all classes generated", constraintsClasses.contains(propertyConstraint.getClass().getName()));
109         }
110     }
111
112     @Test
113     public void testIsPropertyDefaultValueValid_NoDefault() {
114         PropertyDefinition property = new PropertyDefinition();
115         property.setName("myProperty");
116         property.setType(ToscaPropertyType.BOOLEAN.getType());
117         assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
118     }
119
120     @Test
121     public void testIsPropertyDefaultValueValid_ValidDefault() {
122         PropertyDefinition property = new PropertyDefinition();
123         property.setName("myProperty");
124         property.setType(ToscaPropertyType.INTEGER.getType());
125         property.setDefaultValue("50");
126         assertTrue(propertyOperation.isPropertyDefaultValueValid(property, null));
127     }
128
129     @Test
130     public void testIsPropertyDefaultValueValid_InvalidDefault() {
131         PropertyDefinition property = new PropertyDefinition();
132         property.setName("myProperty");
133         property.setType(ToscaPropertyType.BOOLEAN.getType());
134         property.setDefaultValue("50");
135         assertFalse(propertyOperation.isPropertyDefaultValueValid(property, null));
136     }
137
138     private List<PropertyConstraint> buildConstraints() {
139         List<PropertyConstraint> constraints = new ArrayList<>();
140         GreaterThanConstraint propertyConstraint1 = new GreaterThanConstraint("0");
141         LessOrEqualConstraint propertyConstraint2 = new LessOrEqualConstraint("10");
142         List<String> range = new ArrayList<>();
143         range.add("0");
144         range.add("100");
145         InRangeConstraint propertyConstraint3 = new InRangeConstraint(range);
146         constraints.add(propertyConstraint1);
147         constraints.add(propertyConstraint2);
148         constraints.add(propertyConstraint3);
149         return constraints;
150     }
151
152     @Test
153     public void findPropertyValueBestMatch1() {
154
155         String propertyUniqueId = "x1";
156         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
157         instanceProperty.setValue("v1");
158         instanceProperty.setDefaultValue("vv1");
159         List<String> path = new ArrayList<>();
160         path.add("node1");
161         path.add("node2");
162         path.add("node3");
163         instanceProperty.setPath(path);
164
165         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
166         ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
167         instanceProperty1.setValue("v1node1");
168         instanceIdToValue.put("node1", instanceProperty1);
169
170         ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
171         instanceProperty2.setValue("v1node2");
172         instanceIdToValue.put("node2", instanceProperty2);
173
174         ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
175         instanceProperty3.setValue("v1node3");
176         instanceIdToValue.put("node3", instanceProperty3);
177
178         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
179
180         assertEquals("check value", "v1node1", instanceProperty.getValue());
181         assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
182
183     }
184
185     @Test
186     public void findPropertyValueBestMatch2() {
187
188         String propertyUniqueId = "x1";
189         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
190         instanceProperty.setValue("v1");
191         instanceProperty.setDefaultValue("vv1");
192         List<String> path = new ArrayList<>();
193         path.add("node1");
194         path.add("node2");
195         path.add("node3");
196         instanceProperty.setPath(path);
197
198         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
199
200         ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
201         instanceProperty2.setValue("v1node2");
202         instanceProperty2.setValueUniqueUid("aaaa");
203         instanceIdToValue.put("node2", instanceProperty2);
204
205         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
206
207         assertEquals("check value", "v1node2", instanceProperty.getValue());
208         assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
209         assertNull("check value unique id is null", instanceProperty.getValueUniqueUid());
210
211     }
212
213     @Test
214     public void findPropertyValueBestMatch3() {
215
216         String propertyUniqueId = "x1";
217         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
218         instanceProperty.setValue("v1");
219         instanceProperty.setDefaultValue("vv1");
220         List<String> path = new ArrayList<>();
221         path.add("node1");
222         path.add("node2");
223         path.add("node3");
224         instanceProperty.setPath(path);
225
226         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
227         ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
228         instanceProperty1.setValue("v1node1");
229         instanceProperty1.setValueUniqueUid("aaaa");
230         instanceIdToValue.put("node1", instanceProperty1);
231
232         ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
233         instanceProperty3.setValue("v1node3");
234         instanceIdToValue.put("node3", instanceProperty3);
235
236         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
237
238         assertEquals("check value", "v1node1", instanceProperty.getValue());
239         assertEquals("check default value", "v1node3", instanceProperty.getDefaultValue());
240         assertEquals("check valid unique id", instanceProperty1.getValueUniqueUid(), instanceProperty.getValueUniqueUid());
241
242     }
243
244     @Test
245     public void findPropertyValueBestMatch1Rules() {
246
247         String propertyUniqueId = "x1";
248         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
249         instanceProperty.setValue("v1");
250         instanceProperty.setDefaultValue("vv1");
251         List<String> path = new ArrayList<>();
252         path.add("node1");
253         path.add("node2");
254         path.add("node3");
255         instanceProperty.setPath(path);
256
257         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
258         ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
259         instanceProperty1.setValue("v1node1");
260
261         List<PropertyRule> rules = new ArrayList<>();
262         PropertyRule propertyRule = new PropertyRule();
263         String[] ruleArr = { "node1", ".+", "node3" };
264         List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr));
265         propertyRule.setRule(rule1);
266         propertyRule.setValue("88");
267         rules.add(propertyRule);
268         instanceProperty1.setRules(rules);
269
270         instanceIdToValue.put("node1", instanceProperty1);
271
272         ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
273         instanceProperty2.setValue("v1node2");
274         instanceIdToValue.put("node2", instanceProperty2);
275
276         ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
277         instanceProperty3.setValue("v1node3");
278         instanceIdToValue.put("node3", instanceProperty3);
279
280         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
281
282         assertEquals("check value", propertyRule.getValue(), instanceProperty.getValue());
283         assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
284
285     }
286
287     @Test
288     public void findPropertyValueBestMatch2Rules() {
289
290         String propertyUniqueId = "x1";
291         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
292         instanceProperty.setValue("v1");
293         instanceProperty.setDefaultValue("vv1");
294         List<String> path = new ArrayList<>();
295         path.add("node1");
296         path.add("node2");
297         path.add("node3");
298         instanceProperty.setPath(path);
299
300         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
301         ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
302         instanceProperty1.setValue("v1node1");
303
304         List<PropertyRule> rules = new ArrayList<>();
305         PropertyRule propertyRule1 = new PropertyRule();
306         String[] ruleArr1 = { "node1", "node2", ".+" };
307         List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
308         propertyRule1.setRule(rule1);
309         propertyRule1.setValue("88");
310
311         PropertyRule propertyRule2 = new PropertyRule();
312         String[] ruleArr2 = { "node1", "node2", "node3" };
313         List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
314         propertyRule2.setRule(rule2);
315         propertyRule2.setValue("99");
316
317         rules.add(propertyRule2);
318         rules.add(propertyRule1);
319
320         instanceProperty1.setRules(rules);
321
322         instanceIdToValue.put("node1", instanceProperty1);
323
324         ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
325         instanceProperty2.setValue("v1node2");
326         instanceIdToValue.put("node2", instanceProperty2);
327
328         ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
329         instanceProperty3.setValue("v1node3");
330         instanceIdToValue.put("node3", instanceProperty3);
331
332         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
333
334         assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
335         assertEquals("check default value", "v1node2", instanceProperty.getDefaultValue());
336
337     }
338
339     @Test
340     public void findPropertyValueBestMatch1RuleLowLevel() {
341
342         String propertyUniqueId = "x1";
343         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
344         instanceProperty.setValue("v1");
345         instanceProperty.setDefaultValue("vv1");
346         List<String> path = new ArrayList<>();
347         path.add("node1");
348         path.add("node2");
349         path.add("node3");
350         instanceProperty.setPath(path);
351
352         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
353         ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
354         instanceProperty1.setValue("v1node1");
355
356         List<PropertyRule> rules = new ArrayList<>();
357         PropertyRule propertyRule1 = new PropertyRule();
358         String[] ruleArr1 = { "node1", "node2", ".+" };
359         List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
360         propertyRule1.setRule(rule1);
361         propertyRule1.setValue("88");
362
363         PropertyRule propertyRule2 = new PropertyRule();
364         String[] ruleArr2 = { "node1", "node2", "node3" };
365         List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
366         propertyRule2.setRule(rule2);
367         propertyRule2.setValue("99");
368
369         rules.add(propertyRule2);
370         rules.add(propertyRule1);
371
372         instanceProperty1.setRules(rules);
373
374         instanceIdToValue.put("node1", instanceProperty1);
375
376         ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
377         instanceProperty2.setValue("v1node2");
378
379         List<PropertyRule> rules3 = new ArrayList<>();
380         PropertyRule propertyRule3 = new PropertyRule();
381         String[] ruleArr3 = { "node2", "node3" };
382         List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
383         propertyRule3.setRule(rule3);
384         propertyRule3.setValue("77");
385         rules3.add(propertyRule3);
386
387         instanceProperty2.setRules(rules3);
388         instanceIdToValue.put("node2", instanceProperty2);
389
390         ComponentInstanceProperty instanceProperty3 = new ComponentInstanceProperty();
391         instanceProperty3.setValue("v1node3");
392         instanceIdToValue.put("node3", instanceProperty3);
393
394         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
395
396         assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
397         assertEquals("check default value", propertyRule3.getValue(), instanceProperty.getDefaultValue());
398
399     }
400
401     @Test
402     public void findPropertyValueBestMatchDefaultValueNotChanged() {
403
404         String propertyUniqueId = "x1";
405         ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
406         instanceProperty.setValue("v1");
407         instanceProperty.setDefaultValue("vv1");
408         List<String> path = new ArrayList<>();
409         path.add("node1");
410         path.add("node2");
411         path.add("node3");
412         instanceProperty.setPath(path);
413
414         Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
415         ComponentInstanceProperty instanceProperty1 = new ComponentInstanceProperty();
416         instanceProperty1.setValue("v1node1");
417
418         List<PropertyRule> rules = new ArrayList<>();
419         PropertyRule propertyRule1 = new PropertyRule();
420         String[] ruleArr1 = { "node1", "node2", ".+" };
421         List<String> rule1 = new ArrayList<>(Arrays.asList(ruleArr1));
422         propertyRule1.setRule(rule1);
423         propertyRule1.setValue("88");
424
425         PropertyRule propertyRule2 = new PropertyRule();
426         String[] ruleArr2 = { "node1", "node2", "node3" };
427         List<String> rule2 = new ArrayList<>(Arrays.asList(ruleArr2));
428         propertyRule2.setRule(rule2);
429         propertyRule2.setValue("99");
430
431         rules.add(propertyRule2);
432         rules.add(propertyRule1);
433
434         instanceProperty1.setRules(rules);
435
436         instanceIdToValue.put("node1", instanceProperty1);
437
438         ComponentInstanceProperty instanceProperty2 = new ComponentInstanceProperty();
439         instanceProperty2.setValue("v1node2");
440
441         List<PropertyRule> rules3 = new ArrayList<>();
442         PropertyRule propertyRule3 = new PropertyRule();
443         String[] ruleArr3 = { "node2", "node333" };
444         List<String> rule3 = new ArrayList<>(Arrays.asList(ruleArr3));
445         propertyRule3.setRule(rule3);
446         propertyRule3.setValue("77");
447         rules3.add(propertyRule3);
448
449         instanceProperty2.setRules(rules3);
450         instanceIdToValue.put("node2", instanceProperty2);
451
452         propertyOperation.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
453
454         assertEquals("check value", propertyRule2.getValue(), instanceProperty.getValue());
455         assertEquals("check default value", "vv1", instanceProperty.getDefaultValue());
456
457         }
458
459     private PropertyOperation createTestSubject() {
460         final var propertyOperation = new PropertyOperation(new HealingJanusGraphGenericDao(new JanusGraphClient()), null);
461         propertyOperation.setDataTypeOperation(dataTypeOperation);
462         return propertyOperation;
463     }
464
465         @Test
466         public void testConvertPropertyDataToPropertyDefinition() throws Exception {
467                 PropertyOperation testSubject;
468                 PropertyData propertyDataResult = new PropertyData();
469                 String propertyName = "";
470                 String resourceId = "";
471                 PropertyDefinition result;
472
473                 // default test
474                 testSubject = createTestSubject();
475                 result = testSubject.convertPropertyDataToPropertyDefinition(propertyDataResult, propertyName, resourceId);
476         }
477         
478         @Test
479         public void testAddProperty() throws Exception {
480                 PropertyOperation testSubject;
481                 String propertyName = "";
482                 PropertyDefinition propertyDefinition = new PropertyDefinition();
483                 String resourceId = "";
484                 Either<PropertyData, StorageOperationStatus> result;
485
486                 // default test
487                 testSubject = createTestSubject();
488                 result = testSubject.addProperty(propertyName, propertyDefinition, resourceId);
489         }
490
491         
492         @Test
493         public void testValidateAndUpdateProperty() throws Exception {
494                 PropertyOperation testSubject;
495                 IComplexDefaultValue propertyDefinition = new PropertyDefinition();
496                 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
497                 dataTypes.put("", new DataTypeDefinition());
498                 StorageOperationStatus result;
499
500                 // default test
501                 testSubject = createTestSubject();
502                 result = testSubject.validateAndUpdateProperty(propertyDefinition, dataTypes);
503         }
504
505         
506         @Test
507         public void testAddPropertyToGraph() throws Exception {
508                 PropertyOperation testSubject;
509                 String propertyName = "";
510                 PropertyDefinition propertyDefinition = new PropertyDefinition();
511                 String resourceId = "";
512                 Either<PropertyData, JanusGraphOperationStatus> result;
513
514                 // default test
515                 testSubject = createTestSubject();
516                 result = testSubject.addPropertyToGraph(propertyName, propertyDefinition, resourceId);
517         }
518
519         
520         @Test
521         public void testAddPropertyToGraphByVertex() throws Exception {
522                 PropertyOperation testSubject;
523                 JanusGraphVertex metadataVertex = null;
524                 String propertyName = "";
525                 PropertyDefinition propertyDefinition = new PropertyDefinition();
526                 String resourceId = "";
527                 JanusGraphOperationStatus result;
528
529                 // default test
530                 testSubject = createTestSubject();
531                 result = testSubject.addPropertyToGraphByVertex(metadataVertex, propertyName, propertyDefinition, resourceId);
532         }
533
534         
535         @Test
536         public void testGetJanusGraphGenericDao() throws Exception {
537                 PropertyOperation testSubject;
538                 JanusGraphGenericDao result;
539
540                 // default test
541                 testSubject = createTestSubject();
542                 result = testSubject.getJanusGraphGenericDao();
543         }
544
545         @Test
546         public void testDeletePropertyFromGraph() throws Exception {
547                 PropertyOperation testSubject;
548                 String propertyId = "";
549                 Either<PropertyData, JanusGraphOperationStatus> result;
550
551                 // default test
552                 testSubject = createTestSubject();
553                 result = testSubject.deletePropertyFromGraph(propertyId);
554         }
555
556         
557         @Test
558         public void testUpdateProperty() throws Exception {
559                 PropertyOperation testSubject;
560                 String propertyId = "";
561                 PropertyDefinition newPropertyDefinition = new PropertyDefinition();
562                 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
563                 Either<PropertyData, StorageOperationStatus> result;
564
565                 // default test
566                 testSubject = createTestSubject();
567                 result = testSubject.updateProperty(propertyId, newPropertyDefinition, dataTypes);
568         }
569
570         
571         @Test
572         public void testUpdatePropertyFromGraph() throws Exception {
573                 PropertyOperation testSubject;
574                 String propertyId = "";
575                 PropertyDefinition propertyDefinition = null;
576                 Either<PropertyData, JanusGraphOperationStatus> result;
577
578                 // default test
579                 testSubject = createTestSubject();
580                 result = testSubject.updatePropertyFromGraph(propertyId, propertyDefinition);
581         }
582
583
584         @Test
585         public void testSetJanusGraphGenericDao()  {
586
587                 PropertyOperation testSubject;
588         HealingJanusGraphGenericDao janusGraphGenericDao = null;
589
590                 // default test
591                 testSubject = createTestSubject();
592                 testSubject.setJanusGraphGenericDao(janusGraphGenericDao);
593         }
594
595         
596         @Test
597         public void testAddPropertyToNodeType()  {
598                 PropertyOperation testSubject;
599                 String propertyName = "";
600                 PropertyDefinition propertyDefinition = new PropertyDefinition();
601                 NodeTypeEnum nodeType = NodeTypeEnum.Attribute;
602                 String uniqueId = "";
603                 Either<PropertyData, JanusGraphOperationStatus> result;
604
605                 // default test
606                 testSubject = createTestSubject();
607                 result = testSubject.addPropertyToNodeType(propertyName, propertyDefinition, nodeType, uniqueId);
608         }
609
610         
611         @Test
612         public void testFindPropertiesOfNode() throws Exception {
613                 PropertyOperation testSubject;
614                 NodeTypeEnum nodeType = null;
615                 String uniqueId = "";
616                 Either<Map<String, PropertyDefinition>, JanusGraphOperationStatus> result;
617
618                 // default test
619                 testSubject = createTestSubject();
620                 result = testSubject.findPropertiesOfNode(nodeType, uniqueId);
621         }
622
623         
624         @Test
625         public void testDeletePropertiesAssociatedToNode() throws Exception {
626                 PropertyOperation testSubject;
627                 NodeTypeEnum nodeType = null;
628                 String uniqueId = "";
629                 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
630
631                 // default test
632                 testSubject = createTestSubject();
633                 result = testSubject.deletePropertiesAssociatedToNode(nodeType, uniqueId);
634         }
635
636         
637         @Test
638         public void testDeleteAllPropertiesAssociatedToNode() throws Exception {
639                 PropertyOperation testSubject;
640                 NodeTypeEnum nodeType = null;
641                 String uniqueId = "";
642                 Either<Map<String, PropertyDefinition>, StorageOperationStatus> result;
643
644                 // default test
645                 testSubject = createTestSubject();
646                 result = testSubject.deleteAllPropertiesAssociatedToNode(nodeType, uniqueId);
647         }
648
649         
650         @Test
651         public void testIsPropertyExist() throws Exception {
652                 PropertyOperation testSubject;
653                 List<PropertyDefinition> properties = null;
654                 String resourceUid = "";
655                 String propertyName = "";
656                 String propertyType = "";
657                 boolean result;
658
659                 // default test
660                 testSubject = createTestSubject();
661                 result = testSubject.isPropertyExist(properties, resourceUid, propertyName, propertyType);
662         }
663
664         
665         @Test
666         public void testValidateAndUpdateRules() throws Exception {
667                 PropertyOperation testSubject;
668                 String propertyType = "";
669                 List<PropertyRule> rules = null;
670                 String innerType = "";
671                 Map<String, DataTypeDefinition> dataTypes = null;
672                 boolean isValidate = false;
673                 ImmutablePair<String, Boolean> result;
674
675                 // test 1
676                 testSubject = createTestSubject();
677                 rules = null;
678                 result = testSubject.validateAndUpdateRules(propertyType, rules, innerType, dataTypes, isValidate);
679         }
680
681         
682         @Test
683         public void testAddRulesToNewPropertyValue() throws Exception {
684                 PropertyOperation testSubject;
685                 PropertyValueData propertyValueData = new PropertyValueData();
686                 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
687                 String resourceInstanceId = "";
688
689                 // default test
690                 testSubject = createTestSubject();
691                 testSubject.addRulesToNewPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
692         }
693
694         
695         @Test
696         public void testFindPropertyValue() throws Exception {
697                 PropertyOperation testSubject;
698                 String resourceInstanceId = "";
699                 String propertyId = "";
700                 ImmutablePair<JanusGraphOperationStatus, String> result;
701
702                 // default test
703                 testSubject = createTestSubject();
704                 result = testSubject.findPropertyValue(resourceInstanceId, propertyId);
705         }
706
707         
708         @Test
709         public void testUpdateRulesInPropertyValue() throws Exception {
710                 PropertyOperation testSubject;
711                 PropertyValueData propertyValueData = new PropertyValueData();
712                 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
713                 String resourceInstanceId = "";
714
715                 // default test
716                 testSubject = createTestSubject();
717                 testSubject.updateRulesInPropertyValue(propertyValueData, resourceInstanceProperty, resourceInstanceId);
718         }
719
720         
721         @Test
722         public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId() throws Exception {
723                 PropertyOperation testSubject;
724                 String resourceInstanceUid = "";
725                 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
726
727                 // default test
728                 testSubject = createTestSubject();
729                 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid);
730         }
731
732         
733         @Test
734         public void testRemovePropertyOfResourceInstance() throws Exception {
735                 PropertyOperation testSubject;
736                 String propertyValueUid = "";
737                 String resourceInstanceId = "";
738                 Either<PropertyValueData, JanusGraphOperationStatus> result;
739
740                 // default test
741                 testSubject = createTestSubject();
742                 result = testSubject.removePropertyOfResourceInstance(propertyValueUid, resourceInstanceId);
743         }
744
745         
746         @Test
747         public void testRemovePropertyValueFromResourceInstance() throws Exception {
748                 PropertyOperation testSubject;
749                 String propertyValueUid = "";
750                 String resourceInstanceId = "";
751                 boolean inTransaction = false;
752                 Either<ComponentInstanceProperty, StorageOperationStatus> result;
753
754                 // default test
755                 testSubject = createTestSubject();
756                 result = testSubject.removePropertyValueFromResourceInstance(propertyValueUid, resourceInstanceId,
757                                 inTransaction);
758         }
759
760         
761         @Test
762         public void testBuildResourceInstanceProperty() throws Exception {
763                 PropertyOperation testSubject;
764                 PropertyValueData propertyValueData = new PropertyValueData();
765                 ComponentInstanceProperty resourceInstanceProperty = new ComponentInstanceProperty();
766                 ComponentInstanceProperty result;
767
768                 // default test
769                 testSubject = createTestSubject();
770                 result = testSubject.buildResourceInstanceProperty(propertyValueData, resourceInstanceProperty);
771         }
772
773         
774         @Test
775         public void testIsPropertyDefaultValueValid() throws Exception {
776                 PropertyOperation testSubject;
777                 IComplexDefaultValue propertyDefinition = null;
778                 Map<String, DataTypeDefinition> dataTypes = null;
779                 boolean result;
780
781                 // test 1
782                 testSubject = createTestSubject();
783                 propertyDefinition = null;
784                 result = testSubject.isPropertyDefaultValueValid(propertyDefinition, dataTypes);
785                 Assert.assertEquals(false, result);
786         }
787
788         
789         @Test
790         public void testIsPropertyTypeValid() throws Exception {
791                 PropertyOperation testSubject;
792                 IComplexDefaultValue property = null;
793                 boolean result;
794
795                 // test 1
796                 testSubject = createTestSubject();
797                 property = null;
798                 result = testSubject.isPropertyTypeValid(property, (String)null);
799                 Assert.assertEquals(false, result);
800         }
801
802         
803         @Test
804         public void testIsPropertyInnerTypeValid() throws Exception {
805                 PropertyOperation testSubject;
806                 IComplexDefaultValue property = null;
807                 Map<String, DataTypeDefinition> dataTypes = null;
808                 ImmutablePair<String, Boolean> result;
809
810                 // test 1
811                 testSubject = createTestSubject();
812                 property = null;
813                 result = testSubject.isPropertyInnerTypeValid(property, dataTypes);
814         }
815
816         
817         @Test
818         public void testGetAllPropertiesOfResourceInstanceOnlyPropertyDefId_1() throws Exception {
819                 PropertyOperation testSubject;
820                 String resourceInstanceUid = "";
821                 NodeTypeEnum instanceNodeType = null;
822                 Either<List<ComponentInstanceProperty>, JanusGraphOperationStatus> result;
823
824                 // default test
825                 testSubject = createTestSubject();
826                 result = testSubject.getAllPropertiesOfResourceInstanceOnlyPropertyDefId(resourceInstanceUid, instanceNodeType);
827         }
828
829         
830         @Test
831         public void testFindDefaultValueFromSecondPosition() throws Exception {
832                 PropertyOperation testSubject;
833                 List<String> pathOfComponentInstances = null;
834                 String propertyUniqueId = "";
835                 String defaultValue = "";
836                 Either<String, JanusGraphOperationStatus> result;
837
838                 // test 1
839                 testSubject = createTestSubject();
840                 pathOfComponentInstances = null;
841                 result = testSubject.findDefaultValueFromSecondPosition(pathOfComponentInstances, propertyUniqueId,
842                                 defaultValue);
843         }
844
845         
846         @Test
847         public void testUpdatePropertyByBestMatch() throws Exception {
848                 PropertyOperation testSubject;
849                 String propertyUniqueId = "";
850                 ComponentInstanceProperty instanceProperty = new ComponentInstanceProperty();
851                 List<String> path = new ArrayList<>();
852                 path.add("path");
853                 instanceProperty.setPath(path);
854                 Map<String, ComponentInstanceProperty> instanceIdToValue = new HashMap<>();
855                 instanceIdToValue.put("123", instanceProperty);
856
857                 // default test
858                 testSubject = createTestSubject();
859                 testSubject.updatePropertyByBestMatch(propertyUniqueId, instanceProperty, instanceIdToValue);
860         }
861
862         
863         @Test
864         public void testGetDataTypeByUid() throws Exception {
865                 PropertyOperation testSubject;
866                 String uniqueId = "";
867                 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
868
869                 // default test
870                 testSubject = createTestSubject();
871                 result = testSubject.getDataTypeByUid(uniqueId);
872         }
873
874         
875         @Test
876         public void testAddAndGetDataType() throws Exception {
877             final String dataTypeName = "myDataType";
878                 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
879                 dataTypeDefinition.setName("myDataType");
880                 Either<DataTypeDefinition, StorageOperationStatus> result;
881                 
882         Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
883             .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
884         
885         Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
886             .getNode(GraphPropertiesDictionary.NAME.getProperty(), dataTypeName, DataTypeData.class, null);
887         
888         Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
889             .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
890
891                 result = propertyOperation.addDataType(dataTypeDefinition);
892         assertTrue(result.isLeft());
893         
894         Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
895             .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
896                 
897             result = propertyOperation.getDataTypeByName(dataTypeName, null, false);
898             assertTrue(result.isLeft());
899             
900             result = propertyOperation.getDataTypeByName(dataTypeName, null);
901             assertTrue(result.isLeft());
902             
903         Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
904             .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), dataTypeName + ".datatype", DataTypeData.class);
905             
906             Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("myDataType.datatype");
907             assertTrue(resultGetByUid.isLeft());
908             
909             Either<Boolean, JanusGraphOperationStatus> resultIsDefinedDataType = propertyOperation.isDefinedInDataTypes(dataTypeName, null);
910         assertTrue(resultIsDefinedDataType.isLeft());
911         }
912         
913            @Test
914             public void testAddDataTypeToModel() throws Exception {
915                 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
916                 dataTypeDefinition.setName("testName");
917                 dataTypeDefinition.setModel("testModel");
918                 Either<DataTypeDefinition, StorageOperationStatus> result;
919
920                 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
921                 .createNode(Mockito.any(), Mockito.eq(DataTypeData.class));
922                 
923                 Mockito.doReturn(Either.left(new GraphRelation())).when(janusGraphGenericDao)
924                 .createRelation(Mockito.any(), Mockito.any(), Mockito.eq(GraphEdgeLabels.MODEL_ELEMENT), Mockito.any());
925
926                 result = propertyOperation.addDataType(dataTypeDefinition);
927                 assertTrue(result.isLeft());
928                 
929                 Mockito.doReturn(Either.left(new DataTypeData(dataTypeDefinition))).when(janusGraphGenericDao)
930                     .getNode(GraphPropertiesDictionary.UNIQUE_ID.getProperty(), "testModel.testName.datatype", DataTypeData.class);
931                 
932                 Mockito.doReturn(Either.left(Collections.EMPTY_LIST)).when(janusGraphGenericDao)
933                     .getChildrenNodes(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.PROPERTY), Mockito.eq(NodeTypeEnum.Property), Mockito.eq(PropertyData.class));
934                 
935                 Mockito.doReturn(Either.right(JanusGraphOperationStatus.NOT_FOUND)).when(janusGraphGenericDao)
936                     .getChild(Mockito.anyString(), Mockito.anyString(), Mockito.eq(GraphEdgeLabels.DERIVED_FROM), Mockito.eq(NodeTypeEnum.DataType), Mockito.eq(DataTypeData.class));
937                 
938                 Either<DataTypeDefinition, JanusGraphOperationStatus> resultGetByUid = propertyOperation.getDataTypeByUid("testModel.testName.datatype");
939                 assertTrue(resultGetByUid.isLeft());
940             }
941
942         
943         @Test
944         public void testGetDataTypeByUidWithoutDerivedDataTypes() throws Exception {
945                 PropertyOperation testSubject;
946                 String uniqueId = "";
947                 Either<DataTypeDefinition, JanusGraphOperationStatus> result;
948
949                 // default test
950                 testSubject = createTestSubject();
951                 result = testSubject.getDataTypeByUidWithoutDerivedDataTypes(uniqueId);
952         }
953
954         
955         @Test
956         public void testGetAllDataTypes() throws Exception {
957                 PropertyOperation testSubject;
958                 Either<Map<String, Map<String, DataTypeDefinition>>, JanusGraphOperationStatus> result;
959
960                 // default test
961                 testSubject = createTestSubject();
962                 result = testSubject.getAllDataTypes();
963         }
964
965         
966         @Test
967         public void testCheckInnerType() throws Exception {
968                 PropertyOperation testSubject;
969                 PropertyDataDefinition propDataDef = new PropertyDataDefinition();
970                 Either<String, JanusGraphOperationStatus> result;
971
972                 // default test
973                 testSubject = createTestSubject();
974                 result = testSubject.checkInnerType(propDataDef);
975         }
976
977         @Test
978         public void testValidateAndUpdatePropertyValue() throws Exception {
979                 PropertyOperation testSubject;
980                 String propertyType = "";
981                 String value = "";
982                 boolean isValidate = false;
983                 String innerType = "";
984                 Map<String, DataTypeDefinition> dataTypes = null;
985                 Either<Object, Boolean> result;
986
987                 // default test
988                 testSubject = createTestSubject();
989                 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, isValidate, innerType, dataTypes);
990         }
991
992         
993         @Test
994         public void testValidateAndUpdatePropertyValue_1() throws Exception {
995                 PropertyOperation testSubject;
996                 String propertyType = "";
997                 String value = "";
998                 String innerType = "";
999                 Map<String, DataTypeDefinition> dataTypes = new HashMap<>();
1000                 dataTypes.put("", new DataTypeDefinition());
1001                 Either<Object, Boolean> result;
1002
1003                 // default test
1004                 testSubject = createTestSubject();
1005                 result = testSubject.validateAndUpdatePropertyValue(propertyType, value, innerType, dataTypes);
1006         }
1007
1008         
1009
1010
1011         
1012         @Test
1013         public void testAddPropertiesToElementType() throws Exception {
1014                 PropertyOperation testSubject;
1015                 String uniqueId = "";
1016                 NodeTypeEnum elementType = null;
1017                 List<PropertyDefinition> properties = null;
1018                 Either<Map<String, PropertyData>, JanusGraphOperationStatus> result;
1019
1020                 // test 1
1021                 testSubject = createTestSubject();
1022                 properties = null;
1023                 result = testSubject.addPropertiesToElementType(uniqueId, elementType, properties);
1024         }
1025
1026         
1027         @Test
1028         public void testUpdateDataType() throws Exception {
1029                 PropertyOperation testSubject;
1030                 DataTypeDefinition newDataTypeDefinition = new DataTypeDefinition();
1031                 DataTypeDefinition oldDataTypeDefinition = new DataTypeDefinition();
1032                 Either<DataTypeDefinition, StorageOperationStatus> result;
1033
1034                 // default test
1035                 testSubject = createTestSubject();
1036                 result = testSubject.updateDataType(newDataTypeDefinition, oldDataTypeDefinition);
1037         }
1038 }