2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.components.path;
23 import com.google.common.collect.Lists;
24 import org.junit.Before;
25 import org.openecomp.sdc.be.components.merge.instance.DataForMergeHolder;
26 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
27 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
29 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
30 import org.openecomp.sdc.be.model.*;
32 import java.util.Arrays;
33 import java.util.HashMap;
34 import java.util.List;
37 public abstract class BaseForwardingPathVersionChangeTest {
38 protected Service service;
39 protected ComponentInstance nodeACI;
40 protected ComponentInstance newNodeACI;
41 protected Component newNodeAC;
42 protected Component newNodeWithoutCapability;
43 protected DataForMergeHolder dataHolder;
44 protected static final String nodeA = "nodeA";
45 protected static final String NODE_A_FORWARDER_CAPABILITY = "nodeA_FORWARDER_CAPABILITY";
46 protected static final String nodeB = "nodeB";
47 protected static final String newNodeA = "newNodeA";
48 protected static final String fpName = "fpName";
49 protected static final String FPId = "1122";
53 public void initService() {
54 service = new Service();
55 ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(fpName);
56 String protocol = "protocol";
57 forwardingPath.setProtocol(protocol);
58 forwardingPath.setDestinationPortNumber("DestinationPortNumber");
59 ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition
60 = new ListDataDefinition<>();
62 forwardingPathElementListDataDefinition.add(
63 new ForwardingPathElementDataDefinition(nodeA, nodeB, NODE_A_FORWARDER_CAPABILITY, "nodeBcpType" , "nodeDcpName",
65 forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
66 Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
67 forwardingPaths.put(FPId, forwardingPath);
68 service.setForwardingPaths(forwardingPaths);
69 nodeACI = new ComponentInstance();
70 initComponentInstance(nodeACI, nodeA);
71 newNodeACI = new ComponentInstance();
72 initComponentInstance(newNodeACI, newNodeA);
73 newNodeAC = new Resource();
74 newNodeWithoutCapability=new Resource();
75 initComponent(newNodeAC, newNodeA);
76 service.setComponentInstances(Lists.newArrayList(newNodeACI));
77 initComponentWithoutForwarder(newNodeWithoutCapability,"newNodeC");
78 service.setComponentInstances(Lists.newArrayList(nodeACI));
80 dataHolder = new DataForMergeHolder();
81 dataHolder.setOrigComponentInstId(nodeA);
84 private void initComponent(Component component, String uniqueId) {
85 component.setUniqueId(uniqueId);
86 HashMap<String, List<CapabilityDefinition>> capabilities = initCapabilites();
87 component.setCapabilities(capabilities);
90 private void initComponentWithoutForwarder(Component component, String uniqueId) {
91 component.setUniqueId(uniqueId);
92 HashMap<String, List<CapabilityDefinition>> capabilities = initCapabilitesWithoutForwarder();
93 component.setCapabilities(capabilities);
96 private HashMap<String, List<CapabilityDefinition>> initCapabilites() {
97 HashMap<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
98 CapabilityDefinition forwarder = new CapabilityDefinition();
99 forwarder.setType(ForwardingPathUtils.FORWARDER_CAPABILITY);
100 forwarder.setUniqueId(NODE_A_FORWARDER_CAPABILITY);
101 forwarder.setName(NODE_A_FORWARDER_CAPABILITY);
102 capabilities.put("bla bla", Arrays.asList(forwarder));
106 private HashMap<String, List<CapabilityDefinition>> initCapabilitesWithoutForwarder() {
107 HashMap<String, List<CapabilityDefinition>> capabilities = new HashMap<>();
108 CapabilityDefinition capabilityDefinition = new CapabilityDefinition();
109 capabilityDefinition.setType("tosca.capabilities.Node");
110 capabilityDefinition.setUniqueId("tosca capability");
111 capabilityDefinition.setName("tosca capability");
112 capabilities.put("bla bla", Arrays.asList(capabilityDefinition));
116 private void initComponentInstance(ComponentInstance component, String uniqueId) {
117 component.setUniqueId(uniqueId);
118 component.setName(uniqueId);
119 HashMap<String, List<CapabilityDefinition>> capabilities = initCapabilites();
120 component.setCapabilities(capabilities);