blob: 3d86d937a3322df65b9d3e22dc2bd288b9484b68 [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;
Jordan Halterman07f052b2017-10-08 14:22:41 -070022import org.onosproject.core.Version;
Jon Halld5435132017-04-04 17:19:16 -070023import org.onosproject.net.provider.ProviderId;
24
25import static org.hamcrest.Matchers.contains;
26import static org.hamcrest.Matchers.hasSize;
27import static org.hamcrest.Matchers.is;
28import static org.junit.Assert.*;
29
30/**
31 * Unit tests for ClusterMetadata.
32 */
33public class ClusterMetadataTest {
34 private final PartitionId pid1 = PartitionId.from(1);
35 private final PartitionId pid2 = PartitionId.from(2);
36
37 private final NodeId nid1 = NodeId.nodeId("10.0.0.1");
38 private final NodeId nid2 = NodeId.nodeId("10.0.0.2");
39
40 private final ControllerNode n1 =
41 new DefaultControllerNode(nid1, IpAddress.valueOf("10.0.0.1"), 9876);
42 private final ControllerNode n2 =
43 new DefaultControllerNode(nid2, IpAddress.valueOf("10.0.0.2"), 9876);
44
Jordan Halterman07f052b2017-10-08 14:22:41 -070045 private final Partition p1 = new DefaultPartition(pid1, Version.version("1.0.0"), ImmutableSet.of(nid1));
46 private final Partition p2 = new DefaultPartition(pid2, Version.version("1.0.0"), ImmutableSet.of(nid1, nid2));
Jon Halld5435132017-04-04 17:19:16 -070047
48 private final ClusterMetadata metadata1 =
49 new ClusterMetadata("foo", ImmutableSet.of(n1), ImmutableSet.of(p1));
50 private final ClusterMetadata sameAsMetadata1 =
51 new ClusterMetadata("foo", ImmutableSet.of(n1), ImmutableSet.of(p1));
52 private final ClusterMetadata metadata2 =
53 new ClusterMetadata("bar", ImmutableSet.of(n1, n2), ImmutableSet.of(p1, p2));
54 private final ProviderId defaultProvider =
55 new ProviderId("none", "none");
56 /**
57 * Tests for proper operation of equals(), hashCode() and toString() methods.
58 */
59 @Test
60 public void checkEquals() {
61 new EqualsTester()
62 .addEqualityGroup(metadata1, sameAsMetadata1)
63 .addEqualityGroup(metadata2)
64 .testEquals();
65 }
66
67 /**
68 * Tests that objects are created properly and accessor methods return
69 * the correct values.
70 */
71 @Test
72 public void checkConstruction() {
73 assertThat(metadata2.getName(), is("bar"));
74 assertThat(metadata2.getNodes(), hasSize(2));
75 assertThat(metadata2.getNodes(), contains(n1, n2));
76 assertThat(metadata2.getPartitions(), hasSize(2));
77 assertThat(metadata2.getPartitions(), contains(p1, p2));
78 assertThat(metadata1.providerId(), is(defaultProvider));
79
80 }
81}