Jon Hall | b471f2c | 2017-04-05 09:07:39 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jon Hall | b471f2c | 2017-04-05 09:07:39 -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 | */ |
| 16 | package org.onosproject.cluster; |
| 17 | |
| 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | |
| 22 | import static org.hamcrest.Matchers.is; |
| 23 | import static org.junit.Assert.assertThat; |
| 24 | |
| 25 | /** |
| 26 | * Unit tests for the cluster event test. |
| 27 | */ |
| 28 | public class ClusterEventTest { |
| 29 | private final NodeId node1 = new NodeId("1"); |
| 30 | private final NodeId node2 = new NodeId("2"); |
| 31 | private final IpAddress ip1 = IpAddress.valueOf("10.0.0.1"); |
| 32 | private final IpAddress ip2 = IpAddress.valueOf("10.0.0.2"); |
| 33 | private final ControllerNode cNode1 = new DefaultControllerNode(node1, ip1); |
| 34 | private final ControllerNode cNode2 = new DefaultControllerNode(node2, ip2); |
| 35 | private final ClusterEvent event1 = |
| 36 | new ClusterEvent(ClusterEvent.Type.INSTANCE_ADDED, cNode1); |
| 37 | private final ClusterEvent event2 = |
| 38 | new ClusterEvent(ClusterEvent.Type.INSTANCE_REMOVED, cNode1); |
| 39 | private final ClusterEvent event3 = |
| 40 | new ClusterEvent(ClusterEvent.Type.INSTANCE_ACTIVATED, cNode1); |
| 41 | private final ClusterEvent event4 = |
| 42 | new ClusterEvent(ClusterEvent.Type.INSTANCE_READY, cNode1); |
| 43 | private final ClusterEvent event5 = |
| 44 | new ClusterEvent(ClusterEvent.Type.INSTANCE_DEACTIVATED, cNode1); |
| 45 | private final ClusterEvent event6 = |
| 46 | new ClusterEvent(ClusterEvent.Type.INSTANCE_ADDED, cNode2); |
| 47 | private final long time = System.currentTimeMillis(); |
| 48 | private final ClusterEvent event7 = |
| 49 | new ClusterEvent(ClusterEvent.Type.INSTANCE_READY, cNode2, time); |
| 50 | private final ClusterEvent sameAsEvent7 = |
| 51 | new ClusterEvent(ClusterEvent.Type.INSTANCE_READY, cNode2, time); |
| 52 | |
| 53 | /** |
| 54 | * Tests for proper operation of equals(), hashCode() and toString() methods. |
| 55 | */ |
| 56 | @Test |
| 57 | public void checkEquals() { |
| 58 | new EqualsTester() |
| 59 | .addEqualityGroup(event1) |
| 60 | .addEqualityGroup(event2) |
| 61 | .addEqualityGroup(event3) |
| 62 | .addEqualityGroup(event4) |
| 63 | .addEqualityGroup(event5) |
| 64 | .addEqualityGroup(event6) |
| 65 | .addEqualityGroup(event7, sameAsEvent7) |
| 66 | .testEquals(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Tests that objects are created properly. |
| 71 | */ |
| 72 | @Test |
| 73 | public void checkConstruction() { |
| 74 | assertThat(event1.type(), is(ClusterEvent.Type.INSTANCE_ADDED)); |
| 75 | assertThat(event1.subject(), is(cNode1)); |
| 76 | |
| 77 | assertThat(event7.time(), is(time)); |
| 78 | assertThat(event7.type(), is(ClusterEvent.Type.INSTANCE_READY)); |
| 79 | assertThat(event7.subject(), is(cNode2)); |
| 80 | } |
| 81 | |
| 82 | } |