2 * Copyright (c) 2016 Inocybe Technologies and others. All rights reserved.
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
9 package org.opendaylight.vpnservice.impl;
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;
17 import java.util.HashMap;
20 import org.junit.Test;
21 import org.opendaylight.nic.mapping.api.IntentMappingService;
23 public class MappingServiceManagerTests {
26 public void addInfo() {
28 String siteName = "UoR";
29 String ipPrefix = "16.101.233.2/8";
30 String switchPortId = "openflow:1:3";
32 String nextHop = "16.101.233.1/8";
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);
40 IntentMappingService mapSvc = mock(IntentMappingService.class);
41 when(mapSvc.get(any(String.class))).thenReturn(map);
43 MappingServiceManager manager = new MappingServiceManager(mapSvc);
46 manager.add(siteName, ipPrefix, switchPortId, mplsLabel, nextHop);
48 Map<String, String> returnedObjs = manager.get(siteName);
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"));
58 public void removeInfo() {
60 String siteName = "UoR";
61 String ipPrefix = "16.101.233.2/8";
62 String switchPortId = "openflow:1:3";
64 Map<String, String> map = new HashMap<>();
65 map.put("ip_prefix", ipPrefix);
66 map.put("switch_port", switchPortId);
68 IntentMappingService mapSvc = mock(IntentMappingService.class);
70 MappingServiceManager manager = new MappingServiceManager(mapSvc);
72 // Add first to delete next
73 manager.add(siteName, ipPrefix, switchPortId, null, null);
76 boolean result = manager.delete(siteName);