Thomas Vachuska | 4844808 | 2016-02-19 22:14:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014-2016 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 | |
| 17 | package org.onosproject.net.region; |
| 18 | |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.ImmutableSet; |
| 21 | import com.google.common.testing.EqualsTester; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.cluster.NodeId; |
| 24 | |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static org.junit.Assert.assertEquals; |
| 28 | import static org.onosproject.cluster.NodeId.nodeId; |
| 29 | import static org.onosproject.net.region.Region.Type.METRO; |
| 30 | |
| 31 | /** |
| 32 | * Suite of tests of the default region implementation. |
| 33 | */ |
| 34 | public class DefaultRegionTest { |
| 35 | |
| 36 | private static final RegionId ID1 = RegionId.regionId("r1"); |
| 37 | |
| 38 | @Test |
| 39 | public void basics() { |
| 40 | ImmutableList<Set<NodeId>> masters = ImmutableList |
| 41 | .of(ImmutableSet.of(nodeId("n1"), nodeId("n2")), |
| 42 | ImmutableSet.of(nodeId("n3"), nodeId("n4"))); |
| 43 | Region r = new DefaultRegion(ID1, "R1", METRO, masters); |
| 44 | assertEquals("incorrect id", ID1, r.id()); |
| 45 | assertEquals("incorrect name", "R1", r.name()); |
| 46 | assertEquals("incorrect type", METRO, r.type()); |
| 47 | assertEquals("incorrect masters", masters, r.masters()); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void equality() { |
| 52 | Region a = new DefaultRegion(ID1, "R1", METRO, null); |
| 53 | Region b = new DefaultRegion(ID1, "R1", METRO, null); |
| 54 | Region c = new DefaultRegion(ID1, "R2", METRO, null); |
| 55 | |
| 56 | new EqualsTester().addEqualityGroup(a, b).addEqualityGroup(c).testEquals(); |
| 57 | } |
| 58 | |
| 59 | } |