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