blob: 9fa38935142fead3aee4875c66aced46469599fa [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey85267002016-11-16 11:06:35 -08003 *
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 */
Ray Milkeydbf59f02016-08-19 12:54:16 -070016package org.onosproject.net.device;
17
18import org.junit.Test;
19import org.onosproject.net.PortNumber;
20
21import com.google.common.testing.EqualsTester;
22
23import static org.hamcrest.MatcherAssert.assertThat;
24import static org.hamcrest.Matchers.is;
25import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutableBaseClass;
26import static org.onosproject.net.Port.Type.COPPER;
27
28/**
29 * Unit tests for the DefaultPortDescription test.
30 */
31public class DefaultPortDescriptionTest {
32
33 private static PortNumber port1 = PortNumber.portNumber(1);
34 private static long portSpeed1 = 111L;
35 private static DefaultPortDescription portDescription1 =
Yuta HIGUCHI53e47962018-03-01 23:50:48 -080036 DefaultPortDescription.builder().withPortNumber(port1).isEnabled(true)
37 .type(COPPER).portSpeed(portSpeed1).build();
Ray Milkeydbf59f02016-08-19 12:54:16 -070038
39 private static DefaultPortDescription sameAsPortDescription1 =
Yuta HIGUCHI53e47962018-03-01 23:50:48 -080040 DefaultPortDescription.builder(portDescription1)
41 .annotations(portDescription1.annotations())
42 .build();
Ray Milkeydbf59f02016-08-19 12:54:16 -070043
44 private static PortNumber port2 = PortNumber.portNumber(2);
45 private static DefaultPortDescription portDescription2 =
Yuta HIGUCHI53e47962018-03-01 23:50:48 -080046 DefaultPortDescription.builder().withPortNumber(port2).isEnabled(true).build();
Ray Milkeydbf59f02016-08-19 12:54:16 -070047
48 private static DefaultPortDescription portDescription3 =
49 new DefaultPortDescription();
50 /**
51 * Tests the immutability of {@link DefaultPortDescription}.
52 */
53 @Test
54 public void testImmutable() {
55 assertThatClassIsImmutableBaseClass(DefaultPortDescription.class);
56 }
57
58 /**
59 * Tests object construction and fetching of member data.
60 */
61 @Test
62 public void testConstruction() {
63 assertThat(portDescription1.portNumber(), is(port1));
64 assertThat(portDescription1.isEnabled(), is(true));
65 assertThat(portDescription1.portSpeed(), is(portSpeed1));
66 assertThat(portDescription1.type(), is(COPPER));
67 }
68
69 /**
70 * Tests equals(), hashCode(), and toString() methods.
71 */
72 @Test
73 public void testEquals() {
74 new EqualsTester()
75 .addEqualityGroup(portDescription1, sameAsPortDescription1)
76 .addEqualityGroup(portDescription2)
77 .addEqualityGroup(portDescription3)
78 .testEquals();
79 }
80}