blob: c624e022d3b66d1538eec968343dcf62541472ba [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.Before;
22import org.junit.Test;
23import org.onosproject.ospf.controller.LsaWrapper;
24import org.onosproject.ospf.controller.OspfArea;
25import org.onosproject.ospf.controller.OspfLsaType;
26import org.onosproject.ospf.controller.area.OspfAreaImpl;
27import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
28import org.onosproject.ospf.protocol.lsa.LsaHeader;
29import org.onosproject.ospf.protocol.lsa.types.RouterLsa;
30import org.onosproject.ospf.protocol.util.OspfInterfaceState;
31
32import java.util.concurrent.ArrayBlockingQueue;
33import java.util.concurrent.BlockingQueue;
34
35import static org.hamcrest.CoreMatchers.is;
36import static org.hamcrest.CoreMatchers.notNullValue;
37import static org.hamcrest.MatcherAssert.assertThat;
38
39/**
40 * Unit test class for LsaQueueConsumer.
41 */
42public class LsaQueueConsumerTest {
43 private LsaQueueConsumer lsaQueueConsumer;
44 private BlockingQueue<LsaWrapper> blockingQueue;
45 private Channel channel;
46 private LsaWrapperImpl lsaWrapper;
47 private OspfArea ospfArea;
48 private RouterLsa routerLsa;
49 private OspfInterfaceImpl ospfInterface;
50 private LsaHeader lsaHeader;
51 private LsdbAgeImpl lsdbAge;
52
53 @Before
54 public void setUp() throws Exception {
55 lsaQueueConsumer = EasyMock.createMock(LsaQueueConsumer.class);
56 }
57
58 @After
59 public void tearDown() throws Exception {
60 lsaQueueConsumer = null;
61 blockingQueue = null;
62 channel = null;
63 lsaWrapper = null;
64 lsdbAge = null;
65 lsaHeader = null;
66 ospfInterface = null;
67 ospfArea = null;
68 routerLsa = null;
69 }
70
71 /**
72 * Tests run() method.
73 */
74 @Test
75 public void testRun() throws Exception {
76 blockingQueue = new ArrayBlockingQueue(5);
Kalyankumar Asangi19f64492016-02-17 17:34:16 +053077 ospfArea = new OspfAreaImpl();
sunishvkf7c56552016-07-18 16:02:39 +053078 lsdbAge = new LsdbAgeImpl(ospfArea);
79 channel = EasyMock.createMock(Channel.class);
Kalyankumar Asangi19f64492016-02-17 17:34:16 +053080 lsaWrapper = new LsaWrapperImpl();
81 lsaWrapper.setLsaProcessing("verifyChecksum");
82 blockingQueue.add(lsaWrapper);
83 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
84 lsaQueueConsumer.run();
85 assertThat(lsaQueueConsumer, is(notNullValue()));
86 }
87
88 /**
89 * Tests run() method.
90 */
91 @Test
92 public void testRun1() throws Exception {
93 blockingQueue = new ArrayBlockingQueue(5);
94 channel = EasyMock.createMock(Channel.class);
95 ospfArea = new OspfAreaImpl();
96 lsaWrapper = new LsaWrapperImpl();
97 routerLsa = new RouterLsa();
98 routerLsa.setLsType(1);
99 lsaWrapper.addLsa(OspfLsaType.ROUTER, routerLsa);
100 ospfInterface = new OspfInterfaceImpl();
101 ospfInterface.setState(OspfInterfaceState.DR);
102 lsaWrapper.setOspfInterface(ospfInterface);
103 lsaWrapper.setIsSelfOriginated(true);
104 lsaHeader = new LsaHeader();
105 lsaHeader.setLsType(1);
106 lsaWrapper.setLsaHeader(lsaHeader);
107 lsaWrapper.setLsaProcessing("refreshLsa");
sunishvkf7c56552016-07-18 16:02:39 +0530108 lsaWrapper.setLsdbAge(new LsdbAgeImpl(ospfArea));
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530109 blockingQueue.add(lsaWrapper);
110 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
111 lsaQueueConsumer.run();
112 assertThat(lsaQueueConsumer, is(notNullValue()));
113 }
114
115 @Test
116 public void testRun3() throws Exception {
117 blockingQueue = new ArrayBlockingQueue(5);
118 channel = EasyMock.createMock(Channel.class);
119 ospfArea = new OspfAreaImpl();
120 lsaWrapper = new LsaWrapperImpl();
121 routerLsa = new RouterLsa();
122 routerLsa.setLsType(2);
123 lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa);
124 ospfInterface = new OspfInterfaceImpl();
125 ospfInterface.setState(OspfInterfaceState.BDR);
126 lsaWrapper.setOspfInterface(ospfInterface);
127 lsaWrapper.setIsSelfOriginated(true);
128 lsaHeader = new LsaHeader();
129 lsaHeader.setLsType(2);
130 lsaWrapper.setLsaHeader(lsaHeader);
131 lsaWrapper.setLsaProcessing("refreshLsa");
sunishvkf7c56552016-07-18 16:02:39 +0530132 lsaWrapper.setLsdbAge(new LsdbAgeImpl(ospfArea));
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530133 blockingQueue.add(lsaWrapper);
134 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
135 lsaQueueConsumer.run();
136 assertThat(lsaQueueConsumer, is(notNullValue()));
137 }
138
139 /**
140 * Tests run() method.
141 */
142 @Test
143 public void testRun5() throws Exception {
144 blockingQueue = new ArrayBlockingQueue(5);
145 channel = EasyMock.createMock(Channel.class);
146 ospfArea = new OspfAreaImpl();
147 lsaWrapper = new LsaWrapperImpl();
148 routerLsa = new RouterLsa();
149 routerLsa.setLsType(2);
150 lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa);
151 ospfInterface = new OspfInterfaceImpl();
152 ospfInterface.setState(OspfInterfaceState.DR);
153 lsaWrapper.setOspfInterface(ospfInterface);
154 lsaWrapper.setIsSelfOriginated(true);
155 lsaHeader = new LsaHeader();
156 lsaHeader.setLsType(2);
157 lsaWrapper.setLsaHeader(lsaHeader);
158 lsaWrapper.setLsaProcessing("maxAgeLsa");
sunishvkf7c56552016-07-18 16:02:39 +0530159 lsaWrapper.setLsdbAge(new LsdbAgeImpl(ospfArea));
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530160 blockingQueue.add(lsaWrapper);
161 lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea);
162 lsaQueueConsumer.run();
163 assertThat(lsaQueueConsumer, is(notNullValue()));
164 }
165
166 /**
167 * Tests setChannel() method.
168 */
169 @Test
170 public void testSetChannel() throws Exception {
171 channel = EasyMock.createMock(Channel.class);
sunishvkf7c56552016-07-18 16:02:39 +0530172 lsdbAge = new LsdbAgeImpl(ospfArea);
Kalyankumar Asangi19f64492016-02-17 17:34:16 +0530173 lsdbAge.startDbAging();
174 lsdbAge.setChannel(channel);
175 assertThat(lsaQueueConsumer, is(notNullValue()));
176 }
177
178}