Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / path / ForwardingPathDeleteCITest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.components.path;
22
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
26 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
27 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
28 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
29 import org.openecomp.sdc.be.model.Service;
30
31 import java.util.HashMap;
32 import java.util.Map;
33 import java.util.Set;
34
35 import static org.junit.Assert.*;
36
37 public class ForwardingPathDeleteCITest {
38
39     private Service service;
40     private static final String nodeA = "nodeA";
41     private static final String nodeB = "nodeB";
42     private static final String fpName = "fpName";
43
44     @Before
45     public void initService() {
46         service = new Service();
47         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(fpName);
48         String protocol = "protocol";
49         forwardingPath.setProtocol(protocol);
50         forwardingPath.setDestinationPortNumber("DestinationPortNumber");
51         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition
52             = new ListDataDefinition<>();
53
54         forwardingPathElementListDataDefinition.add(
55             new ForwardingPathElementDataDefinition(nodeA, nodeB, "nodeAcpType", "nodeBcpType", "nodeDcpName",
56                 "nodeBcpName"));
57         forwardingPathElementListDataDefinition.add(
58             new ForwardingPathElementDataDefinition(nodeB, "nodeC", "nodeBcpType", "nodeCcpType", "nodeDcpName",
59                 "nodeBcpName"));
60         forwardingPathElementListDataDefinition.add(
61             new ForwardingPathElementDataDefinition("nodeC", "nodeD", "nodeCcpType", "nodeDcpType", "nodeDcpName",
62                 "nodeBcpName"));
63         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
64         Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
65         forwardingPaths.put("NEW", forwardingPath);
66         service.setForwardingPaths(forwardingPaths);
67     }
68
69
70     @Test
71     public void getListToDelete() {
72
73         Set<String> forwardingPathNamesToDeleteOnComponenetInstanceDeletion = new ForwardingPathUtils()
74             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeA);
75         assertEquals(1, forwardingPathNamesToDeleteOnComponenetInstanceDeletion.size());
76         assertTrue(forwardingPathNamesToDeleteOnComponenetInstanceDeletion.contains(fpName));
77
78         Set<String> forwardingPathNamesToDeleteOnCIDelete = new ForwardingPathUtils()
79             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeB);
80         assertNotNull(forwardingPathNamesToDeleteOnCIDelete);
81         assertEquals(1, forwardingPathNamesToDeleteOnCIDelete.size());
82         assertTrue(forwardingPathNamesToDeleteOnComponenetInstanceDeletion.contains(fpName));
83
84         forwardingPathNamesToDeleteOnCIDelete = new ForwardingPathUtils()
85             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, "Does not exist");
86         assertNotNull(forwardingPathNamesToDeleteOnCIDelete);
87         assertEquals(0, forwardingPathNamesToDeleteOnCIDelete.size());
88         assertFalse(forwardingPathNamesToDeleteOnCIDelete.contains(fpName));
89     }
90
91 }