blob: f43942ae4b3b03a78740469aa098e452cc6c4d00 [file] [log] [blame]
Thomas Vachuska48448082016-02-19 22:14:54 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Thomas Vachuska48448082016-02-19 22:14:54 -08003 *
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
17package org.onosproject.net.region;
18
19import com.google.common.collect.ImmutableList;
20import com.google.common.collect.ImmutableSet;
21import com.google.common.testing.EqualsTester;
22import org.junit.Test;
23import org.onosproject.cluster.NodeId;
Simon Hunt53612212016-12-04 17:19:52 -080024import org.onosproject.net.Annotations;
25import org.onosproject.net.DefaultAnnotations;
Thomas Vachuska48448082016-02-19 22:14:54 -080026
27import java.util.Set;
28
29import static org.junit.Assert.assertEquals;
30import static org.onosproject.cluster.NodeId.nodeId;
31import static org.onosproject.net.region.Region.Type.METRO;
32
33/**
34 * Suite of tests of the default region implementation.
35 */
36public class DefaultRegionTest {
37
38 private static final RegionId ID1 = RegionId.regionId("r1");
Simon Hunt53612212016-12-04 17:19:52 -080039 private static final Annotations NO_ANNOTS = DefaultAnnotations.EMPTY;
Thomas Vachuska48448082016-02-19 22:14:54 -080040
41 @Test
42 public void basics() {
Simon Hunt53612212016-12-04 17:19:52 -080043 ImmutableList<Set<NodeId>> masters =
44 ImmutableList.of(
45 ImmutableSet.of(nodeId("n1"), nodeId("n2")),
46 ImmutableSet.of(nodeId("n3"), nodeId("n4"))
47 );
48 Region r = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, masters);
Thomas Vachuska48448082016-02-19 22:14:54 -080049 assertEquals("incorrect id", ID1, r.id());
50 assertEquals("incorrect name", "R1", r.name());
51 assertEquals("incorrect type", METRO, r.type());
52 assertEquals("incorrect masters", masters, r.masters());
53 }
54
55 @Test
56 public void equality() {
Simon Hunt53612212016-12-04 17:19:52 -080057 Region a = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, null);
58 Region b = new DefaultRegion(ID1, "R1", METRO, NO_ANNOTS, null);
59 Region c = new DefaultRegion(ID1, "R2", METRO, NO_ANNOTS, null);
Thomas Vachuska48448082016-02-19 22:14:54 -080060
61 new EqualsTester().addEqualityGroup(a, b).addEqualityGroup(c).testEquals();
62 }
63
64}