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