2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.model.operations.impl;
23 import org.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;
30 import java.util.Collections;
31 import java.util.List;
33 import static org.junit.Assert.assertEquals;
35 public class ToscaDefinitionPathCalculatorTest {
37 private static final String INSTANCE_ID = "123";
38 private static final String OWNER_ID = "321";
40 private ToscaDefinitionPathCalculator toscaDefinitionPathCalculator;
44 public void setUp() throws Exception {
45 toscaDefinitionPathCalculator = new ToscaDefinitionPathCalculatorImpl();
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));
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));
69 private ComponentInstance getComponentInstance(String instanceId) {
70 ComponentInstance instance = new ComponentInstance();
71 instance.setUniqueId(instanceId);
75 private GraphEdge createEdgeWithOwner(String owner) {
76 GraphEdge edge = new GraphEdge();
77 edge.setProperties(Collections.singletonMap(GraphEdgePropertiesDictionary.OWNER_ID.getProperty(), owner));