069282367f8840f1909cd2370bb7ff3561befda7
[sdc.git] /
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.junit.Before;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.dao.graph.datatype.GraphEdge;
26 import org.openecomp.sdc.be.dao.neo4j.GraphEdgePropertiesDictionary;
27 import org.openecomp.sdc.be.model.ComponentInstance;
28 import org.openecomp.sdc.be.model.operations.api.ToscaDefinitionPathCalculator;
29
30 import java.util.Collections;
31 import java.util.List;
32
33 import static org.junit.Assert.assertEquals;
34
35 public class ToscaDefinitionPathCalculatorTest {
36
37     private static final String INSTANCE_ID = "123";
38     private static final String OWNER_ID = "321";
39
40     private ToscaDefinitionPathCalculator toscaDefinitionPathCalculator;
41
42
43     @Before
44     public void setUp() throws Exception {
45         toscaDefinitionPathCalculator = new ToscaDefinitionPathCalculatorImpl();
46     }
47
48     @Test
49     public void calculatePath_ownerAndComponentInstanceEqual() throws Exception {
50         ComponentInstance instance = getComponentInstance(INSTANCE_ID);
51         GraphEdge edge = createEdgeWithOwner(INSTANCE_ID);
52         List<String> definitionPath = toscaDefinitionPathCalculator.calculateToscaDefinitionPath(instance, edge);
53         assertEquals(1, definitionPath.size());
54         assertEquals(INSTANCE_ID, definitionPath.get(0));
55     }
56
57     @Test
58     public void calculatePath() throws Exception {
59         ComponentInstance instance = getComponentInstance(INSTANCE_ID);
60         GraphEdge edge = createEdgeWithOwner(OWNER_ID);
61         List<String> definitionPath = toscaDefinitionPathCalculator.calculateToscaDefinitionPath(instance, edge);
62         assertEquals(2, definitionPath.size());
63         assertEquals(INSTANCE_ID, definitionPath.get(0));
64         assertEquals(OWNER_ID, definitionPath.get(1));
65
66     }
67
68
69     private ComponentInstance getComponentInstance(String instanceId) {
70         ComponentInstance instance = new ComponentInstance();
71         instance.setUniqueId(instanceId);
72         return instance;
73     }
74
75     private GraphEdge createEdgeWithOwner(String owner) {
76         GraphEdge edge = new GraphEdge();
77         edge.setProperties(Collections.singletonMap(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), owner));
78         return edge;
79     }
80
81 }