MappingServiceManager: pass VPN info to intents
[vpnservice.git] / vpnintent / impl / src / test / java / org / opendaylight / vpnservice / impl / MappingServiceManagerTests.java
1 /*
2  * Copyright (c) 2016 Inocybe Technologies and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.vpnservice.impl;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.mockito.Matchers.any;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.junit.Test;
21 import org.opendaylight.nic.mapping.api.IntentMappingService;
22
23 public class MappingServiceManagerTests {
24
25     @Test
26     public void addInfo() {
27         // Arrange
28         String siteName = "UoR";
29         String ipPrefix = "16.101.233.2/8";
30         String switchPortId = "openflow:1:3";
31         long mplsLabel = 10L;
32         String nextHop = "16.101.233.1/8";
33
34         Map<String, String> map = new HashMap<>();
35         map.put("ip_prefix", ipPrefix);
36         map.put("switch_port", switchPortId);
37         map.put("mpls_label", String.valueOf(mplsLabel));
38         map.put("next_hop", nextHop);
39
40         IntentMappingService mapSvc = mock(IntentMappingService.class);
41         when(mapSvc.get(any(String.class))).thenReturn(map);
42
43         MappingServiceManager manager = new MappingServiceManager(mapSvc);
44
45         // Act
46         manager.add(siteName, ipPrefix, switchPortId, mplsLabel, nextHop);
47
48         Map<String, String> returnedObjs = manager.get(siteName);
49
50         // Assert
51         assertEquals(ipPrefix, returnedObjs.get("ip_prefix"));
52         assertEquals(switchPortId, returnedObjs.get("switch_port"));
53         assertEquals(mplsLabel, Long.parseLong(returnedObjs.get("mpls_label")));
54         assertEquals(nextHop, returnedObjs.get("next_hop"));
55     }
56
57     @Test
58     public void removeInfo() {
59         // Arrange
60         String siteName = "UoR";
61         String ipPrefix = "16.101.233.2/8";
62         String switchPortId = "openflow:1:3";
63
64         Map<String, String> map = new HashMap<>();
65         map.put("ip_prefix", ipPrefix);
66         map.put("switch_port", switchPortId);
67
68         IntentMappingService mapSvc = mock(IntentMappingService.class);
69
70         MappingServiceManager manager = new MappingServiceManager(mapSvc);
71
72         // Add first to delete next
73         manager.add(siteName, ipPrefix, switchPortId, null, null);
74
75         // Act
76         boolean result = manager.delete(siteName);
77
78         // Assert
79         assertTrue(result);
80     }
81 }