blob: 0b4d1ef602dc87ee1428d959ededdd8086156f38 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.cluster;
Yuta HIGUCHIdc7374c2014-10-10 11:11:09 -070017
Yuta HIGUCHIb35a3812014-10-15 23:22:17 -070018import static com.google.common.base.Predicates.notNull;
Yuta HIGUCHIdc7374c2014-10-10 11:11:09 -070019import static org.junit.Assert.*;
Brian O'Connorabafb502014-12-02 22:26:20 -080020import static org.onosproject.cluster.ControllerNodeToNodeId.toNodeId;
Yuta HIGUCHIdc7374c2014-10-10 11:11:09 -070021
22import java.util.Arrays;
23import java.util.List;
24
25import org.junit.Test;
Pavlin Radoslavov444b5192014-10-28 10:45:19 -070026import org.onlab.packet.IpAddress;
Yuta HIGUCHIdc7374c2014-10-10 11:11:09 -070027
28import com.google.common.collect.FluentIterable;
29
30
31public 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 Radoslavov444b5192014-10-28 10:45:19 -070037 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 HIGUCHIdc7374c2014-10-10 11:11:09 -070040
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 HIGUCHIb35a3812014-10-15 23:22:17 -070049 final Iterable<ControllerNode> nodes = Arrays.asList(CN1, CN2, CN3, null);
Yuta HIGUCHIdc7374c2014-10-10 11:11:09 -070050 final List<NodeId> nodeIds = Arrays.asList(NID1, NID2, NID3);
51
52 assertEquals(nodeIds,
53 FluentIterable.from(nodes)
54 .transform(toNodeId())
Yuta HIGUCHIb35a3812014-10-15 23:22:17 -070055 .filter(notNull())
Yuta HIGUCHIdc7374c2014-10-10 11:11:09 -070056 .toList());
57 }
58
59}