Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
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.mastership; |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
Ray Milkey | a16ea65 | 2015-07-22 13:25:55 -0700 | [diff] [blame] | 19 | import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable; |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 20 | |
| 21 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.cluster.NodeId; |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 23 | |
| 24 | import com.google.common.testing.EqualsTester; |
| 25 | |
| 26 | public 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 Milkey | a16ea65 | 2015-07-22 13:25:55 -0700 | [diff] [blame] | 46 | .addEqualityGroup(TERM4) |
| 47 | .testEquals(); |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Ray Milkey | a16ea65 | 2015-07-22 13:25:55 -0700 | [diff] [blame] | 50 | /** |
| 51 | * Checks that the MembershipTerm class is immutable. |
| 52 | */ |
| 53 | @Test |
| 54 | public void testImmutability() { |
| 55 | assertThatClassIsImmutable(MastershipTerm.class); |
| 56 | } |
Ayaka Koshibe | 3de43ca | 2014-09-26 16:40:23 -0700 | [diff] [blame] | 57 | } |