blob: 8594eb88fdd4b9ee32940ba538ed88e51309bc46 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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.mastership;
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -070017
18import static org.junit.Assert.assertEquals;
Ray Milkeya16ea652015-07-22 13:25:55 -070019import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -070020
21import org.junit.Test;
Brian O'Connorabafb502014-12-02 22:26:20 -080022import org.onosproject.cluster.NodeId;
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -070023
24import com.google.common.testing.EqualsTester;
25
26public class MastershipTermTest {
27
28 private static final NodeId N1 = new NodeId("foo");
29 private static final NodeId N2 = new NodeId("bar");
30
31 private static final MastershipTerm TERM1 = MastershipTerm.of(N1, 0);
32 private static final MastershipTerm TERM2 = MastershipTerm.of(N2, 1);
33 private static final MastershipTerm TERM3 = MastershipTerm.of(N2, 1);
34 private static final MastershipTerm TERM4 = MastershipTerm.of(N1, 1);
35
36 @Test
37 public void basics() {
38 assertEquals("incorrect term number", 0, TERM1.termNumber());
39 assertEquals("incorrect master", new NodeId("foo"), TERM1.master());
40 }
41
42 @Test
43 public void testEquality() {
44 new EqualsTester().addEqualityGroup(MastershipTerm.of(N1, 0), TERM1)
45 .addEqualityGroup(TERM2, TERM3)
Ray Milkeya16ea652015-07-22 13:25:55 -070046 .addEqualityGroup(TERM4)
47 .testEquals();
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -070048 }
49
Ray Milkeya16ea652015-07-22 13:25:55 -070050 /**
51 * Checks that the MembershipTerm class is immutable.
52 */
53 @Test
54 public void testImmutability() {
55 assertThatClassIsImmutable(MastershipTerm.class);
56 }
Ayaka Koshibe3de43ca2014-09-26 16:40:23 -070057}