Committed by
Thomas Vachuska
ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests
Change-Id: I7cb129186a99bbf3d20fd6731485e3d84905e939
Showing
9 changed files
with
926 additions
and
0 deletions
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/ConfigurationTest.java
0 → 100755
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.controller.area; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.ospf.controller.OspfProcess; | ||
22 | + | ||
23 | +import java.util.ArrayList; | ||
24 | +import java.util.List; | ||
25 | + | ||
26 | +import static org.hamcrest.CoreMatchers.is; | ||
27 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
28 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
29 | + | ||
30 | +/** | ||
31 | + * Unit test class for Configuration. | ||
32 | + */ | ||
33 | +public class ConfigurationTest { | ||
34 | + private Configuration configuration; | ||
35 | + private List<OspfProcess> ospfProcesses; | ||
36 | + private List result; | ||
37 | + private OspfProcessImpl ospfProcessImpl; | ||
38 | + | ||
39 | + @Before | ||
40 | + public void setUp() throws Exception { | ||
41 | + configuration = new Configuration(); | ||
42 | + } | ||
43 | + | ||
44 | + @After | ||
45 | + public void tearDown() throws Exception { | ||
46 | + configuration = null; | ||
47 | + ospfProcessImpl = new OspfProcessImpl(); | ||
48 | + result = null; | ||
49 | + ospfProcesses = null; | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Tests getProcesses() getter method. | ||
54 | + */ | ||
55 | + @Test | ||
56 | + public void testGetOspfProcess() throws Exception { | ||
57 | + ospfProcesses = new ArrayList(); | ||
58 | + ospfProcesses.add(ospfProcessImpl); | ||
59 | + ospfProcesses.add(ospfProcessImpl); | ||
60 | + configuration.setProcesses(ospfProcesses); | ||
61 | + result = configuration.getProcesses(); | ||
62 | + assertThat(result.size(), is(2)); | ||
63 | + } | ||
64 | + | ||
65 | + /** | ||
66 | + * Tests setProcesses() setter method. | ||
67 | + */ | ||
68 | + @Test | ||
69 | + public void testSetOspfProcess() throws Exception { | ||
70 | + ospfProcesses = new ArrayList(); | ||
71 | + ospfProcesses.add(ospfProcessImpl); | ||
72 | + ospfProcesses.add(ospfProcessImpl); | ||
73 | + configuration.setProcesses(ospfProcesses); | ||
74 | + result = configuration.getProcesses(); | ||
75 | + assertThat(result.size(), is(2)); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Tests getMethod() getter method. | ||
80 | + */ | ||
81 | + @Test | ||
82 | + public void testGetMethod() throws Exception { | ||
83 | + configuration.setMethod("method"); | ||
84 | + assertThat(configuration.getMethod(), is("method")); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Tests setMethod() setter method. | ||
89 | + */ | ||
90 | + @Test | ||
91 | + public void testSetMethod() throws Exception { | ||
92 | + configuration.setMethod("method"); | ||
93 | + assertThat(configuration.getMethod(), is("method")); | ||
94 | + } | ||
95 | + | ||
96 | + /** | ||
97 | + * Tests to string method. | ||
98 | + */ | ||
99 | + @Test | ||
100 | + public void testToString() throws Exception { | ||
101 | + assertThat(configuration.toString(), is(notNullValue())); | ||
102 | + } | ||
103 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.controller.area; | ||
17 | + | ||
18 | + | ||
19 | +import org.easymock.EasyMock; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onlab.packet.Ip4Address; | ||
24 | +import org.onosproject.ospf.controller.OspfAreaAddressRange; | ||
25 | + | ||
26 | +import static org.hamcrest.CoreMatchers.is; | ||
27 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
28 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
29 | + | ||
30 | +/** | ||
31 | + * Unit test class for OspfAreaAddressRangeImpl. | ||
32 | + */ | ||
33 | +public class OspfAreaAddressRangeImplTest { | ||
34 | + | ||
35 | + private OspfAreaAddressRange ospfAreaAddressRange; | ||
36 | + private int result; | ||
37 | + private String result1; | ||
38 | + | ||
39 | + @Before | ||
40 | + public void setUp() throws Exception { | ||
41 | + ospfAreaAddressRange = new OspfAreaAddressRangeImpl(); | ||
42 | + } | ||
43 | + | ||
44 | + @After | ||
45 | + public void tearDown() throws Exception { | ||
46 | + ospfAreaAddressRange = null; | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Tests ipAddress() getter method. | ||
51 | + */ | ||
52 | + @Test | ||
53 | + public void testGetIpAddress() throws Exception { | ||
54 | + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
55 | + assertThat(ospfAreaAddressRange.ipAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Tests ipAddress() setter method. | ||
60 | + */ | ||
61 | + @Test | ||
62 | + public void testSetIpAddress() throws Exception { | ||
63 | + ospfAreaAddressRange.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
64 | + assertThat(ospfAreaAddressRange.ipAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Tests mask() getter method. | ||
69 | + */ | ||
70 | + @Test | ||
71 | + public void testGetMask() throws Exception { | ||
72 | + ospfAreaAddressRange.setMask("1.1.1.1"); | ||
73 | + assertThat(ospfAreaAddressRange.mask(), is("1.1.1.1")); | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * Tests mask() setter method. | ||
78 | + */ | ||
79 | + @Test | ||
80 | + public void testSetMask() throws Exception { | ||
81 | + ospfAreaAddressRange.setMask("1.1.1.1"); | ||
82 | + assertThat(ospfAreaAddressRange.mask(), is("1.1.1.1")); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Tests isAdvertise() getter method. | ||
87 | + */ | ||
88 | + @Test | ||
89 | + public void testIsAdvertise() throws Exception { | ||
90 | + ospfAreaAddressRange.setAdvertise(true); | ||
91 | + assertThat(ospfAreaAddressRange.isAdvertise(), is(true)); | ||
92 | + } | ||
93 | + | ||
94 | + /** | ||
95 | + * Tests isAdvertise() setter method. | ||
96 | + */ | ||
97 | + @Test | ||
98 | + public void testSetAdvertise() throws Exception { | ||
99 | + ospfAreaAddressRange.setAdvertise(true); | ||
100 | + assertThat(ospfAreaAddressRange.isAdvertise(), is(true)); | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Tests equals() method. | ||
105 | + */ | ||
106 | + @Test | ||
107 | + public void testEquals() throws Exception { | ||
108 | + assertThat(ospfAreaAddressRange.equals(new OspfAreaAddressRangeImpl()), is(false)); | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * Tests equals() method. | ||
113 | + */ | ||
114 | + @Test | ||
115 | + public void testEquals1() throws Exception { | ||
116 | + assertThat(ospfAreaAddressRange.equals(EasyMock.createMock(OspfAreaAddressRange.class)), is(false)); | ||
117 | + } | ||
118 | + | ||
119 | + @Test | ||
120 | + public void testHashCode() throws Exception { | ||
121 | + result = ospfAreaAddressRange.hashCode(); | ||
122 | + assertThat(result, is(notNullValue())); | ||
123 | + } | ||
124 | + | ||
125 | + /** | ||
126 | + * Tests to string method. | ||
127 | + */ | ||
128 | + @Test | ||
129 | + public void testToString() throws Exception { | ||
130 | + result1 = ospfAreaAddressRange.toString(); | ||
131 | + assertThat(result1, is(notNullValue())); | ||
132 | + } | ||
133 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/area/OspfAreaImplTest.java
0 → 100755
This diff is collapsed. Click to expand it.
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaBinImplTest.java
0 → 100755
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.controller.lsdb; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onosproject.ospf.controller.LsaWrapper; | ||
22 | +import org.onosproject.ospf.protocol.lsa.LsaHeader; | ||
23 | + | ||
24 | +import static org.hamcrest.CoreMatchers.is; | ||
25 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
26 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
27 | + | ||
28 | +/** | ||
29 | + * Unit test class for LsaBinImpl. | ||
30 | + */ | ||
31 | +public class LsaBinImplTest { | ||
32 | + private LsaBinImpl lsaBin; | ||
33 | + private LsaHeader ospflsa1; | ||
34 | + private LsaWrapper lsaWrapper; | ||
35 | + | ||
36 | + | ||
37 | + @Before | ||
38 | + public void setUp() throws Exception { | ||
39 | + ospflsa1 = new LsaHeader(); | ||
40 | + ospflsa1.setAge(20); | ||
41 | + lsaBin = new LsaBinImpl(1); | ||
42 | + } | ||
43 | + | ||
44 | + @After | ||
45 | + public void tearDown() throws Exception { | ||
46 | + ospflsa1 = null; | ||
47 | + lsaBin = null; | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Tests binNumber() getter method. | ||
52 | + */ | ||
53 | + @Test | ||
54 | + public void testGetBinNumber() throws Exception { | ||
55 | + lsaWrapper = new LsaWrapperImpl(); | ||
56 | + lsaBin.addOspfLsa("lsa1", lsaWrapper); | ||
57 | + assertThat(lsaBin.binNumber(), is(1)); | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Tests addOspfLsa() method. | ||
62 | + */ | ||
63 | + @Test | ||
64 | + public void testAddOspfLsa() throws Exception { | ||
65 | + LsaWrapper lsaWrapper = new LsaWrapperImpl(); | ||
66 | + lsaBin.addOspfLsa("lsa1", lsaWrapper); | ||
67 | + assertThat(lsaBin, is(notNullValue())); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Tests ospfLsa() getter method. | ||
72 | + */ | ||
73 | + @Test | ||
74 | + public void testGetOspfLsa() throws Exception { | ||
75 | + lsaWrapper = new LsaWrapperImpl(); | ||
76 | + lsaBin.addOspfLsa("lsa1", lsaWrapper); | ||
77 | + assertThat(lsaBin, is(notNullValue())); | ||
78 | + assertThat(lsaBin.ospfLsa("lsa1"), is(lsaWrapper)); | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * Tests removeOspfLsa() method. | ||
83 | + */ | ||
84 | + @Test | ||
85 | + public void testRemoveOspfLsa() throws Exception { | ||
86 | + lsaWrapper = new LsaWrapperImpl(); | ||
87 | + lsaBin.addOspfLsa("lsa1", lsaWrapper); | ||
88 | + lsaBin.removeOspfLsa("lsa1", lsaWrapper); | ||
89 | + assertThat(lsaBin, is(notNullValue())); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Tests listOfLsa() method. | ||
94 | + */ | ||
95 | + @Test | ||
96 | + public void testGetListOfLsa() throws Exception { | ||
97 | + lsaWrapper = new LsaWrapperImpl(); | ||
98 | + lsaBin.addOspfLsa("lsa1", lsaWrapper); | ||
99 | + assertThat(lsaBin.listOfLsa().size(), is(1)); | ||
100 | + } | ||
101 | + | ||
102 | + /** | ||
103 | + * Tests to string method. | ||
104 | + */ | ||
105 | + @Test | ||
106 | + public void testToString() throws Exception { | ||
107 | + assertThat(lsaBin.toString(), is(notNullValue())); | ||
108 | + } | ||
109 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaQueueConsumerTest.java
0 → 100755
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.controller.lsdb; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.channel.Channel; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Before; | ||
22 | +import org.junit.Test; | ||
23 | +import org.onosproject.ospf.controller.LsaWrapper; | ||
24 | +import org.onosproject.ospf.controller.OspfArea; | ||
25 | +import org.onosproject.ospf.controller.OspfLsaType; | ||
26 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
27 | +import org.onosproject.ospf.controller.area.OspfInterfaceImpl; | ||
28 | +import org.onosproject.ospf.protocol.lsa.LsaHeader; | ||
29 | +import org.onosproject.ospf.protocol.lsa.types.RouterLsa; | ||
30 | +import org.onosproject.ospf.protocol.util.OspfInterfaceState; | ||
31 | + | ||
32 | +import java.util.concurrent.ArrayBlockingQueue; | ||
33 | +import java.util.concurrent.BlockingQueue; | ||
34 | + | ||
35 | +import static org.hamcrest.CoreMatchers.is; | ||
36 | +import static org.hamcrest.CoreMatchers.notNullValue; | ||
37 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
38 | + | ||
39 | +/** | ||
40 | + * Unit test class for LsaQueueConsumer. | ||
41 | + */ | ||
42 | +public class LsaQueueConsumerTest { | ||
43 | + private LsaQueueConsumer lsaQueueConsumer; | ||
44 | + private BlockingQueue<LsaWrapper> blockingQueue; | ||
45 | + private Channel channel; | ||
46 | + private LsaWrapperImpl lsaWrapper; | ||
47 | + private OspfArea ospfArea; | ||
48 | + private RouterLsa routerLsa; | ||
49 | + private OspfInterfaceImpl ospfInterface; | ||
50 | + private LsaHeader lsaHeader; | ||
51 | + private LsdbAgeImpl lsdbAge; | ||
52 | + | ||
53 | + @Before | ||
54 | + public void setUp() throws Exception { | ||
55 | + lsaQueueConsumer = EasyMock.createMock(LsaQueueConsumer.class); | ||
56 | + } | ||
57 | + | ||
58 | + @After | ||
59 | + public void tearDown() throws Exception { | ||
60 | + lsaQueueConsumer = null; | ||
61 | + blockingQueue = null; | ||
62 | + channel = null; | ||
63 | + lsaWrapper = null; | ||
64 | + lsdbAge = null; | ||
65 | + lsaHeader = null; | ||
66 | + ospfInterface = null; | ||
67 | + ospfArea = null; | ||
68 | + routerLsa = null; | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * Tests run() method. | ||
73 | + */ | ||
74 | + @Test | ||
75 | + public void testRun() throws Exception { | ||
76 | + blockingQueue = new ArrayBlockingQueue(5); | ||
77 | + channel = EasyMock.createMock(Channel.class); | ||
78 | + ospfArea = new OspfAreaImpl(); | ||
79 | + lsaWrapper = new LsaWrapperImpl(); | ||
80 | + lsaWrapper.setLsaProcessing("verifyChecksum"); | ||
81 | + blockingQueue.add(lsaWrapper); | ||
82 | + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); | ||
83 | + lsaQueueConsumer.run(); | ||
84 | + assertThat(lsaQueueConsumer, is(notNullValue())); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Tests run() method. | ||
89 | + */ | ||
90 | + @Test | ||
91 | + public void testRun1() throws Exception { | ||
92 | + blockingQueue = new ArrayBlockingQueue(5); | ||
93 | + channel = EasyMock.createMock(Channel.class); | ||
94 | + ospfArea = new OspfAreaImpl(); | ||
95 | + lsaWrapper = new LsaWrapperImpl(); | ||
96 | + routerLsa = new RouterLsa(); | ||
97 | + routerLsa.setLsType(1); | ||
98 | + lsaWrapper.addLsa(OspfLsaType.ROUTER, routerLsa); | ||
99 | + ospfInterface = new OspfInterfaceImpl(); | ||
100 | + ospfInterface.setState(OspfInterfaceState.DR); | ||
101 | + lsaWrapper.setOspfInterface(ospfInterface); | ||
102 | + lsaWrapper.setIsSelfOriginated(true); | ||
103 | + lsaHeader = new LsaHeader(); | ||
104 | + lsaHeader.setLsType(1); | ||
105 | + lsaWrapper.setLsaHeader(lsaHeader); | ||
106 | + lsaWrapper.setLsaProcessing("refreshLsa"); | ||
107 | + lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); | ||
108 | + blockingQueue.add(lsaWrapper); | ||
109 | + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); | ||
110 | + lsaQueueConsumer.run(); | ||
111 | + assertThat(lsaQueueConsumer, is(notNullValue())); | ||
112 | + } | ||
113 | + | ||
114 | + @Test | ||
115 | + public void testRun3() throws Exception { | ||
116 | + blockingQueue = new ArrayBlockingQueue(5); | ||
117 | + channel = EasyMock.createMock(Channel.class); | ||
118 | + ospfArea = new OspfAreaImpl(); | ||
119 | + lsaWrapper = new LsaWrapperImpl(); | ||
120 | + routerLsa = new RouterLsa(); | ||
121 | + routerLsa.setLsType(2); | ||
122 | + lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa); | ||
123 | + ospfInterface = new OspfInterfaceImpl(); | ||
124 | + ospfInterface.setState(OspfInterfaceState.BDR); | ||
125 | + lsaWrapper.setOspfInterface(ospfInterface); | ||
126 | + lsaWrapper.setIsSelfOriginated(true); | ||
127 | + lsaHeader = new LsaHeader(); | ||
128 | + lsaHeader.setLsType(2); | ||
129 | + lsaWrapper.setLsaHeader(lsaHeader); | ||
130 | + lsaWrapper.setLsaProcessing("refreshLsa"); | ||
131 | + lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); | ||
132 | + blockingQueue.add(lsaWrapper); | ||
133 | + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); | ||
134 | + lsaQueueConsumer.run(); | ||
135 | + assertThat(lsaQueueConsumer, is(notNullValue())); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * Tests run() method. | ||
140 | + */ | ||
141 | + @Test | ||
142 | + public void testRun5() throws Exception { | ||
143 | + blockingQueue = new ArrayBlockingQueue(5); | ||
144 | + channel = EasyMock.createMock(Channel.class); | ||
145 | + ospfArea = new OspfAreaImpl(); | ||
146 | + lsaWrapper = new LsaWrapperImpl(); | ||
147 | + routerLsa = new RouterLsa(); | ||
148 | + routerLsa.setLsType(2); | ||
149 | + lsaWrapper.addLsa(OspfLsaType.NETWORK, routerLsa); | ||
150 | + ospfInterface = new OspfInterfaceImpl(); | ||
151 | + ospfInterface.setState(OspfInterfaceState.DR); | ||
152 | + lsaWrapper.setOspfInterface(ospfInterface); | ||
153 | + lsaWrapper.setIsSelfOriginated(true); | ||
154 | + lsaHeader = new LsaHeader(); | ||
155 | + lsaHeader.setLsType(2); | ||
156 | + lsaWrapper.setLsaHeader(lsaHeader); | ||
157 | + lsaWrapper.setLsaProcessing("maxAgeLsa"); | ||
158 | + lsaWrapper.setLsdbAge(new LsdbAgeImpl(new OspfAreaImpl())); | ||
159 | + blockingQueue.add(lsaWrapper); | ||
160 | + lsaQueueConsumer = new LsaQueueConsumer(blockingQueue, channel, ospfArea); | ||
161 | + lsaQueueConsumer.run(); | ||
162 | + assertThat(lsaQueueConsumer, is(notNullValue())); | ||
163 | + } | ||
164 | + | ||
165 | + /** | ||
166 | + * Tests setChannel() method. | ||
167 | + */ | ||
168 | + @Test | ||
169 | + public void testSetChannel() throws Exception { | ||
170 | + channel = EasyMock.createMock(Channel.class); | ||
171 | + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); | ||
172 | + lsdbAge.startDbAging(); | ||
173 | + lsdbAge.setChannel(channel); | ||
174 | + assertThat(lsaQueueConsumer, is(notNullValue())); | ||
175 | + } | ||
176 | + | ||
177 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsaWrapperImplTest.java
0 → 100755
This diff is collapsed. Click to expand it.
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/LsdbAgeImplTest.java
0 → 100755
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.controller.lsdb; | ||
17 | + | ||
18 | +import org.easymock.EasyMock; | ||
19 | +import org.jboss.netty.channel.Channel; | ||
20 | +import org.junit.After; | ||
21 | +import org.junit.Assert; | ||
22 | +import org.junit.Before; | ||
23 | +import org.junit.Test; | ||
24 | +import org.onosproject.ospf.controller.LsaBin; | ||
25 | +import org.onosproject.ospf.controller.OspfArea; | ||
26 | +import org.onosproject.ospf.controller.area.OspfAreaImpl; | ||
27 | + | ||
28 | +import static org.hamcrest.CoreMatchers.*; | ||
29 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
30 | + | ||
31 | +/** | ||
32 | + * Unit test class for LsdbAgeImpl. | ||
33 | + */ | ||
34 | +public class LsdbAgeImplTest { | ||
35 | + private LsdbAgeImpl lsdbAge; | ||
36 | + private OspfAreaImpl ospfAreaImpl; | ||
37 | + private LsaBinImpl lsaBin; | ||
38 | + private LsaBin lsaBin1; | ||
39 | + private LsaWrapperImpl lsaWrapper; | ||
40 | + private OspfArea ospfArea; | ||
41 | + private Channel channel; | ||
42 | + | ||
43 | + @Before | ||
44 | + public void setUp() throws Exception { | ||
45 | + ospfAreaImpl = EasyMock.createMock(OspfAreaImpl.class); | ||
46 | + lsdbAge = new LsdbAgeImpl(ospfAreaImpl); | ||
47 | + } | ||
48 | + | ||
49 | + @After | ||
50 | + public void tearDown() throws Exception { | ||
51 | + lsdbAge = null; | ||
52 | + lsaBin = null; | ||
53 | + lsaBin1 = null; | ||
54 | + ospfAreaImpl = null; | ||
55 | + lsaWrapper = null; | ||
56 | + channel = null; | ||
57 | + ospfArea = null; | ||
58 | + } | ||
59 | + | ||
60 | + /** | ||
61 | + * Tests getLsaBin() method. | ||
62 | + */ | ||
63 | + @Test | ||
64 | + public void testGetLsaBin() throws Exception { | ||
65 | + lsaBin = new LsaBinImpl(1); | ||
66 | + lsdbAge.addLsaBin(1, lsaBin); | ||
67 | + assertThat(lsdbAge, is(notNullValue())); | ||
68 | + lsaBin1 = lsdbAge.getLsaBin(1); | ||
69 | + assertThat(lsaBin, instanceOf(LsaBin.class)); | ||
70 | + assertThat(lsaBin1, instanceOf(LsaBin.class)); | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * Tests addLsaBin() method. | ||
75 | + */ | ||
76 | + @Test | ||
77 | + public void testAddLsaBin() throws Exception { | ||
78 | + lsaBin = new LsaBinImpl(1); | ||
79 | + lsdbAge.addLsaBin(1, lsaBin); | ||
80 | + assertThat(lsdbAge, is(notNullValue())); | ||
81 | + assertThat(lsaBin, instanceOf(LsaBin.class)); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Tests equals() method. | ||
86 | + */ | ||
87 | + @Test | ||
88 | + public void testEquals() throws Exception { | ||
89 | + assertThat(lsdbAge.equals(lsdbAge), is(true)); | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Tests hashCode() method. | ||
94 | + */ | ||
95 | + @Test | ||
96 | + public void testHashCode() throws Exception { | ||
97 | + int hashCode = lsdbAge.hashCode(); | ||
98 | + assertThat(hashCode, is(notNullValue())); | ||
99 | + } | ||
100 | + | ||
101 | + /** | ||
102 | + * Tests addLsaToMaxAgeBin() method. | ||
103 | + */ | ||
104 | + @Test | ||
105 | + public void testAddLsaToMaxAgeBin() throws Exception { | ||
106 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
107 | + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); | ||
108 | + assertThat(lsdbAge, is(notNullValue())); | ||
109 | + } | ||
110 | + | ||
111 | + /** | ||
112 | + * Tests removeLsaFromBin() method. | ||
113 | + */ | ||
114 | + @Test | ||
115 | + public void testRemoveLsaFromBin() throws Exception { | ||
116 | + lsaBin = EasyMock.createMock(LsaBinImpl.class); | ||
117 | + lsaWrapper = new LsaWrapperImpl(); | ||
118 | + lsaWrapper.setBinNumber(-1); | ||
119 | + lsaBin.addOspfLsa("1", lsaWrapper); | ||
120 | + lsdbAge.startDbAging(); | ||
121 | + lsdbAge.addLsaToMaxAgeBin("3600", lsaWrapper); | ||
122 | + lsdbAge.addLsaBin(-1, lsaBin); | ||
123 | + lsdbAge.removeLsaFromBin(lsaWrapper); | ||
124 | + assertThat(lsdbAge, is(notNullValue())); | ||
125 | + } | ||
126 | + | ||
127 | + /** | ||
128 | + * Tests startDbAging() method. | ||
129 | + */ | ||
130 | + @Test | ||
131 | + public void testStartDbAging() throws Exception { | ||
132 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
133 | + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); | ||
134 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
135 | + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper); | ||
136 | + lsdbAge.startDbAging(); | ||
137 | + assertThat(lsdbAge, is(notNullValue())); | ||
138 | + } | ||
139 | + | ||
140 | + /** | ||
141 | + * Tests ageLsaAndFlood() method. | ||
142 | + */ | ||
143 | + @Test | ||
144 | + public void testAgeLsaAndFlood() throws Exception { | ||
145 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
146 | + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); | ||
147 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
148 | + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper); | ||
149 | + lsdbAge.startDbAging(); | ||
150 | + lsdbAge.ageLsaAndFlood(); | ||
151 | + Assert.assertNotNull(lsdbAge); | ||
152 | + } | ||
153 | + | ||
154 | + /** | ||
155 | + * Tests maxAgeLsa() method. | ||
156 | + */ | ||
157 | + @Test | ||
158 | + public void testMaxageLsa() throws Exception { | ||
159 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
160 | + ospfArea = new OspfAreaImpl(); | ||
161 | + lsdbAge = new LsdbAgeImpl(ospfArea); | ||
162 | + lsaWrapper.setLsdbAge(lsdbAge); | ||
163 | + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); | ||
164 | + lsaBin = new LsaBinImpl(1); | ||
165 | + lsaBin.addOspfLsa("1", lsaWrapper); | ||
166 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
167 | + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper); | ||
168 | + lsaBin.addOspfLsa("2", lsaWrapper); | ||
169 | + lsdbAge.startDbAging(); | ||
170 | + lsdbAge = new LsdbAgeImpl(new OspfAreaImpl()); | ||
171 | + lsdbAge.ageLsaAndFlood(); | ||
172 | + lsdbAge.maxAgeLsa(); | ||
173 | + assertThat(lsdbAge, is(notNullValue())); | ||
174 | + | ||
175 | + } | ||
176 | + | ||
177 | + /** | ||
178 | + * Tests refreshLsa() method. | ||
179 | + */ | ||
180 | + @Test | ||
181 | + public void testRefereshLsa() throws Exception { | ||
182 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
183 | + lsaWrapper.setBinNumber(0); | ||
184 | + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); | ||
185 | + lsdbAge.ageLsaAndFlood(); | ||
186 | + lsaWrapper.setBinNumber(0); | ||
187 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
188 | + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper); | ||
189 | + lsdbAge.ageLsaAndFlood(); | ||
190 | + lsdbAge.startDbAging(); | ||
191 | + lsaBin = new LsaBinImpl(1809); | ||
192 | + lsdbAge.refreshLsa(); | ||
193 | + assertThat(lsdbAge, is(notNullValue())); | ||
194 | + } | ||
195 | + | ||
196 | + /** | ||
197 | + * Tests checkAges() method. | ||
198 | + */ | ||
199 | + @Test | ||
200 | + public void testCheckAges() throws Exception { | ||
201 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
202 | + lsdbAge.addLsaToMaxAgeBin("lsa1", lsaWrapper); | ||
203 | + lsaWrapper = EasyMock.createMock(LsaWrapperImpl.class); | ||
204 | + lsdbAge.addLsaToMaxAgeBin("lsa2", lsaWrapper); | ||
205 | + lsdbAge.startDbAging(); | ||
206 | + lsdbAge.checkAges(); | ||
207 | + assertThat(lsdbAge, is(notNullValue())); | ||
208 | + | ||
209 | + } | ||
210 | + | ||
211 | + /** | ||
212 | + * Tests getChannel() getter method. | ||
213 | + */ | ||
214 | + @Test | ||
215 | + public void testGetChannel() throws Exception { | ||
216 | + channel = EasyMock.createMock(Channel.class); | ||
217 | + lsdbAge.setChannel(channel); | ||
218 | + assertThat(lsdbAge.getChannel(), is(notNullValue())); | ||
219 | + } | ||
220 | + | ||
221 | + /** | ||
222 | + * Tests setChannel() setter method. | ||
223 | + */ | ||
224 | + @Test | ||
225 | + public void testSetChannel() throws Exception { | ||
226 | + channel = EasyMock.createMock(Channel.class); | ||
227 | + lsdbAge.setChannel(channel); | ||
228 | + assertThat(lsdbAge.getChannel(), is(notNullValue())); | ||
229 | + } | ||
230 | + | ||
231 | + /** | ||
232 | + * Tests getAgeCounter() method. | ||
233 | + */ | ||
234 | + @Test | ||
235 | + public void testGetAgeCounter() throws Exception { | ||
236 | + lsaBin = new LsaBinImpl(1); | ||
237 | + lsdbAge.addLsaBin(1, lsaBin); | ||
238 | + int age = lsdbAge.getAgeCounter(); | ||
239 | + assertThat(age, is(notNullValue())); | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | + * Tests getAgeCounterRollOver() method. | ||
244 | + */ | ||
245 | + @Test | ||
246 | + public void testGetAgeCounterRollOver() throws Exception { | ||
247 | + lsaBin = new LsaBinImpl(1); | ||
248 | + lsdbAge.addLsaBin(1, lsaBin); | ||
249 | + lsdbAge.startDbAging(); | ||
250 | + assertThat(lsdbAge.getAgeCounterRollOver(), is(notNullValue())); | ||
251 | + } | ||
252 | + | ||
253 | + /** | ||
254 | + * Tests getMaxAgeBin() method. | ||
255 | + */ | ||
256 | + @Test | ||
257 | + public void testGetMaxAgeBin() throws Exception { | ||
258 | + lsaBin = new LsaBinImpl(1); | ||
259 | + lsdbAge.addLsaBin(1, lsaBin); | ||
260 | + lsdbAge.startDbAging(); | ||
261 | + assertThat(lsdbAge.getMaxAgeBin(), is(notNullValue())); | ||
262 | + } | ||
263 | + | ||
264 | + /** | ||
265 | + * Tests age2Bin() method. | ||
266 | + */ | ||
267 | + @Test | ||
268 | + public void testAge2Bin() throws Exception { | ||
269 | + int age = lsdbAge.age2Bin(0); | ||
270 | + assertThat(age, is(notNullValue())); | ||
271 | + } | ||
272 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/lsdb/OspfLsdbImplTest.java
0 → 100755
This diff is collapsed. Click to expand it.
protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/util/OspfEligibleRouterTest.java
0 → 100755
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.controller.util; | ||
17 | + | ||
18 | +import org.junit.After; | ||
19 | +import org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | +import org.onlab.packet.Ip4Address; | ||
22 | + | ||
23 | +import static org.hamcrest.CoreMatchers.is; | ||
24 | +import static org.hamcrest.MatcherAssert.assertThat; | ||
25 | + | ||
26 | +/** | ||
27 | + * Unit test class for OspfEligibleRouter. | ||
28 | + */ | ||
29 | +public class OspfEligibleRouterTest { | ||
30 | + | ||
31 | + private OspfEligibleRouter ospfEligibleRouter; | ||
32 | + | ||
33 | + @Before | ||
34 | + public void setUp() throws Exception { | ||
35 | + ospfEligibleRouter = new OspfEligibleRouter(); | ||
36 | + } | ||
37 | + | ||
38 | + @After | ||
39 | + public void tearDown() throws Exception { | ||
40 | + ospfEligibleRouter = null; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * Tests getIpAddress() getter method. | ||
45 | + */ | ||
46 | + @Test | ||
47 | + public void testGetIpAddress() throws Exception { | ||
48 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
49 | + assertThat(ospfEligibleRouter.getIpAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * Tests setIpAddress() setter method. | ||
54 | + */ | ||
55 | + @Test | ||
56 | + public void testSetIpAddress() throws Exception { | ||
57 | + ospfEligibleRouter.setIpAddress(Ip4Address.valueOf("1.1.1.1")); | ||
58 | + assertThat(ospfEligibleRouter.getIpAddress(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Tests getRouterId() getter method. | ||
63 | + */ | ||
64 | + @Test | ||
65 | + public void testGetRouterId() throws Exception { | ||
66 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
67 | + assertThat(ospfEligibleRouter.getRouterId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
68 | + } | ||
69 | + | ||
70 | + /** | ||
71 | + * Tests setRouterId() setter method. | ||
72 | + */ | ||
73 | + @Test | ||
74 | + public void testSetRouterId() throws Exception { | ||
75 | + ospfEligibleRouter.setRouterId(Ip4Address.valueOf("1.1.1.1")); | ||
76 | + assertThat(ospfEligibleRouter.getRouterId(), is(Ip4Address.valueOf("1.1.1.1"))); | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Tests getRouterPriority() getter method. | ||
81 | + */ | ||
82 | + @Test | ||
83 | + public void testGetRouterPriority() throws Exception { | ||
84 | + ospfEligibleRouter.setRouterPriority(1); | ||
85 | + assertThat(ospfEligibleRouter.getRouterPriority(), is(1)); | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Tests getRouterPriority() setter method. | ||
90 | + */ | ||
91 | + @Test | ||
92 | + public void testSetRouterPriority() throws Exception { | ||
93 | + ospfEligibleRouter.setRouterPriority(1); | ||
94 | + assertThat(ospfEligibleRouter.getRouterPriority(), is(1)); | ||
95 | + } | ||
96 | + | ||
97 | + /** | ||
98 | + * Tests isDr() getter method. | ||
99 | + */ | ||
100 | + @Test | ||
101 | + public void testIsDr() throws Exception { | ||
102 | + ospfEligibleRouter.setIsDr(true); | ||
103 | + assertThat(ospfEligibleRouter.isDr(), is(true)); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Tests isDr() setter method. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testSetIsDr() throws Exception { | ||
111 | + ospfEligibleRouter.setIsDr(true); | ||
112 | + assertThat(ospfEligibleRouter.isDr(), is(true)); | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Tests isBdr() getter method. | ||
117 | + */ | ||
118 | + @Test | ||
119 | + public void testIsBdr() throws Exception { | ||
120 | + ospfEligibleRouter.setIsBdr(true); | ||
121 | + assertThat(ospfEligibleRouter.isBdr(), is(true)); | ||
122 | + } | ||
123 | + | ||
124 | + /** | ||
125 | + * Tests isBdr() setter method. | ||
126 | + */ | ||
127 | + @Test | ||
128 | + public void testSetIsBdr() throws Exception { | ||
129 | + ospfEligibleRouter.setIsBdr(true); | ||
130 | + assertThat(ospfEligibleRouter.isBdr(), is(true)); | ||
131 | + } | ||
132 | +} |
-
Please register or login to post a comment