blob: a13c634f6532337d9dc4fd0ab54820016af0d7ab [file] [log] [blame]
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +05301/*
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 */
16package org.onosproject.pce.pcestore;
17
18import static org.hamcrest.MatcherAssert.assertThat;
19import static org.hamcrest.Matchers.is;
20
21import com.google.common.testing.EqualsTester;
22
23import java.util.List;
24import java.util.LinkedList;
25
26import org.junit.Test;
27import org.onlab.util.DataRateUnit;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.intent.Constraint;
30import org.onosproject.net.intent.constraint.BandwidthConstraint;
31import org.onosproject.pce.pceservice.LspType;
32
33/**
34 * Unit tests for PcePathInfo class.
35 */
36public 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 Bbae0eeb12016-11-30 11:59:48 +053056 PcePathInfo pathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053057
58 // create same object as above object
Priyanka Bbae0eeb12016-11-30 11:59:48 +053059 PcePathInfo samePathInfo1 = new PcePathInfo(src1, dst1, name1, constraints1, lspType1, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053060
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 Bbae0eeb12016-11-30 11:59:48 +053072 PcePathInfo pathInfo2 = new PcePathInfo(src2, dst2, name2, constraints2, lspType2, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053073
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 Bbae0eeb12016-11-30 11:59:48 +053096 PcePathInfo pathInfo = new PcePathInfo(src, dst, name, constraints, lspType, null);
Mahesh Poojary Sf920ec02016-05-17 23:16:09 +053097
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}