Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.cluster; |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 17 | |
Yuta HIGUCHI | b35a381 | 2014-10-15 23:22:17 -0700 | [diff] [blame] | 18 | import static com.google.common.base.Predicates.notNull; |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 19 | import static org.junit.Assert.*; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 20 | import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId; |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 21 | |
| 22 | import java.util.Arrays; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import org.junit.Test; |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 26 | import org.onlab.packet.IpAddress; |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 27 | |
| 28 | import com.google.common.collect.FluentIterable; |
| 29 | |
| 30 | |
| 31 | public class ControllerNodeToNodeIdTest { |
| 32 | |
| 33 | private static final NodeId NID1 = new NodeId("foo"); |
| 34 | private static final NodeId NID2 = new NodeId("bar"); |
| 35 | private static final NodeId NID3 = new NodeId("buz"); |
| 36 | |
Pavlin Radoslavov | 444b519 | 2014-10-28 10:45:19 -0700 | [diff] [blame] | 37 | private static final IpAddress IP1 = IpAddress.valueOf("127.0.0.1"); |
| 38 | private static final IpAddress IP2 = IpAddress.valueOf("127.0.0.2"); |
| 39 | private static final IpAddress IP3 = IpAddress.valueOf("127.0.0.3"); |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 40 | |
| 41 | private static final ControllerNode CN1 = new DefaultControllerNode(NID1, IP1); |
| 42 | private static final ControllerNode CN2 = new DefaultControllerNode(NID2, IP2); |
| 43 | private static final ControllerNode CN3 = new DefaultControllerNode(NID3, IP3); |
| 44 | |
| 45 | |
| 46 | @Test |
| 47 | public final void testToNodeId() { |
| 48 | |
Yuta HIGUCHI | b35a381 | 2014-10-15 23:22:17 -0700 | [diff] [blame] | 49 | final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3, null); |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 50 | final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3); |
| 51 | |
| 52 | assertEquals(nodeIds, |
| 53 | FluentIterable.from(nodes) |
| 54 | .transform(toNodeId()) |
Yuta HIGUCHI | b35a381 | 2014-10-15 23:22:17 -0700 | [diff] [blame] | 55 | .filter(notNull()) |
Yuta HIGUCHI | dc7374c | 2014-10-10 11:11:09 -0700 | [diff] [blame] | 56 | .toList()); |
| 57 | } |
| 58 | |
| 59 | } |