Committed by
Gerrit Code Review
Seeding a test for the edge-manager implementation.
Change-Id: I6743aae85eab1444bcafcc2f1d8514cc2c2a5bc0
Showing
2 changed files
with
128 additions
and
1 deletions
... | @@ -181,7 +181,7 @@ public class EdgeManager implements EdgePortService { | ... | @@ -181,7 +181,7 @@ public class EdgeManager implements EdgePortService { |
181 | 181 | ||
182 | // Initial loading of the edge port cache. | 182 | // Initial loading of the edge port cache. |
183 | private void loadAllEdgePorts() { | 183 | private void loadAllEdgePorts() { |
184 | - deviceService.getDevices().forEach(d -> deviceService.getPorts(d.id()) | 184 | + deviceService.getAvailableDevices().forEach(d -> deviceService.getPorts(d.id()) |
185 | .forEach(p -> addEdgePort(new ConnectPoint(d.id(), p.number())))); | 185 | .forEach(p -> addEdgePort(new ConnectPoint(d.id(), p.number())))); |
186 | } | 186 | } |
187 | 187 | ... | ... |
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.net.edgeservice.impl; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.common.event.impl.TestEventDispatcher; | ||
22 | +import org.onosproject.net.ConnectPoint; | ||
23 | +import org.onosproject.net.Device; | ||
24 | +import org.onosproject.net.DeviceId; | ||
25 | +import org.onosproject.net.Port; | ||
26 | +import org.onosproject.net.device.DeviceServiceAdapter; | ||
27 | +import org.onosproject.net.edge.EdgePortEvent; | ||
28 | +import org.onosproject.net.edge.EdgePortListener; | ||
29 | +import org.onosproject.net.packet.PacketServiceAdapter; | ||
30 | +import org.onosproject.net.topology.Topology; | ||
31 | +import org.onosproject.net.topology.TopologyListener; | ||
32 | +import org.onosproject.net.topology.TopologyServiceAdapter; | ||
33 | + | ||
34 | +import java.util.List; | ||
35 | +import java.util.Set; | ||
36 | + | ||
37 | +import static org.junit.Assert.assertFalse; | ||
38 | + | ||
39 | +/** | ||
40 | + * Test of the edge port manager. | ||
41 | + */ | ||
42 | +public class EdgeManagerTest { | ||
43 | + | ||
44 | + private EdgeManager mgr; | ||
45 | + private final EdgePortListener testListener = new TestListener(); | ||
46 | + | ||
47 | + | ||
48 | + @Before | ||
49 | + public void setUp() { | ||
50 | + mgr = new EdgeManager(); | ||
51 | + mgr.eventDispatcher = new TestEventDispatcher(); | ||
52 | + mgr.topologyService = new TestTopologyManager(); | ||
53 | + mgr.deviceService = new TestDeviceManager(); | ||
54 | + mgr.packetService = new TestPacketManager(); | ||
55 | + mgr.activate(); | ||
56 | + mgr.addListener(testListener); | ||
57 | + } | ||
58 | + | ||
59 | + @After | ||
60 | + public void tearDown() { | ||
61 | + mgr.removeListener(testListener); | ||
62 | + mgr.deactivate(); | ||
63 | + } | ||
64 | + | ||
65 | + @Test | ||
66 | + public void basics() { | ||
67 | + assertFalse("no ports expected", mgr.getEdgePoints().iterator().hasNext()); | ||
68 | + } | ||
69 | + | ||
70 | + private class TestTopologyManager extends TopologyServiceAdapter { | ||
71 | + private TopologyListener listener; | ||
72 | + private Set<ConnectPoint> infrastructurePorts; | ||
73 | + | ||
74 | + @Override | ||
75 | + public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) { | ||
76 | + return infrastructurePorts.contains(connectPoint); | ||
77 | + } | ||
78 | + | ||
79 | + @Override | ||
80 | + public void addListener(TopologyListener listener) { | ||
81 | + this.listener = listener; | ||
82 | + } | ||
83 | + | ||
84 | + @Override | ||
85 | + public void removeListener(TopologyListener listener) { | ||
86 | + this.listener = null; | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | + private class TestDeviceManager extends DeviceServiceAdapter { | ||
91 | + | ||
92 | + private Set<Device> devices; | ||
93 | + | ||
94 | + @Override | ||
95 | + public boolean isAvailable(DeviceId deviceId) { | ||
96 | + for (Device device : devices) { | ||
97 | + if (device.id().equals(deviceId)) { | ||
98 | + return true; | ||
99 | + } | ||
100 | + } | ||
101 | + return false; | ||
102 | + } | ||
103 | + | ||
104 | + @Override | ||
105 | + public List<Port> getPorts(DeviceId deviceId) { | ||
106 | + return super.getPorts(deviceId); | ||
107 | + } | ||
108 | + | ||
109 | + @Override | ||
110 | + public Iterable<Device> getAvailableDevices() { | ||
111 | + return devices; | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + private class TestPacketManager extends PacketServiceAdapter { | ||
116 | + } | ||
117 | + | ||
118 | + | ||
119 | + private class TestListener implements EdgePortListener { | ||
120 | + private List<EdgePortEvent> events; | ||
121 | + | ||
122 | + @Override | ||
123 | + public void event(EdgePortEvent event) { | ||
124 | + events.add(event); | ||
125 | + } | ||
126 | + } | ||
127 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment