blob: f439af4d84b6b73c5e6f2f313ff3a4919b88596f [file] [log] [blame]
Chidambar babu86b3b1a2016-02-16 17:39:52 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Chidambar babu86b3b1a2016-02-16 17:39:52 +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.protocol.lsa;
17
18import org.hamcrest.Matchers;
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.Ip4Address;
23
24import static org.hamcrest.CoreMatchers.notNullValue;
25import static org.hamcrest.Matchers.is;
26import static org.junit.Assert.assertThat;
27
28/**
29 * Unit test class for OpaqueLsaHeader.
30 */
31public class OpaqueLsaHeaderTest {
32
33 private OpaqueLsaHeader opaqueHeader;
34 private OpaqueLsaHeader opaqueLsaHeader1;
35 private int num;
36 private byte[] result;
37 private int result1;
38
39 @Before
40 public void setUp() throws Exception {
41 opaqueHeader = new OpaqueLsaHeader();
42 }
43
44 @After
45 public void tearDown() throws Exception {
46 opaqueHeader = null;
47 opaqueLsaHeader1 = null;
48 result = null;
49 }
50
51 /**
52 * Tests populateHeader() method.
53 */
54 @Test
55 public void testPopulateHeader() throws Exception {
56 opaqueLsaHeader1 = new OpaqueLsaHeader();
57 opaqueLsaHeader1.setLsPacketLen(10);
58 opaqueLsaHeader1.setAdvertisingRouter(Ip4Address.valueOf("1.1.1.1"));
59 opaqueLsaHeader1.setOptions(2);
60 opaqueLsaHeader1.setAge(20);
61 opaqueLsaHeader1.setLsType(3);
62 opaqueLsaHeader1.setOpaqueId(1);
63 opaqueLsaHeader1.setOpaqueType(3);
64 opaqueLsaHeader1.setLsCheckSum(1234);
65 opaqueLsaHeader1.setLsSequenceNo(456789);
66 opaqueLsaHeader1.populateHeader(opaqueLsaHeader1);
67 assertThat(opaqueLsaHeader1, is(notNullValue()));
68 }
69
70 /**
71 * Tests opaqueId() getter method.
72 */
73 @Test
74 public void testGetOpaqueId() throws Exception {
75 opaqueHeader.setOpaqueId(1);
76 num = opaqueHeader.opaqueId();
77 assertThat(num, is(1));
78 }
79
80 /**
81 * Tests opaqueId() setter method.
82 */
83 @Test
84 public void testSetOpaqueId() throws Exception {
85 opaqueHeader.setOpaqueId(1);
86 num = opaqueHeader.opaqueId();
87 assertThat(num, is(1));
88 }
89
90 /**
91 * Tests opaqueType() getter method.
92 */
93 @Test
94 public void testGetOpaqueType() throws Exception {
95 opaqueHeader.setOpaqueType(1);
96 num = opaqueHeader.opaqueType();
97 assertThat(num, is(1));
98 }
99
100 /**
101 * Tests opaqueType() setter method.
102 */
103 @Test
104 public void testSetOpaqueType() throws Exception {
105 opaqueHeader.setOpaqueType(1);
106 num = opaqueHeader.opaqueType();
107 assertThat(num, is(1));
108 }
109
110 /**
111 * Tests getOpaqueLsaHeaderAsByteArray() method.
112 */
113 @Test
114 public void testGetOpaqueLsaHeaderAsByteArray() throws Exception {
115 result = opaqueHeader.getOpaqueLsaHeaderAsByteArray();
116 assertThat(result, is(notNullValue()));
117 }
118
119 /**
120 * Tests to string method.
121 */
122 @Test
123 public void testToString() throws Exception {
124 assertThat(opaqueHeader.toString(), is(notNullValue()));
125 }
126
127 /**
128 * Tests hashCode() method.
129 */
130 @Test
131 public void testHashcode() throws Exception {
132
133 result1 = opaqueHeader.hashCode();
134 assertThat(result1, is(Matchers.notNullValue()));
135
136 }
137}