efef9bd799717c80addc2438ce8ded81507f80d2
[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.assertEquals;
36 import static org.junit.Assert.assertFalse;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertTrue;
39
40 public class ForwardingPathDeleteCITest {
41
42     private Service service;
43     private static final String nodeA = "nodeA";
44     private static final String nodeB = "nodeB";
45     private static final String fpName = "fpName";
46
47     @Before
48     public void initService() {
49         service = new Service();
50         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(fpName);
51         String protocol = "protocol";
52         forwardingPath.setProtocol(protocol);
53         forwardingPath.setDestinationPortNumber("DestinationPortNumber");
54         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition
55             = new ListDataDefinition<>();
56
57         forwardingPathElementListDataDefinition.add(
58             new ForwardingPathElementDataDefinition(nodeA, nodeB, "nodeAcpType", "nodeBcpType", "nodeDcpName",
59                 "nodeBcpName"));
60         forwardingPathElementListDataDefinition.add(
61             new ForwardingPathElementDataDefinition(nodeB, "nodeC", "nodeBcpType", "nodeCcpType", "nodeDcpName",
62                 "nodeBcpName"));
63         forwardingPathElementListDataDefinition.add(
64             new ForwardingPathElementDataDefinition("nodeC", "nodeD", "nodeCcpType", "nodeDcpType", "nodeDcpName",
65                 "nodeBcpName"));
66         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
67         Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
68         forwardingPaths.put("NEW", forwardingPath);
69         service.setForwardingPaths(forwardingPaths);
70     }
71
72
73     @Test
74     public void getListToDelete() {
75
76         Set<String> forwardingPathNamesToDeleteOnComponenetInstanceDeletion = new ForwardingPathUtils()
77             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeA);
78         assertEquals(1, forwardingPathNamesToDeleteOnComponenetInstanceDeletion.size());
79         assertTrue(forwardingPathNamesToDeleteOnComponenetInstanceDeletion.contains(fpName));
80
81         Set<String> forwardingPathNamesToDeleteOnCIDelete = new ForwardingPathUtils()
82             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeB);
83         assertNotNull(forwardingPathNamesToDeleteOnCIDelete);
84         assertEquals(1, forwardingPathNamesToDeleteOnCIDelete.size());
85         assertTrue(forwardingPathNamesToDeleteOnComponenetInstanceDeletion.contains(fpName));
86
87         forwardingPathNamesToDeleteOnCIDelete = new ForwardingPathUtils()
88             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, "Does not exist");
89         assertNotNull(forwardingPathNamesToDeleteOnCIDelete);
90         assertEquals(0, forwardingPathNamesToDeleteOnCIDelete.size());
91         assertFalse(forwardingPathNamesToDeleteOnCIDelete.contains(fpName));
92     }
93
94 }