blob: 6d9bcd384726b35e20b5ba61337951419c9b5809 [file] [log] [blame]
Mahesh Poojary Sba827292016-05-09 11:31:12 +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 java.util.LinkedList;
19import java.util.List;
20
21import static org.hamcrest.MatcherAssert.assertThat;
22import static org.hamcrest.Matchers.is;
23
24import com.google.common.testing.EqualsTester;
25
26import org.junit.Test;
27import org.onosproject.incubator.net.resource.label.LabelResourceId;
28import org.onosproject.net.DeviceId;
29import org.onosproject.net.PortNumber;
30import org.onosproject.net.resource.ResourceConsumer;
31import org.onosproject.pce.pceservice.TunnelConsumerId;
32import org.onosproject.pce.pcestore.api.LspLocalLabelInfo;
33
34/**
35 * Unit tests for PceccTunnelInfo class.
36 */
37public class PceccTunnelInfoTest {
38
39 /**
40 * Checks the operation of equals() methods.
41 */
42 @Test
43 public void testEquals() {
44 // create same two objects.
45 List<LspLocalLabelInfo> lspLocalLabelList1 = new LinkedList<>();
46 ResourceConsumer tunnelConsumerId1 = TunnelConsumerId.valueOf(10);
47
48 // create object of DefaultLspLocalLabelInfo
49 DeviceId deviceId1 = DeviceId.deviceId("foo");
50 LabelResourceId inLabelId1 = LabelResourceId.labelResourceId(1);
51 LabelResourceId outLabelId1 = LabelResourceId.labelResourceId(2);
52 PortNumber inPort1 = PortNumber.portNumber(5122);
53 PortNumber outPort1 = PortNumber.portNumber(5123);
54
55 LspLocalLabelInfo lspLocalLabel1 = DefaultLspLocalLabelInfo.builder()
56 .deviceId(deviceId1)
57 .inLabelId(inLabelId1)
58 .outLabelId(outLabelId1)
59 .inPort(inPort1)
60 .outPort(outPort1)
61 .build();
62 lspLocalLabelList1.add(lspLocalLabel1);
63
64 PceccTunnelInfo pceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1);
65
66 // create same as above object
67 PceccTunnelInfo samePceccTunnelInfo1 = new PceccTunnelInfo(lspLocalLabelList1, tunnelConsumerId1);
68
69 // Create different object.
70 List<LspLocalLabelInfo> lspLocalLabelInfoList2 = new LinkedList<>();
71 ResourceConsumer tunnelConsumerId2 = TunnelConsumerId.valueOf(20);
72
73 // create object of DefaultLspLocalLabelInfo
74 DeviceId deviceId2 = DeviceId.deviceId("goo");
75 LabelResourceId inLabelId2 = LabelResourceId.labelResourceId(3);
76 LabelResourceId outLabelId2 = LabelResourceId.labelResourceId(4);
77 PortNumber inPort2 = PortNumber.portNumber(5124);
78 PortNumber outPort2 = PortNumber.portNumber(5125);
79
80 LspLocalLabelInfo lspLocalLabel2 = DefaultLspLocalLabelInfo.builder()
81 .deviceId(deviceId2)
82 .inLabelId(inLabelId2)
83 .outLabelId(outLabelId2)
84 .inPort(inPort2)
85 .outPort(outPort2)
86 .build();
87 lspLocalLabelInfoList2.add(lspLocalLabel2);
88
89 PceccTunnelInfo pceccTunnelInfo2 = new PceccTunnelInfo(lspLocalLabelInfoList2, tunnelConsumerId2);
90
91 new EqualsTester().addEqualityGroup(pceccTunnelInfo1, samePceccTunnelInfo1)
92 .addEqualityGroup(pceccTunnelInfo2)
93 .testEquals();
94 }
95
96 /**
97 * Checks the construction of a PceccTunnelInfo object.
98 */
99 @Test
100 public void testConstruction() {
101 List<LspLocalLabelInfo> lspLocalLabelInfoList = new LinkedList<>();
102 ResourceConsumer tunnelConsumerId = TunnelConsumerId.valueOf(10);
103
104 // create object of DefaultLspLocalLabelInfo
105 DeviceId deviceId = DeviceId.deviceId("foo");
106 LabelResourceId inLabelId = LabelResourceId.labelResourceId(1);
107 LabelResourceId outLabelId = LabelResourceId.labelResourceId(2);
108 PortNumber inPort = PortNumber.portNumber(5122);
109 PortNumber outPort = PortNumber.portNumber(5123);
110
111 LspLocalLabelInfo lspLocalLabelInfo = DefaultLspLocalLabelInfo.builder()
112 .deviceId(deviceId)
113 .inLabelId(inLabelId)
114 .outLabelId(outLabelId)
115 .inPort(inPort)
116 .outPort(outPort)
117 .build();
118 lspLocalLabelInfoList.add(lspLocalLabelInfo);
119
120 PceccTunnelInfo pceccTunnelInfo = new PceccTunnelInfo(lspLocalLabelInfoList, tunnelConsumerId);
121
122 assertThat(lspLocalLabelInfoList, is(pceccTunnelInfo.lspLocalLabelInfoList()));
123 }
124}