blob: 04077eafad1f1d89acd3ce092b675a5511e634c3 [file] [log] [blame]
Jon Halld5435132017-04-04 17:19:16 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jon Halld5435132017-04-04 17:19:16 -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 */
16package org.onosproject.cluster;
17
18import com.google.common.collect.ImmutableSet;
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22import org.onosproject.net.provider.ProviderId;
23
24import static org.hamcrest.Matchers.contains;
25import static org.hamcrest.Matchers.hasSize;
26import static org.hamcrest.Matchers.is;
Jordan Halterman00e92da2018-05-22 23:05:52 -070027import static org.junit.Assert.assertThat;
Jon Halld5435132017-04-04 17:19:16 -070028
29/**
30 * Unit tests for ClusterMetadata.
31 */
32public class ClusterMetadataTest {
Jon Halld5435132017-04-04 17:19:16 -070033 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 Halld5435132017-04-04 17:19:16 -070041 private final ClusterMetadata metadata1 =
Samuel Jero31e16f52018-09-21 10:34:28 -040042 new ClusterMetadata("foo", n1, ImmutableSet.of(), ImmutableSet.of(n1), "");
Jon Halld5435132017-04-04 17:19:16 -070043 private final ClusterMetadata sameAsMetadata1 =
Samuel Jero31e16f52018-09-21 10:34:28 -040044 new ClusterMetadata("foo", n1, ImmutableSet.of(), ImmutableSet.of(n1), "");
Jon Halld5435132017-04-04 17:19:16 -070045 private final ClusterMetadata metadata2 =
Samuel Jero31e16f52018-09-21 10:34:28 -040046 new ClusterMetadata("bar", n1, ImmutableSet.of(n1), ImmutableSet.of(n1, n2), "");
Jon Halld5435132017-04-04 17:19:16 -070047 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 Halterman19c123a2018-07-30 13:57:19 -070067 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 Halld5435132017-04-04 17:19:16 -070071 assertThat(metadata1.providerId(), is(defaultProvider));
Jon Halld5435132017-04-04 17:19:16 -070072 }
73}