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