chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 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 | */ |
| 16 | package org.onosproject.isis.controller.impl; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.channel.ChannelHandlerContext; |
| 20 | import org.jboss.netty.channel.ChannelStateEvent; |
| 21 | import org.jboss.netty.channel.ExceptionEvent; |
| 22 | import org.jboss.netty.channel.MessageEvent; |
| 23 | import org.junit.After; |
| 24 | import org.junit.Before; |
| 25 | import org.junit.Test; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 26 | import org.onlab.packet.Ip4Address; |
| 27 | import org.onosproject.isis.controller.IsisInterface; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 28 | import org.onosproject.isis.controller.IsisMessage; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 29 | import org.onosproject.isis.controller.IsisNetworkType; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 30 | import org.onosproject.isis.controller.IsisProcess; |
| 31 | import org.onosproject.isis.io.isispacket.pdu.L1L2HelloPdu; |
| 32 | |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 33 | import java.util.ArrayList; |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 34 | import java.util.List; |
| 35 | |
| 36 | import static org.hamcrest.CoreMatchers.is; |
| 37 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 38 | import static org.junit.Assert.assertThat; |
| 39 | |
| 40 | /** |
| 41 | * Unit test class for IsisChannelHandler. |
| 42 | */ |
| 43 | public 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 vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 50 | private List<IsisProcess> isisProcessList = new ArrayList(); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 51 | private ChannelHandlerContext channelHandlerContext; |
| 52 | private ChannelStateEvent channelStateEvent; |
| 53 | private ExceptionEvent exceptionEvent; |
| 54 | private MessageEvent messageEvent; |
| 55 | private IsisMessage isisMessage; |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 56 | private List<IsisInterface> isisInterfaceList = new ArrayList<>(); |
| 57 | private Ip4Address ip4Address = Ip4Address.valueOf("10.10.10.10"); |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 58 | |
| 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 vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 80 | @Test |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 81 | 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 vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 91 | 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 babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 117 | isisChannelHandler.updateInterfaceMap(isisProcessList); |
| 118 | assertThat(isisChannelHandler, is(notNullValue())); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Tests initializeInterfaceIpList() method. |
| 123 | */ |
sunish vk | 4b5ce00 | 2016-05-09 20:18:35 +0530 | [diff] [blame] | 124 | @Test |
chidambar babu | 344dc81 | 2016-05-02 19:13:10 +0530 | [diff] [blame] | 125 | 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 | } |