nicklesh adlakha | 90bfa6a | 2016-04-28 20:38:33 +0530 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present 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 | */ |
| 16 | package org.onosproject.isis.io.isispacket.pdu; |
| 17 | |
| 18 | import org.easymock.EasyMock; |
| 19 | import org.jboss.netty.buffer.ChannelBuffer; |
| 20 | import org.jboss.netty.buffer.ChannelBuffers; |
| 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.onosproject.isis.controller.IsisPduType; |
| 25 | import org.onosproject.isis.io.isispacket.IsisHeader; |
| 26 | import org.onosproject.isis.io.isispacket.tlv.AdjacencyStateTlv; |
| 27 | import org.onosproject.isis.io.isispacket.tlv.IsisTlv; |
| 28 | import org.onosproject.isis.io.isispacket.tlv.TlvHeader; |
| 29 | |
| 30 | import java.util.List; |
| 31 | |
| 32 | import static org.hamcrest.CoreMatchers.is; |
| 33 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 34 | import static org.hamcrest.MatcherAssert.assertThat; |
| 35 | |
| 36 | /** |
| 37 | * Unit test class for Csnp. |
| 38 | */ |
| 39 | public class CsnpTest { |
| 40 | |
| 41 | private final String srcId = "1111.1111.1111"; |
| 42 | private final byte[] csnpBytes = { |
| 43 | 0, 67, 18, 52, 18, 52, 0, 0, 67, 18, 52, 18, 52, 0, |
| 44 | 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, |
| 45 | -1, -1, 9, 32, 4, -81, 18, 52, 18, 52, 0, 18, 0, 0, 0, |
| 46 | 0, 0, 41, -92, -30, 4, -81, 41, 41, 41, 41, 41, 41, 0, |
| 47 | 0, 0, 0, 0, 1, 91, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 48 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 49 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 50 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 51 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 52 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 53 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 54 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 55 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 56 | 0, 0, 0 |
| 57 | }; |
| 58 | private Csnp csnp; |
| 59 | private IsisHeader isisHeader; |
| 60 | private IsisTlv isisTlv; |
| 61 | private TlvHeader tlvHeader; |
| 62 | private List<IsisTlv> resultList; |
| 63 | private String resultStr; |
| 64 | private int resultInt; |
| 65 | private ChannelBuffer channelBuffer; |
| 66 | private byte[] result; |
| 67 | |
| 68 | @Before |
| 69 | public void setUp() throws Exception { |
| 70 | isisHeader = new IsisHeader(); |
| 71 | isisHeader.setIsisPduType(IsisPduType.L1CSNP.value()); |
| 72 | csnp = new Csnp(isisHeader); |
| 73 | tlvHeader = new TlvHeader(); |
| 74 | isisTlv = new AdjacencyStateTlv(tlvHeader); |
| 75 | channelBuffer = EasyMock.createMock(ChannelBuffer.class); |
| 76 | } |
| 77 | |
| 78 | @After |
| 79 | public void tearDown() throws Exception { |
| 80 | isisHeader = null; |
| 81 | csnp = null; |
| 82 | tlvHeader = null; |
| 83 | isisTlv = null; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Tests getAllTlv() method. |
| 88 | */ |
| 89 | @Test |
| 90 | public void testGetAllTlv() throws Exception { |
| 91 | channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); |
| 92 | csnp.readFrom(channelBuffer); |
| 93 | resultList = csnp.getAllTlv(); |
| 94 | assertThat(resultList.size(), is(0)); |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Tests sourceId() getter method. |
| 99 | */ |
| 100 | @Test |
| 101 | public void testSourceId() throws Exception { |
| 102 | csnp.setSourceId(srcId); |
| 103 | resultStr = csnp.sourceId(); |
| 104 | assertThat(resultStr, is(srcId)); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Tests sourceId() setter method. |
| 109 | */ |
| 110 | @Test |
| 111 | public void testSetSourceId() throws Exception { |
| 112 | csnp.setSourceId(srcId); |
| 113 | resultStr = csnp.sourceId(); |
| 114 | assertThat(resultStr, is(srcId)); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * Tests startLspId() getter method. |
| 120 | */ |
| 121 | @Test |
| 122 | public void testStartLspId() throws Exception { |
| 123 | csnp.setStartLspId(srcId); |
| 124 | resultStr = csnp.startLspId(); |
| 125 | assertThat(resultStr, is(srcId)); |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Tests startLspId() setter method. |
| 130 | */ |
| 131 | @Test |
| 132 | public void testSetStartLspId() throws Exception { |
| 133 | csnp.setStartLspId(srcId); |
| 134 | resultStr = csnp.startLspId(); |
| 135 | assertThat(resultStr, is(srcId)); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Tests endLspId() getter method. |
| 140 | */ |
| 141 | @Test |
| 142 | public void testEndLspId() throws Exception { |
| 143 | csnp.setEndLspId(srcId); |
| 144 | resultStr = csnp.endLspId(); |
| 145 | assertThat(resultStr, is(srcId)); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Tests endLspId() setter method. |
| 150 | */ |
| 151 | @Test |
| 152 | public void testSetEndLspId() throws Exception { |
| 153 | csnp.setEndLspId(srcId); |
| 154 | resultStr = csnp.endLspId(); |
| 155 | assertThat(resultStr, is(srcId)); |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Tests pduLength() getter method. |
| 160 | */ |
| 161 | @Test |
| 162 | public void testPduLength() throws Exception { |
| 163 | csnp.setPduLength(10); |
| 164 | resultInt = csnp.pduLength(); |
| 165 | assertThat(resultInt, is(10)); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Tests pduLength() setter method. |
| 170 | */ |
| 171 | @Test |
| 172 | public void testSetPduLength() throws Exception { |
| 173 | csnp.setPduLength(10); |
| 174 | resultInt = csnp.pduLength(); |
| 175 | assertThat(resultInt, is(10)); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * Tests readFrom() method. |
| 180 | */ |
| 181 | @Test |
| 182 | public void testReadFrom() throws Exception { |
| 183 | channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); |
| 184 | csnp.readFrom(channelBuffer); |
| 185 | assertThat(csnp, is(notNullValue())); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Tests asBytes() method. |
| 190 | */ |
| 191 | @Test |
| 192 | public void testAsBytes() throws Exception { |
| 193 | channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); |
| 194 | csnp.readFrom(channelBuffer); |
| 195 | result = csnp.asBytes(); |
| 196 | assertThat(csnp, is(notNullValue())); |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * Tests isisPduHeader() method. |
| 201 | */ |
| 202 | @Test |
| 203 | public void testIsisPduHeader() throws Exception { |
| 204 | result = csnp.isisPduHeader(); |
| 205 | assertThat(result, is(notNullValue())); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Tests completeSequenceNumberPduBody() method. |
| 210 | */ |
| 211 | @Test |
| 212 | public void testCompleteSequenceNumberPduBody() throws Exception { |
| 213 | channelBuffer = ChannelBuffers.copiedBuffer(csnpBytes); |
| 214 | csnp.readFrom(channelBuffer); |
| 215 | result = csnp.completeSequenceNumberPduBody(); |
| 216 | assertThat(result, is(notNullValue())); |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Tests toString() method. |
| 221 | */ |
| 222 | @Test |
| 223 | public void testToString() throws Exception { |
| 224 | assertThat((csnp.toString()), is(notNullValue())); |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * Tests equals() method. |
| 229 | */ |
| 230 | @Test |
| 231 | public void testEquals() throws Exception { |
| 232 | assertThat(csnp.equals(new Csnp(new IsisHeader())), is(true)); |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Tests hashCode() method. |
| 237 | */ |
| 238 | @Test |
| 239 | public void testHashCode() throws Exception { |
| 240 | int hashCode = csnp.hashCode(); |
| 241 | assertThat(hashCode, is(notNullValue())); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
| 246 | |