Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 1 | package org.onlab.onos.cluster; |
| 2 | |
Yuta HIGUCHI | b35a381 | 2014-10-15 23:22:17 -0700 | [diff] [blame] | 3 | import static com.google.common.base.Predicates.notNull; |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 4 | import static org.junit.Assert.*; |
| 5 | import static org.onlab.onos.cluster.ControllerNodeToNodeId.toNodeId; |
| 6 | |
| 7 | import java.util.Arrays; |
| 8 | import java.util.List; |
| 9 | |
| 10 | import org.junit.Test; |
| 11 | import org.onlab.packet.IpPrefix; |
| 12 | |
| 13 | import com.google.common.collect.FluentIterable; |
| 14 | |
| 15 | |
| 16 | public class ControllerNodeToNodeIdTest { |
| 17 | |
| 18 | private static final NodeId NID1 = new NodeId("foo"); |
| 19 | private static final NodeId NID2 = new NodeId("bar"); |
| 20 | private static final NodeId NID3 = new NodeId("buz"); |
| 21 | |
| 22 | private static final IpPrefix IP1 = IpPrefix.valueOf("127.0.0.1"); |
| 23 | private static final IpPrefix IP2 = IpPrefix.valueOf("127.0.0.2"); |
| 24 | private static final IpPrefix IP3 = IpPrefix.valueOf("127.0.0.3"); |
| 25 | |
| 26 | private static final ControllerNode CN1 = new DefaultControllerNode(NID1, IP1); |
| 27 | private static final ControllerNode CN2 = new DefaultControllerNode(NID2, IP2); |
| 28 | private static final ControllerNode CN3 = new DefaultControllerNode(NID3, IP3); |
| 29 | |
| 30 | |
| 31 | @Test |
| 32 | public final void testToNodeId() { |
| 33 | |
Yuta HIGUCHI | b35a381 | 2014-10-15 23:22:17 -0700 | [diff] [blame] | 34 | final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3, null); |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 35 | final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3); |
| 36 | |
| 37 | assertEquals(nodeIds, |
| 38 | FluentIterable.from(nodes) |
| 39 | .transform(toNodeId()) |
Yuta HIGUCHI | b35a381 | 2014-10-15 23:22:17 -0700 | [diff] [blame] | 40 | .filter(notNull()) |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 41 | .toList()); |
| 42 | } |
| 43 | |
| 44 | } |