Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 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 | */ |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 16 | package org.onosproject.pcelabelstore; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 17 | |
| 18 | import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | import static org.hamcrest.Matchers.is; |
| 20 | |
| 21 | import com.google.common.testing.EqualsTester; |
| 22 | |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 25 | import org.onosproject.net.DeviceId; |
| 26 | import org.onosproject.net.PortNumber; |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 27 | import org.onosproject.pcelabelstore.api.LspLocalLabelInfo; |
Mahesh Poojary S | ba82729 | 2016-05-09 11:31:12 +0530 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Unit tests for DefaultLspLocalLabelInfo class. |
| 31 | */ |
| 32 | public class DefaultLspLocalLabelInfoTest { |
| 33 | |
| 34 | /** |
| 35 | * Checks the operation of equals() methods. |
| 36 | */ |
| 37 | @Test |
| 38 | public void testEquals() { |
| 39 | // create same two objects. |
| 40 | DeviceId deviceId1 = DeviceId.deviceId("foo"); |
| 41 | LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1); |
| 42 | LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2); |
| 43 | PortNumber inPort1 = PortNumber.portNumber(5122); |
| 44 | PortNumber outPort1 = PortNumber.portNumber(5123); |
| 45 | |
| 46 | LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder() |
| 47 | .deviceId(deviceId1) |
| 48 | .inLabelId(inLabelId1) |
| 49 | .outLabelId(outLabelId1) |
| 50 | .inPort(inPort1) |
| 51 | .outPort(outPort1) |
| 52 | .build(); |
| 53 | |
| 54 | // create same object as above object |
| 55 | LspLocalLabelInfo sameLocalLabel1 = DefaultLspLocalLabelInfo.builder() |
| 56 | .deviceId(deviceId1) |
| 57 | .inLabelId(inLabelId1) |
| 58 | .outLabelId(outLabelId1) |
| 59 | .inPort(inPort1) |
| 60 | .outPort(outPort1) |
| 61 | .build(); |
| 62 | |
| 63 | // Create different object. |
| 64 | DeviceId deviceId2 = DeviceId.deviceId("goo"); |
| 65 | LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3); |
| 66 | LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4); |
| 67 | PortNumber inPort2 = PortNumber.portNumber(5124); |
| 68 | PortNumber outPort2 = PortNumber.portNumber(5125); |
| 69 | |
| 70 | LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder() |
| 71 | .deviceId(deviceId2) |
| 72 | .inLabelId(inLabelId2) |
| 73 | .outLabelId(outLabelId2) |
| 74 | .inPort(inPort2) |
| 75 | .outPort(outPort2) |
| 76 | .build(); |
| 77 | |
| 78 | new EqualsTester().addEqualityGroup(lspLocalLabel1, sameLocalLabel1) |
| 79 | .addEqualityGroup(lspLocalLabel2) |
| 80 | .testEquals(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Checks the construction of a DefaultLspLocalLabelInfo object. |
| 85 | */ |
| 86 | @Test |
| 87 | public void testConstruction() { |
| 88 | DeviceId deviceId = DeviceId.deviceId("foo"); |
| 89 | LabelResourceId inLabelId = LabelResourceId.labelResourceId(1); |
| 90 | LabelResourceId outLabelId = LabelResourceId.labelResourceId(2); |
| 91 | PortNumber inPort = PortNumber.portNumber(5122); |
| 92 | PortNumber outPort = PortNumber.portNumber(5123); |
| 93 | |
| 94 | LspLocalLabelInfo lspLocalLabel = DefaultLspLocalLabelInfo.builder() |
| 95 | .deviceId(deviceId) |
| 96 | .inLabelId(inLabelId) |
| 97 | .outLabelId(outLabelId) |
| 98 | .inPort(inPort) |
| 99 | .outPort(outPort) |
| 100 | .build(); |
| 101 | |
| 102 | assertThat(deviceId, is(lspLocalLabel.deviceId())); |
| 103 | assertThat(inLabelId, is(lspLocalLabel.inLabelId())); |
| 104 | assertThat(outLabelId, is(lspLocalLabel.outLabelId())); |
| 105 | assertThat(inPort, is(lspLocalLabel.inPort())); |
| 106 | assertThat(outPort, is(lspLocalLabel.outPort())); |
| 107 | } |
| 108 | } |