Kiran Ramachandra | 959353a | 2016-02-16 22:12:07 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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.ospf.protocol.lsa.linksubtype; |
| 17 | |
| 18 | import org.jboss.netty.buffer.ChannelBuffer; |
| 19 | import org.jboss.netty.buffer.ChannelBuffers; |
| 20 | import org.junit.After; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.Test; |
| 23 | import org.onosproject.ospf.protocol.lsa.TlvHeader; |
| 24 | |
| 25 | import static org.hamcrest.CoreMatchers.is; |
| 26 | import static org.hamcrest.CoreMatchers.notNullValue; |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | |
| 29 | /** |
| 30 | * Unit test class for TrafficEngineeringMetric. |
| 31 | */ |
| 32 | public class TrafficEngineeringMetricTest { |
| 33 | |
| 34 | private final byte[] packet = {0, 0, 1, 1}; |
| 35 | private TrafficEngineeringMetric trafficEngineeringMetric; |
| 36 | private TlvHeader header; |
| 37 | private byte[] result; |
| 38 | private ChannelBuffer channelBuffer; |
| 39 | |
| 40 | @Before |
| 41 | public void setUp() throws Exception { |
| 42 | trafficEngineeringMetric = new TrafficEngineeringMetric(new TlvHeader()); |
| 43 | } |
| 44 | |
| 45 | @After |
| 46 | public void tearDown() throws Exception { |
| 47 | trafficEngineeringMetric = null; |
| 48 | header = null; |
| 49 | result = null; |
| 50 | channelBuffer = null; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Tests trafficEngineeringMetric() setter method. |
| 56 | */ |
| 57 | @Test |
| 58 | public void testSetTrafficEngineeringMetric() throws Exception { |
| 59 | trafficEngineeringMetric.setTrafficEngineeringMetric(123456789L); |
| 60 | assertThat(trafficEngineeringMetric, is(notNullValue())); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Tests readFrom() method. |
| 65 | */ |
| 66 | @Test |
| 67 | public void testReadFrom() throws Exception { |
| 68 | header = new TlvHeader(); |
| 69 | header.setTlvLength(4); |
| 70 | header.setTlvType(5); |
| 71 | channelBuffer = ChannelBuffers.copiedBuffer(packet); |
| 72 | trafficEngineeringMetric = new TrafficEngineeringMetric(header); |
| 73 | trafficEngineeringMetric.readFrom(channelBuffer); |
| 74 | assertThat(trafficEngineeringMetric, is(notNullValue())); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Tests asBytes() method. |
| 79 | */ |
| 80 | @Test |
| 81 | public void testAsBytes() throws Exception { |
| 82 | result = trafficEngineeringMetric.asBytes(); |
| 83 | assertThat(result, is(notNullValue())); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | /** |
| 88 | * Tests getLinkSubTypeTlvBodyAsByteArray() method. |
| 89 | */ |
| 90 | @Test |
| 91 | public void testGetLinkSubTypeTlvBodyAsByteArray() throws Exception { |
| 92 | result = trafficEngineeringMetric.getLinkSubTypeTlvBodyAsByteArray(); |
| 93 | assertThat(result, is(notNullValue())); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Tests to string method. |
| 98 | */ |
| 99 | @Test |
| 100 | public void testToString() throws Exception { |
| 101 | assertThat(trafficEngineeringMetric.toString(), is(notNullValue())); |
| 102 | } |
| 103 | } |