blob: 468036e8e62fcba28bd50f932e74c0fc9c6a6c7e [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;
17
18import org.easymock.EasyMock;
19import org.jboss.netty.channel.ChannelHandlerContext;
20import org.jboss.netty.channel.ChannelStateEvent;
21import org.jboss.netty.channel.ExceptionEvent;
22import org.jboss.netty.channel.MessageEvent;
23import org.junit.After;
24import org.junit.Before;
25import org.junit.Test;
sunish vk4b5ce002016-05-09 20:18:35 +053026import org.onlab.packet.Ip4Address;
27import org.onosproject.isis.controller.IsisInterface;
chidambar babu344dc812016-05-02 19:13:10 +053028import org.onosproject.isis.controller.IsisMessage;
sunish vk4b5ce002016-05-09 20:18:35 +053029import org.onosproject.isis.controller.IsisNetworkType;
chidambar babu344dc812016-05-02 19:13:10 +053030import org.onosproject.isis.controller.IsisProcess;
31import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu;
32
sunish vk4b5ce002016-05-09 20:18:35 +053033import java.util.ArrayList;
chidambar babu344dc812016-05-02 19:13:10 +053034import java.util.List;
35
36import static org.hamcrest.CoreMatchers.is;
37import static org.hamcrest.CoreMatchers.notNullValue;
38import static org.junit.Assert.assertThat;
39
40/**
41 * Unit test class for IsisChannelHandler.
42 */
43public class IsisChannelHandlerTest {
44
45 private final String processId = "1";
46 private final byte[] config = {0, 0, 0, 0, 0, 0, 0};
47 private IsisChannelHandler isisChannelHandler;
48 private Controller controller;
49 private IsisProcess isisProcess;
sunish vk4b5ce002016-05-09 20:18:35 +053050 private List<IsisProcess> isisProcessList = new ArrayList();
chidambar babu344dc812016-05-02 19:13:10 +053051 private ChannelHandlerContext channelHandlerContext;
52 private ChannelStateEvent channelStateEvent;
53 private ExceptionEvent exceptionEvent;
54 private MessageEvent messageEvent;
55 private IsisMessage isisMessage;
sunish vk4b5ce002016-05-09 20:18:35 +053056 private List<IsisInterface> isisInterfaceList = new ArrayList<>();
57 private Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10");
chidambar babu344dc812016-05-02 19:13:10 +053058
59 @Before
60 public void setUp() throws Exception {
61 controller = EasyMock.createNiceMock(Controller.class);
62 isisProcess = EasyMock.createNiceMock(IsisProcess.class);
63 channelHandlerContext = EasyMock.createNiceMock(ChannelHandlerContext.class);
64 channelStateEvent = EasyMock.createNiceMock(ChannelStateEvent.class);
65 exceptionEvent = EasyMock.createNiceMock(ExceptionEvent.class);
66 messageEvent = EasyMock.createNiceMock(MessageEvent.class);
67 isisMessage = EasyMock.createNiceMock(L1L2HelloPdu.class);
68 isisMessage.setInterfaceIndex(2);
69 isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
70 }
71
72 @After
73 public void tearDown() throws Exception {
74 isisChannelHandler = null;
75 }
76
77 /**
78 * Tests initializeInterfaceMap() method.
79 */
sunish vk4b5ce002016-05-09 20:18:35 +053080 @Test
chidambar babu344dc812016-05-02 19:13:10 +053081 public void testInitializeInterfaceMap() throws Exception {
82 isisChannelHandler.initializeInterfaceMap();
83 assertThat(isisChannelHandler, is(notNullValue()));
84 }
85
86 /**
87 * Tests updateInterfaceMap() method.
88 */
89 @Test(expected = Exception.class)
90 public void testUpdateInterfaceMap() throws Exception {
sunish vk4b5ce002016-05-09 20:18:35 +053091 IsisInterface isisInterface = new DefaultIsisInterface();
92 IsisInterface isisInterface1 = new DefaultIsisInterface();
93 isisInterface.setInterfaceIpAddress(ip4Address);
94 isisInterface.setInterfaceIndex(1);
95 isisInterfaceList.add(isisInterface);
96 IsisProcess isisProcess = new DefaultIsisProcess();
97 isisProcess.setIsisInterfaceList(isisInterfaceList);
98 isisProcessList.add(isisProcess);
99 isisChannelHandler.updateInterfaceMap(isisProcessList);
100 assertThat(isisChannelHandler, is(notNullValue()));
101 isisProcessList = new ArrayList<>();
102 isisInterface1.setInterfaceIpAddress(ip4Address);
103 isisInterface1.setInterfaceIndex(1);
104 isisInterface1.setInterfaceIpAddress(ip4Address);
105 isisInterface1.setInterfaceIndex(1);
106 isisInterface1.setSystemId("9999.9999.9999");
107 isisInterface1.setIntermediateSystemName("router");
108 isisInterface1.setReservedPacketCircuitType(3);
109 isisInterface1.setCircuitId("10");
110 isisInterface1.setNetworkType(IsisNetworkType.BROADCAST);
111 isisInterface1.setAreaAddress("490001");
112 isisInterface1.setHoldingTime(50);
113 isisInterface1.setHelloInterval(10);
114 isisInterfaceList.add(isisInterface1);
115 isisProcess.setIsisInterfaceList(isisInterfaceList);
116 isisProcessList.add(isisProcess);
chidambar babu344dc812016-05-02 19:13:10 +0530117 isisChannelHandler.updateInterfaceMap(isisProcessList);
118 assertThat(isisChannelHandler, is(notNullValue()));
119 }
120
121 /**
122 * Tests initializeInterfaceIpList() method.
123 */
sunish vk4b5ce002016-05-09 20:18:35 +0530124 @Test
chidambar babu344dc812016-05-02 19:13:10 +0530125 public void testInitializeInterfaceIpList() throws Exception {
126 isisChannelHandler.initializeInterfaceIpList();
127 assertThat(isisChannelHandler, is(notNullValue()));
128 }
129
130 /**
131 * Tests channelConnected() method.
132 */
133 @Test(expected = Exception.class)
134 public void testChannelConnected() throws Exception {
135 isisChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
136 assertThat(isisChannelHandler, is(notNullValue()));
137 }
138
139 /**
140 * Tests channelDisconnected() method.
141 */
142 @Test
143 public void testChannelDisconnected() throws Exception {
144 isisChannelHandler.channelDisconnected(channelHandlerContext, channelStateEvent);
145 assertThat(isisChannelHandler, is(notNullValue()));
146 }
147
148 /**
149 * Tests exceptionCaught() method.
150 */
151 @Test(expected = Exception.class)
152 public void testExceptionCaught() throws Exception {
153 isisChannelHandler.exceptionCaught(channelHandlerContext, exceptionEvent);
154 assertThat(isisChannelHandler, is(notNullValue()));
155 }
156
157 /**
158 * Tests messageReceived() method.
159 */
160 @Test
161 public void testMessageReceived() throws Exception {
162 isisChannelHandler.messageReceived(channelHandlerContext, messageEvent);
163 assertThat(isisChannelHandler, is(notNullValue()));
164 }
165
166 /**
167 * Tests processIsisMessage() method.
168 */
169 @Test(expected = Exception.class)
170 public void testProcessIsisMessage() throws Exception {
171 isisChannelHandler.processIsisMessage(isisMessage, channelHandlerContext);
172 assertThat(isisChannelHandler, is(notNullValue()));
173 }
174
175 /**
176 * Tests startHelloSender() method.
177 */
178 @Test
179 public void testStartHelloSender() throws Exception {
180 isisChannelHandler.startHelloSender();
181 assertThat(isisChannelHandler, is(notNullValue()));
182 }
183
184 /**
185 * Tests stopHelloSender() method.
186 */
187 @Test
188 public void testStopHelloSender() throws Exception {
189 isisChannelHandler.stopHelloSender();
190 assertThat(isisChannelHandler, is(notNullValue()));
191 }
192
193 /**
194 * Tests sentConfigPacket() method.
195 */
196 @Test
197 public void testSentConfigPacket() throws Exception {
198 isisChannelHandler.sentConfigPacket(config);
199 assertThat(isisChannelHandler, is(notNullValue()));
200 }
201}