Jon Hall | d543513 | 2017-04-04 17:19:16 -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 | d543513 | 2017-04-04 17:19:16 -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.collect.ImmutableSet; |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onosproject.net.provider.ProviderId; |
| 23 | |
| 24 | import static org.hamcrest.Matchers.contains; |
| 25 | import static org.hamcrest.Matchers.hasSize; |
| 26 | import static org.hamcrest.Matchers.is; |
Jordan Halterman | 00e92da | 2018-05-22 23:05:52 -0700 | [diff] [blame] | 27 | import static org.junit.Assert.assertThat; |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Unit tests for ClusterMetadata. |
| 31 | */ |
| 32 | public class ClusterMetadataTest { |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 33 | private final NodeId nid1 = NodeId.nodeId("10.0.0.1"); |
| 34 | private final NodeId nid2 = NodeId.nodeId("10.0.0.2"); |
| 35 | |
| 36 | private final ControllerNode n1 = |
| 37 | new DefaultControllerNode(nid1, IpAddress.valueOf("10.0.0.1"), 9876); |
| 38 | private final ControllerNode n2 = |
| 39 | new DefaultControllerNode(nid2, IpAddress.valueOf("10.0.0.2"), 9876); |
| 40 | |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 41 | private final ClusterMetadata metadata1 = |
Jordan Halterman | 19c123a | 2018-07-30 13:57:19 -0700 | [diff] [blame] | 42 | new ClusterMetadata("foo", n1, ImmutableSet.of(), ImmutableSet.of(n1)); |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 43 | private final ClusterMetadata sameAsMetadata1 = |
Jordan Halterman | 19c123a | 2018-07-30 13:57:19 -0700 | [diff] [blame] | 44 | new ClusterMetadata("foo", n1, ImmutableSet.of(), ImmutableSet.of(n1)); |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 45 | private final ClusterMetadata metadata2 = |
Jordan Halterman | 19c123a | 2018-07-30 13:57:19 -0700 | [diff] [blame] | 46 | new ClusterMetadata("bar", n1, ImmutableSet.of(n1), ImmutableSet.of(n1, n2)); |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 47 | private final ProviderId defaultProvider = |
| 48 | new ProviderId("none", "none"); |
| 49 | /** |
| 50 | * Tests for proper operation of equals(), hashCode() and toString() methods. |
| 51 | */ |
| 52 | @Test |
| 53 | public void checkEquals() { |
| 54 | new EqualsTester() |
| 55 | .addEqualityGroup(metadata1, sameAsMetadata1) |
| 56 | .addEqualityGroup(metadata2) |
| 57 | .testEquals(); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Tests that objects are created properly and accessor methods return |
| 62 | * the correct values. |
| 63 | */ |
| 64 | @Test |
| 65 | public void checkConstruction() { |
| 66 | assertThat(metadata2.getName(), is("bar")); |
Jordan Halterman | 19c123a | 2018-07-30 13:57:19 -0700 | [diff] [blame] | 67 | assertThat(metadata2.getControllerNodes(), hasSize(1)); |
| 68 | assertThat(metadata2.getControllerNodes(), contains(n1)); |
| 69 | assertThat(metadata2.getStorageNodes(), hasSize(2)); |
| 70 | assertThat(metadata2.getStorageNodes(), contains(n1, n2)); |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 71 | assertThat(metadata1.providerId(), is(defaultProvider)); |
Jon Hall | d543513 | 2017-04-04 17:19:16 -0700 | [diff] [blame] | 72 | } |
| 73 | } |