blob: 56f7a477507872baa9718e28ed0bfd75cf6cd6fd [file] [log] [blame]
Ray Milkey0bc05992015-03-17 15:14:07 -07001/*
2 * Copyright 2015 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.net.resource;
17
18import org.junit.Test;
19
20import com.google.common.testing.EqualsTester;
Brian O'Connor6de2e202015-05-21 14:30:41 -070021import org.onosproject.net.resource.link.MplsLabel;
22import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
Ray Milkey0bc05992015-03-17 15:14:07 -070023
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.is;
26
27/**
28 * Unit tests for MPLS objects.
29 */
30public class MplsObjectsTest {
31
32 MplsLabel label1 = MplsLabel.valueOf(1);
33 MplsLabel label2 = MplsLabel.valueOf(2);
34 MplsLabel sameAsLabel1 = MplsLabel.valueOf(1);
35 MplsLabel sameAsLabel2 = MplsLabel.valueOf(2);
36 MplsLabel label3 = MplsLabel.valueOf(3);
37
38 /**
39 * Tests creation of MPLS label objects.
40 */
41 @Test
42 public void checkLabelConstruction() {
43 assertThat(label1.label().toInt(), is(1));
44 }
45
46 /**
47 * Tests the operation of equals(), hashCode() and toString().
48 */
49 @Test
50 public void testLabelEqualsOperation() {
51 new EqualsTester()
52 .addEqualityGroup(label1, sameAsLabel1)
53 .addEqualityGroup(label2, sameAsLabel2)
54 .addEqualityGroup(label3)
55 .testEquals();
56 }
57
58 MplsLabelResourceAllocation labelAllocation1 =
59 new MplsLabelResourceAllocation(label1);
60 MplsLabelResourceAllocation sameAsLabelAllocation1 =
61 new MplsLabelResourceAllocation(label1);
62 MplsLabelResourceAllocation labelAllocation2 =
63 new MplsLabelResourceAllocation(label2);
64 MplsLabelResourceAllocation sameAsLabelAllocation2 =
65 new MplsLabelResourceAllocation(label2);
66 MplsLabelResourceAllocation labelAllocation3 =
67 new MplsLabelResourceAllocation(label3);
68
69 /**
70 * Tests creation of MPLS label objects.
71 */
72 @Test
73 public void checkLabelResourceAllocationConstruction() {
74 assertThat(labelAllocation1.mplsLabel().label().toInt(), is(1));
75 assertThat(labelAllocation1.type(), is(ResourceType.MPLS_LABEL));
76 }
77
78 /**
79 * Tests the operation of equals(), hashCode() and toString().
80 */
81 @Test
82 public void testLabelResourceAllocationEqualsOperation() {
83 new EqualsTester()
84 .addEqualityGroup(labelAllocation1, sameAsLabelAllocation1)
85 .addEqualityGroup(labelAllocation2, sameAsLabelAllocation2)
86 .addEqualityGroup(labelAllocation3)
87 .testEquals();
88 }
89}