blob: 696ecb80cb85b2b8464b90018c3445563af2baf7 [file] [log] [blame]
Kalyankumar Asangi19f64492016-02-17 17:34:16 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Kalyankumar Asangi19f64492016-02-17 17:34:16 +05303 *
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.ospf.controller.lsdb;
17
18import org.easymock.EasyMock;
19import org.jboss.netty.channel.Channel;
20import org.junit.After;
21import org.junit.Assert;
22import org.junit.Before;
23import org.junit.Test;
24import org.onosproject.ospf.controller.LsaBin;
25import org.onosproject.ospf.controller.OspfArea;
sunishvkf7c56552016-07-18 16:02:39 +053026import org.onosproject.ospf.controller.OspfLsaType;
Kalyankumar Asangi19f64492016-02-17 17:34:16 +053027import org.onosproject.ospf.controller.area.OspfAreaImpl;
28
29import static org.hamcrest.CoreMatchers.*;
30import static org.hamcrest.MatcherAssert.assertThat;
31
32/**
33 * Unit test class for LsdbAgeImpl.
34 */
35public class LsdbAgeImplTest {
36 private LsdbAgeImpl lsdbAge;
37 private OspfAreaImpl ospfAreaImpl;
38 private LsaBinImpl lsaBin;
39 private LsaBin lsaBin1;
40 private LsaWrapperImpl lsaWrapper;
41 private OspfArea ospfArea;
42 private Channel channel;
43
44 @Before
45 public void setUp() throws Exception {
46 ospfAreaImpl = EasyMock.createMock(OspfAreaImpl.class);
47 lsdbAge = new LsdbAgeImpl(ospfAreaImpl);
48 }
49
50 @After
51 public void tearDown() throws Exception {
52 lsdbAge = null;
53 lsaBin = null;
54 lsaBin1 = null;
55 ospfAreaImpl = null;
56 lsaWrapper = null;
57 channel = null;
58 ospfArea = null;
59 }
60
61 /**
62 * Tests getLsaBin() method.
63 */
64 @Test
65 public void testGetLsaBin() throws Exception {
66 lsaBin = new LsaBinImpl(1);
67 lsdbAge.addLsaBin(1, lsaBin);
68 assertThat(lsdbAge, is(notNullValue()));
69 lsaBin1 = lsdbAge.getLsaBin(1);
70 assertThat(lsaBin, instanceOf(LsaBin.class));
71 assertThat(lsaBin1, instanceOf(LsaBin.class));
72 }
73
74 /**
75 * Tests addLsaBin() method.
76 */
77 @Test
78 public void testAddLsaBin() throws Exception {
79 lsaBin = new LsaBinImpl(1);
80 lsdbAge.addLsaBin(1, lsaBin);
81 assertThat(lsdbAge, is(notNullValue()));
82 assertThat(lsaBin, instanceOf(LsaBin.class));
83 }
84
85 /**
86 * Tests equals() method.
87 */
88 @Test
89 public void testEquals() throws Exception {
90 assertThat(lsdbAge.equals(lsdbAge), is(true));
91 }
92
93 /**
94 * Tests hashCode() method.
95 */
96 @Test
97 public void testHashCode() throws Exception {
98 int hashCode = lsdbAge.hashCode();
99 assertThat(hashCode, is(notNullValue()));
100 }
101
102 /**
103 * Tests addLsaToMaxAgeBin() method.
104 */
105 @Test
106 public void testAddLsaToMaxAgeBin() throws Exception {
107 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
108 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
109 assertThat(lsdbAge, is(notNullValue()));
110 }
111
112 /**
113 * Tests removeLsaFromBin() method.
114 */
115 @Test
116 public void testRemoveLsaFromBin() throws Exception {
117 lsaBin = EasyMock.createMock(LsaBinImpl.class);
118 lsaWrapper = new LsaWrapperImpl();
119 lsaWrapper.setBinNumber(-1);
120 lsaBin.addOspfLsa("1", lsaWrapper);
121 lsdbAge.startDbAging();
122 lsdbAge.addLsaToMaxAgeBin("3600", lsaWrapper);
123 lsdbAge.addLsaBin(-1, lsaBin);
124 lsdbAge.removeLsaFromBin(lsaWrapper);
125 assertThat(lsdbAge, is(notNullValue()));
126 }
127
128 /**
129 * Tests startDbAging() method.
130 */
131 @Test
132 public void testStartDbAging() throws Exception {
133 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
134 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
135 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
136 lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
137 lsdbAge.startDbAging();
138 assertThat(lsdbAge, is(notNullValue()));
139 }
140
141 /**
142 * Tests ageLsaAndFlood() method.
143 */
144 @Test
145 public void testAgeLsaAndFlood() throws Exception {
146 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
147 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
148 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
149 lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
150 lsdbAge.startDbAging();
151 lsdbAge.ageLsaAndFlood();
152 Assert.assertNotNull(lsdbAge);
153 }
154
155 /**
156 * Tests maxAgeLsa() method.
157 */
158 @Test
159 public void testMaxageLsa() throws Exception {
160 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
161 ospfArea = new OspfAreaImpl();
162 lsdbAge = new LsdbAgeImpl(ospfArea);
163 lsaWrapper.setLsdbAge(lsdbAge);
164 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
165 lsaBin = new LsaBinImpl(1);
166 lsaBin.addOspfLsa("1", lsaWrapper);
167 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
168 lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
169 lsaBin.addOspfLsa("2", lsaWrapper);
170 lsdbAge.startDbAging();
171 lsdbAge = new LsdbAgeImpl(new OspfAreaImpl());
172 lsdbAge.ageLsaAndFlood();
173 lsdbAge.maxAgeLsa();
174 assertThat(lsdbAge, is(notNullValue()));
175
176 }
177
178 /**
179 * Tests refreshLsa() method.
180 */
181 @Test
182 public void testRefereshLsa() throws Exception {
183 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
184 lsaWrapper.setBinNumber(0);
sunishvkf7c56552016-07-18 16:02:39 +0530185 lsaWrapper.setLsaType(OspfLsaType.NETWORK);
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530186 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
187 lsdbAge.ageLsaAndFlood();
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530188 lsdbAge.startDbAging();
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530189 lsdbAge.refreshLsa();
190 assertThat(lsdbAge, is(notNullValue()));
191 }
192
193 /**
194 * Tests checkAges() method.
195 */
196 @Test
197 public void testCheckAges() throws Exception {
198 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
199 lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper);
200 lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class);
201 lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper);
202 lsdbAge.startDbAging();
203 lsdbAge.checkAges();
204 assertThat(lsdbAge, is(notNullValue()));
205
206 }
207
208 /**
209 * Tests getChannel() getter method.
210 */
211 @Test
212 public void testGetChannel() throws Exception {
213 channel = EasyMock.createMock(Channel.class);
214 lsdbAge.setChannel(channel);
215 assertThat(lsdbAge.getChannel(), is(notNullValue()));
216 }
217
218 /**
219 * Tests setChannel() setter method.
220 */
221 @Test
222 public void testSetChannel() throws Exception {
223 channel = EasyMock.createMock(Channel.class);
224 lsdbAge.setChannel(channel);
225 assertThat(lsdbAge.getChannel(), is(notNullValue()));
226 }
227
228 /**
229 * Tests getAgeCounter() method.
230 */
231 @Test
232 public void testGetAgeCounter() throws Exception {
233 lsaBin = new LsaBinImpl(1);
234 lsdbAge.addLsaBin(1, lsaBin);
235 int age = lsdbAge.getAgeCounter();
236 assertThat(age, is(notNullValue()));
237 }
238
239 /**
240 * Tests getAgeCounterRollOver() method.
241 */
242 @Test
243 public void testGetAgeCounterRollOver() throws Exception {
244 lsaBin = new LsaBinImpl(1);
245 lsdbAge.addLsaBin(1, lsaBin);
246 lsdbAge.startDbAging();
247 assertThat(lsdbAge.getAgeCounterRollOver(), is(notNullValue()));
248 }
249
250 /**
251 * Tests getMaxAgeBin() method.
252 */
253 @Test
254 public void testGetMaxAgeBin() throws Exception {
255 lsaBin = new LsaBinImpl(1);
256 lsdbAge.addLsaBin(1, lsaBin);
257 lsdbAge.startDbAging();
258 assertThat(lsdbAge.getMaxAgeBin(), is(notNullValue()));
259 }
260
261 /**
262 * Tests age2Bin() method.
263 */
264 @Test
265 public void testAge2Bin() throws Exception {
266 int age = lsdbAge.age2Bin(0);
267 assertThat(age, is(notNullValue()));
268 }
269}