blob: 51388ac797ebc0465c33353cb84108a52e952df6 [file] [log] [blame]
chidambar babu344dc812016-05-02 19:13:10 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
chidambar babu344dc812016-05-02 19:13:10 +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.isis.controller.impl.lsdb;
17
18import org.junit.After;
19import org.junit.Before;
20import org.junit.Test;
21import org.onosproject.isis.controller.IsisLspBin;
22import org.onosproject.isis.io.isispacket.IsisHeader;
23import org.onosproject.isis.io.isispacket.pdu.LsPdu;
24
25import static org.hamcrest.CoreMatchers.*;
26import static org.junit.Assert.assertThat;
27
28/**
29 * Unit test case for DefaultIsisLsdbAge.
30 */
31public class DefaultIsisLsdbAgeTest {
32 private DefaultIsisLsdbAge defaultIsisLsdbAge;
33 private IsisLspBin isisLspBin;
34 private int resultInt;
35 private IsisLspBin resultLspBin;
36 private DefaultLspWrapper lspWrapper;
37 private LsPdu lsPdu;
38 private IsisHeader isisHeader;
39 private String lspId = "1234.1234.1234";
40
41 @Before
42 public void setUp() throws Exception {
43 defaultIsisLsdbAge = new DefaultIsisLsdbAge();
44 isisLspBin = new DefaultIsisLspBin(1);
45 lspWrapper = new DefaultLspWrapper();
46 lspWrapper.setBinNumber(1);
47 isisHeader = new IsisHeader();
48 lsPdu = new LsPdu(isisHeader);
49 lsPdu.setLspId(lspId);
50 lspWrapper.setLsPdu(lsPdu);
51 }
52
53 @After
54 public void tearDown() throws Exception {
55 defaultIsisLsdbAge = null;
56 isisLspBin = null;
57 }
58
59 /**
60 * Tests ageCounter() method.
61 */
62 @Test
63 public void testAgeCounter() throws Exception {
64 resultInt = defaultIsisLsdbAge.ageCounter();
65 assertThat(resultInt, is(0));
66 }
67
68 /**
69 * Tests ageCounterRollOver() method.
70 */
71 @Test
72 public void testAgeCounterRollOver() throws Exception {
73 resultInt = defaultIsisLsdbAge.ageCounterRollOver();
74 assertThat(resultInt, is(0));
75 }
76
77 /**
78 * Tests addLspBin() method.
79 */
80 @Test
81 public void testAddLspBin() throws Exception {
82 defaultIsisLsdbAge.addLspBin(1400, isisLspBin);
83 resultLspBin = defaultIsisLsdbAge.getLspBin(1);
84 assertThat(resultLspBin, is(notNullValue()));
85 }
86
87 /**
88 * Tests getLspBin() method.
89 */
90 @Test
91 public void testGetLspBin() throws Exception {
92 defaultIsisLsdbAge.addLspBin(1, isisLspBin);
93 resultLspBin = defaultIsisLsdbAge.getLspBin(1);
94 assertThat(resultLspBin, is(notNullValue()));
95 }
96
97 /**
98 * Tests removeLspFromBin() method.
99 */
100 @Test
101 public void testRemoveLspFromBin() throws Exception {
102 defaultIsisLsdbAge.addLspBin(1400, isisLspBin);
103 defaultIsisLsdbAge.removeLspFromBin(lspWrapper);
104 assertThat(resultLspBin, is(nullValue()));
105 }
106
107 /**
108 * Tests age2Bin() method.
109 */
110 @Test
111 public void testAge2Bin() throws Exception {
112 defaultIsisLsdbAge.age2Bin(1);
113 assertThat(defaultIsisLsdbAge, is(notNullValue()));
114
115 defaultIsisLsdbAge.age2Bin(-1);
116 assertThat(defaultIsisLsdbAge, is(notNullValue()));
117 }
118
119 /**
120 * Tests startDbAging() method.
121 */
122 @Test
123 public void testStartDbAging() throws Exception {
124 defaultIsisLsdbAge.startDbAging();
125 assertThat(defaultIsisLsdbAge, is(notNullValue()));
126 }
127
128 /**
129 * Tests ageLsp() method.
130 */
131 @Test
132 public void testAgeLsp() throws Exception {
133 defaultIsisLsdbAge.age2Bin(1);
134 defaultIsisLsdbAge.startDbAging();
135 defaultIsisLsdbAge.ageLsp();
136 assertThat(defaultIsisLsdbAge, is(notNullValue()));
137 }
138
139 /**
140 * Tests maxAgeLsa() method.
141 */
142 @Test
143 public void testMaxAgeLsa() throws Exception {
144 defaultIsisLsdbAge.age2Bin(1);
145 defaultIsisLsdbAge.startDbAging();
146 defaultIsisLsdbAge.maxAgeLsa();
147 assertThat(defaultIsisLsdbAge, is(notNullValue()));
148
149 defaultIsisLsdbAge.age2Bin(1400);
150 defaultIsisLsdbAge.startDbAging();
151 defaultIsisLsdbAge.maxAgeLsa();
152 assertThat(defaultIsisLsdbAge, is(notNullValue()));
153 }
154
155 /**
156 * Tests refreshLsa() method.
157 */
158 @Test
159 public void testRefreshLsa() throws Exception {
160 defaultIsisLsdbAge.age2Bin(1);
161 defaultIsisLsdbAge.startDbAging();
162 defaultIsisLsdbAge.refreshLsa();
163 assertThat(defaultIsisLsdbAge, is(notNullValue()));
164
165 defaultIsisLsdbAge.age2Bin(1400);
166 defaultIsisLsdbAge.startDbAging();
167 defaultIsisLsdbAge.refreshLsa();
168 assertThat(defaultIsisLsdbAge, is(notNullValue()));
169 }
170}
171