Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-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 | */ |
| 16 | package org.onosproject.pce.pcestore; |
| 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 java.util.List; |
| 24 | import java.util.LinkedList; |
| 25 | |
| 26 | import org.junit.Test; |
| 27 | import org.onlab.util.DataRateUnit; |
| 28 | import org.onosproject.net.DeviceId; |
| 29 | import org.onosproject.net.intent.Constraint; |
| 30 | import org.onosproject.net.intent.constraint.BandwidthConstraint; |
| 31 | import org.onosproject.pce.pceservice.LspType; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for PcePathInfo class. |
| 35 | */ |
| 36 | public class PcePathInfoTest { |
| 37 | |
| 38 | /** |
| 39 | * Checks the operation of equals() methods. |
| 40 | */ |
| 41 | @Test |
| 42 | public void testEquals() { |
| 43 | // create same two objects. |
| 44 | DeviceId src1 = DeviceId.deviceId("foo1"); |
| 45 | DeviceId dst1 = DeviceId.deviceId("goo1"); |
| 46 | String name1 = "pcc1"; |
| 47 | LspType lspType1 = LspType.WITH_SIGNALLING; |
| 48 | List<Constraint> constraints1 = new LinkedList<>(); |
| 49 | Constraint bandwidth11 = BandwidthConstraint.of(100, DataRateUnit.BPS); |
| 50 | constraints1.add(bandwidth11); |
| 51 | Constraint bandwidth12 = BandwidthConstraint.of(200, DataRateUnit.BPS); |
| 52 | constraints1.add(bandwidth12); |
| 53 | Constraint bandwidth13 = BandwidthConstraint.of(300, DataRateUnit.BPS); |
| 54 | constraints1.add(bandwidth13); |
| 55 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame^] | 56 | PcePathInfo pathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 57 | |
| 58 | // create same object as above object |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame^] | 59 | PcePathInfo samePathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 60 | |
| 61 | // Create different object. |
| 62 | DeviceId src2 = DeviceId.deviceId("foo2"); |
| 63 | DeviceId dst2 = DeviceId.deviceId("goo2"); |
| 64 | String name2 = "pcc2"; |
| 65 | LspType lspType2 = LspType.SR_WITHOUT_SIGNALLING; |
| 66 | List<Constraint> constraints2 = new LinkedList<>(); |
| 67 | Constraint bandwidth21 = BandwidthConstraint.of(400, DataRateUnit.BPS); |
| 68 | constraints2.add(bandwidth21); |
| 69 | Constraint bandwidth22 = BandwidthConstraint.of(800, DataRateUnit.BPS); |
| 70 | constraints2.add(bandwidth22); |
| 71 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame^] | 72 | PcePathInfo pathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 73 | |
| 74 | new EqualsTester().addEqualityGroup(pathInfo1, samePathInfo1) |
| 75 | .addEqualityGroup(pathInfo2) |
| 76 | .testEquals(); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Checks the construction of a PcePathInfo object. |
| 81 | */ |
| 82 | @Test |
| 83 | public void testConstruction() { |
| 84 | DeviceId src = DeviceId.deviceId("foo2"); |
| 85 | DeviceId dst = DeviceId.deviceId("goo2"); |
| 86 | String name = "pcc2"; |
| 87 | LspType lspType = LspType.SR_WITHOUT_SIGNALLING; |
| 88 | List<Constraint> constraints = new LinkedList<>(); |
| 89 | Constraint bandwidth1 = BandwidthConstraint.of(100, DataRateUnit.BPS); |
| 90 | constraints.add(bandwidth1); |
| 91 | Constraint bandwidth2 = BandwidthConstraint.of(200, DataRateUnit.BPS); |
| 92 | constraints.add(bandwidth2); |
| 93 | Constraint bandwidth3 = BandwidthConstraint.of(300, DataRateUnit.BPS); |
| 94 | constraints.add(bandwidth3); |
| 95 | |
Priyanka B | bae0eeb1 | 2016-11-30 11:59:48 +0530 | [diff] [blame^] | 96 | PcePathInfo pathInfo = new PcePathInfo(src, dst, name, constraints, lspType, null); |
Mahesh Poojary S | f920ec0 | 2016-05-17 23:16:09 +0530 | [diff] [blame] | 97 | |
| 98 | assertThat(src, is(pathInfo.src())); |
| 99 | assertThat(dst, is(pathInfo.dst())); |
| 100 | assertThat(name, is(pathInfo.name())); |
| 101 | assertThat(constraints, is(pathInfo.constraints())); |
| 102 | assertThat(lspType, is(pathInfo.lspType())); |
| 103 | } |
| 104 | } |