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