Sync Integ to Master
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / path / ForwardingPathDeleteCITest.java
1 package org.openecomp.sdc.be.components.path;
2
3 import org.junit.Before;
4 import org.junit.Test;
5 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
6 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
7 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
8 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
9 import org.openecomp.sdc.be.model.Service;
10
11 import java.util.HashMap;
12 import java.util.Map;
13 import java.util.Set;
14
15 import static org.junit.Assert.assertEquals;
16 import static org.junit.Assert.assertFalse;
17 import static org.junit.Assert.assertNotNull;
18 import static org.junit.Assert.assertTrue;
19
20 public class ForwardingPathDeleteCITest {
21
22     private Service service;
23     private static final String nodeA = "nodeA";
24     private static final String nodeB = "nodeB";
25     private static final String fpName = "fpName";
26
27     @Before
28     public void initService() {
29         service = new Service();
30         ForwardingPathDataDefinition forwardingPath = new ForwardingPathDataDefinition(fpName);
31         String protocol = "protocol";
32         forwardingPath.setProtocol(protocol);
33         forwardingPath.setDestinationPortNumber("DestinationPortNumber");
34         ListDataDefinition<ForwardingPathElementDataDefinition> forwardingPathElementListDataDefinition
35             = new ListDataDefinition<>();
36
37         forwardingPathElementListDataDefinition.add(
38             new ForwardingPathElementDataDefinition(nodeA, nodeB, "nodeAcpType", "nodeBcpType", "nodeDcpName",
39                 "nodeBcpName"));
40         forwardingPathElementListDataDefinition.add(
41             new ForwardingPathElementDataDefinition(nodeB, "nodeC", "nodeBcpType", "nodeCcpType", "nodeDcpName",
42                 "nodeBcpName"));
43         forwardingPathElementListDataDefinition.add(
44             new ForwardingPathElementDataDefinition("nodeC", "nodeD", "nodeCcpType", "nodeDcpType", "nodeDcpName",
45                 "nodeBcpName"));
46         forwardingPath.setPathElements(forwardingPathElementListDataDefinition);
47         Map<String, ForwardingPathDataDefinition> forwardingPaths = new HashMap<>();
48         forwardingPaths.put("NEW", forwardingPath);
49         service.setForwardingPaths(forwardingPaths);
50     }
51
52
53     @Test
54     public void getListToDelete() {
55
56         Set<String> forwardingPathNamesToDeleteOnComponenetInstanceDeletion = new ForwardingPathUtils()
57             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeA);
58         assertEquals(1, forwardingPathNamesToDeleteOnComponenetInstanceDeletion.size());
59         assertTrue(forwardingPathNamesToDeleteOnComponenetInstanceDeletion.contains(fpName));
60
61         Set<String> forwardingPathNamesToDeleteOnCIDelete = new ForwardingPathUtils()
62             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, nodeB);
63         assertNotNull(forwardingPathNamesToDeleteOnCIDelete);
64         assertEquals(1, forwardingPathNamesToDeleteOnCIDelete.size());
65         assertTrue(forwardingPathNamesToDeleteOnComponenetInstanceDeletion.contains(fpName));
66
67         forwardingPathNamesToDeleteOnCIDelete = new ForwardingPathUtils()
68             .findForwardingPathNamesToDeleteOnComponentInstanceDeletion(service, "Does not exist");
69         assertNotNull(forwardingPathNamesToDeleteOnCIDelete);
70         assertEquals(0, forwardingPathNamesToDeleteOnCIDelete.size());
71         assertFalse(forwardingPathNamesToDeleteOnCIDelete.contains(fpName));
72     }
73
74 }