Dhruv Dhody
Committed by Thomas Vachuska

ONOS-2740,ONOS-2741,from ONOS-3032 - to ONOS 3071 , OSPF Protocol Implementation Unit Tests

Change-Id: Ie7f02bd9bff16902647c7af406f7ece9cdf0ae6c
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.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.ospf.controller.OspfArea;
23 +
24 +import java.util.ArrayList;
25 +import java.util.List;
26 +
27 +import static org.hamcrest.MatcherAssert.assertThat;
28 +import static org.hamcrest.Matchers.is;
29 +import static org.hamcrest.Matchers.notNullValue;
30 +
31 +/**
32 + * Unit test class for OspfProcessImpl.
33 + */
34 +public class OspfProcessImplTest {
35 +
36 + private OspfProcessImpl ospfProcess;
37 + private List<OspfArea> list;
38 + private List result;
39 +
40 + @Before
41 + public void setUp() throws Exception {
42 + ospfProcess = new OspfProcessImpl();
43 + }
44 +
45 + @After
46 + public void tearDown() throws Exception {
47 + ospfProcess = null;
48 + list = null;
49 + }
50 +
51 + /**
52 + * Tests areas() getter method.
53 + */
54 + @Test
55 + public void testGetAreas() throws Exception {
56 + list = new ArrayList();
57 + list.add(new OspfAreaImpl());
58 + list.add(new OspfAreaImpl());
59 + ospfProcess.setAreas(list);
60 + result = ospfProcess.areas();
61 + assertThat(result.size(), is(2));
62 + }
63 +
64 + /**
65 + * Tests areas() setter method.
66 + */
67 + @Test
68 + public void testSetAreas() throws Exception {
69 + list = new ArrayList();
70 + list.add(new OspfAreaImpl());
71 + list.add(new OspfAreaImpl());
72 + ospfProcess.setAreas(list);
73 + result = ospfProcess.areas();
74 + assertThat(result.size(), is(2));
75 + }
76 +
77 + /**
78 + * Tests processId() getter method.
79 + */
80 + @Test
81 + public void testGetProcessId() throws Exception {
82 + ospfProcess.setProcessId("1.1.1.1");
83 + assertThat(ospfProcess.processId(), is("1.1.1.1"));
84 + }
85 +
86 + /**
87 + * Tests processId() setter method.
88 + */
89 + @Test
90 + public void testSetProcessId() throws Exception {
91 + ospfProcess.setProcessId("1.1.1.1");
92 + assertThat(ospfProcess.processId(), is("1.1.1.1"));
93 + }
94 +
95 + /**
96 + * Tests to string method.
97 + */
98 + @Test
99 + public void testToString() throws Exception {
100 + assertThat(ospfProcess.toString(), is(notNullValue()));
101 + }
102 +}
...\ 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.impl;
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.junit.Assert.assertThat;
25 +
26 +/**
27 + * Unit test class for DeviceInformationImpl.
28 + */
29 +public class DeviceInformationImplTest {
30 +
31 + private DeviceInformationImpl deviceInformation;
32 +
33 + @Before
34 + public void setUp() throws Exception {
35 + deviceInformation = new DeviceInformationImpl();
36 + }
37 +
38 + @After
39 + public void tearDown() throws Exception {
40 + deviceInformation = null;
41 + }
42 +
43 + /**
44 + * Tests routerId() getter method.
45 + */
46 + @Test
47 + public void testRouterId() throws Exception {
48 + deviceInformation.setRouterId(Ip4Address.valueOf("1.1.1.1"));
49 + assertThat(deviceInformation.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
50 + }
51 +
52 + /**
53 + * Tests routerId() setter method.
54 + */
55 + @Test
56 + public void testSetRouterId() throws Exception {
57 + deviceInformation.setRouterId(Ip4Address.valueOf("1.1.1.1"));
58 + assertThat(deviceInformation.routerId(), is(Ip4Address.valueOf("1.1.1.1")));
59 + }
60 +
61 + /**
62 + * Tests deviceId() getter method.
63 + */
64 + @Test
65 + public void testDeviceId() throws Exception {
66 + deviceInformation.setDeviceId(Ip4Address.valueOf("1.1.1.1"));
67 + assertThat(deviceInformation.deviceId(), is(Ip4Address.valueOf("1.1.1.1")));
68 + }
69 +
70 + /**
71 + * Tests deviceId() getter method.
72 + */
73 + @Test
74 + public void testSetDeviceId() throws Exception {
75 + deviceInformation.setDeviceId(Ip4Address.valueOf("1.1.1.1"));
76 + assertThat(deviceInformation.deviceId(), is(Ip4Address.valueOf("1.1.1.1")));
77 + }
78 +
79 + /**
80 + * Tests interfaceId() method.
81 + */
82 + @Test
83 + public void testInterfaceId() throws Exception {
84 + deviceInformation.addInterfaceId(Ip4Address.valueOf("1.1.1.1"));
85 + assertThat(deviceInformation.interfaceId().size(), is(1));
86 + }
87 +
88 + /**
89 + * Tests addInterfaceId() method.
90 + */
91 + @Test
92 + public void testAddInterfaceId() throws Exception {
93 + deviceInformation.addInterfaceId(Ip4Address.valueOf("1.1.1.1"));
94 + assertThat(deviceInformation.interfaceId().size(), is(1));
95 + }
96 +
97 + /**
98 + * Tests areaId() getter method.
99 + */
100 + @Test
101 + public void testAreaId() throws Exception {
102 + deviceInformation.setAreaId(Ip4Address.valueOf("1.1.1.1"));
103 + assertThat(deviceInformation.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
104 + }
105 +
106 + /**
107 + * Tests areaId() setter method.
108 + */
109 + @Test
110 + public void testSetAreaId() throws Exception {
111 + deviceInformation.setAreaId(Ip4Address.valueOf("1.1.1.1"));
112 + assertThat(deviceInformation.areaId(), is(Ip4Address.valueOf("1.1.1.1")));
113 + }
114 +
115 + /**
116 + * Tests isAlreadyCreated() getter method.
117 + */
118 + @Test
119 + public void testIsAlreadyCreated() throws Exception {
120 + deviceInformation.setAlreadyCreated(true);
121 + assertThat(deviceInformation.isAlreadyCreated(), is(true));
122 + }
123 +
124 + /**
125 + * Tests isAlreadyCreated() setter method.
126 + */
127 + @Test
128 + public void testSetAlreadyCreated() throws Exception {
129 + deviceInformation.setAlreadyCreated(true);
130 + assertThat(deviceInformation.isAlreadyCreated(), is(true));
131 + }
132 +
133 + /**
134 + * Tests isDr() getter method.
135 + */
136 + @Test
137 + public void testIsDr() throws Exception {
138 + deviceInformation.setDr(true);
139 + assertThat(deviceInformation.isDr(), is(true));
140 + }
141 +
142 + /**
143 + * Tests isDr() setter method.
144 + */
145 + @Test
146 + public void testSetDr() throws Exception {
147 + deviceInformation.setDr(true);
148 + assertThat(deviceInformation.isDr(), is(true));
149 + }
150 +
151 + /**
152 + * Tests neighborId() getter method.
153 + */
154 + @Test
155 + public void testNeighborId() throws Exception {
156 + deviceInformation.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
157 + assertThat(deviceInformation.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
158 + }
159 +
160 + /**
161 + * Tests neighborId() setter method.
162 + */
163 + @Test
164 + public void testSetNeighborId() throws Exception {
165 + deviceInformation.setNeighborId(Ip4Address.valueOf("1.1.1.1"));
166 + assertThat(deviceInformation.neighborId(), is(Ip4Address.valueOf("1.1.1.1")));
167 + }
168 +}
...\ 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.impl;
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.junit.Assert.assertThat;
25 +
26 +/**
27 + * Unit test class for LinkInformationImpl.
28 + */
29 +public class LinkInformationImplTest {
30 +
31 + private LinkInformationImpl linkInformation;
32 +
33 + @Before
34 + public void setUp() throws Exception {
35 + linkInformation = new LinkInformationImpl();
36 + }
37 +
38 + @After
39 + public void tearDown() throws Exception {
40 + linkInformation = null;
41 + }
42 +
43 + /**
44 + * Tests linkId() getter method.
45 + */
46 + @Test
47 + public void testLinkId() throws Exception {
48 + linkInformation.setLinkId("1.1.1.1");
49 + assertThat(linkInformation.linkId(), is("1.1.1.1"));
50 + }
51 +
52 + /**
53 + * Tests linkId() setter method.
54 + */
55 + @Test
56 + public void testSetLinkId() throws Exception {
57 + linkInformation.setLinkId("1.1.1.1");
58 + assertThat(linkInformation.linkId(), is("1.1.1.1"));
59 + }
60 +
61 + /**
62 + * Tests isAlreadyCreated() getter method.
63 + */
64 + @Test
65 + public void testIsAlreadyCreated() throws Exception {
66 + linkInformation.setAlreadyCreated(true);
67 + assertThat(linkInformation.isAlreadyCreated(), is(true));
68 + }
69 +
70 + /**
71 + * Tests isAlreadyCreated() setter method.
72 + */
73 + @Test
74 + public void testSetAlreadyCreated() throws Exception {
75 + linkInformation.setAlreadyCreated(true);
76 + assertThat(linkInformation.isAlreadyCreated(), is(true));
77 + }
78 +
79 + /**
80 + * Tests isLinkSrcIdNotRouterId() getter method.
81 + */
82 + @Test
83 + public void testIsLinkSrcIdNotRouterId() throws Exception {
84 + linkInformation.setLinkSrcIdNotRouterId(true);
85 + assertThat(linkInformation.isLinkSrcIdNotRouterId(), is(true));
86 + }
87 +
88 + /**
89 + * Tests isLinkSrcIdNotRouterId() setter method.
90 + */
91 + @Test
92 + public void testSetLinkSrcIdNotRouterId() throws Exception {
93 + linkInformation.setLinkSrcIdNotRouterId(true);
94 + assertThat(linkInformation.isLinkSrcIdNotRouterId(), is(true));
95 + }
96 +
97 + /**
98 + * Tests linkDestinationId() getter method.
99 + */
100 + @Test
101 + public void testLinkDestinationId() throws Exception {
102 + linkInformation.setLinkDestinationId(Ip4Address.valueOf("1.1.1.1"));
103 + assertThat(linkInformation.linkDestinationId(), is(Ip4Address.valueOf("1.1.1.1")));
104 + }
105 +
106 + /**
107 + * Tests linkDestinationId() setter method.
108 + */
109 + @Test
110 + public void testSetLinkDestinationId() throws Exception {
111 + linkInformation.setLinkDestinationId(Ip4Address.valueOf("1.1.1.1"));
112 + assertThat(linkInformation.linkDestinationId(), is(Ip4Address.valueOf("1.1.1.1")));
113 + }
114 +
115 + /**
116 + * Tests linkSourceId() getter method.
117 + */
118 + @Test
119 + public void testLinkSourceId() throws Exception {
120 + linkInformation.setLinkSourceId(Ip4Address.valueOf("1.1.1.1"));
121 + assertThat(linkInformation.linkSourceId(), is(Ip4Address.valueOf("1.1.1.1")));
122 + }
123 +
124 + /**
125 + * Tests linkSourceId() setter method.
126 + */
127 + @Test
128 + public void testSetLinkSourceId() throws Exception {
129 + linkInformation.setLinkSourceId(Ip4Address.valueOf("1.1.1.1"));
130 + assertThat(linkInformation.linkSourceId(), is(Ip4Address.valueOf("1.1.1.1")));
131 + }
132 +
133 + /**
134 + * Tests interfaceIp() getter method.
135 + */
136 + @Test
137 + public void testInterfaceIp() throws Exception {
138 + linkInformation.setInterfaceIp(Ip4Address.valueOf("1.1.1.1"));
139 + assertThat(linkInformation.interfaceIp(), is(Ip4Address.valueOf("1.1.1.1")));
140 + }
141 +
142 + /**
143 + * Tests interfaceIp() setter method.
144 + */
145 + @Test
146 + public void testSetInterfaceIp() throws Exception {
147 + linkInformation.setInterfaceIp(Ip4Address.valueOf("1.1.1.1"));
148 + assertThat(linkInformation.interfaceIp(), is(Ip4Address.valueOf("1.1.1.1")));
149 + }
150 +
151 + /**
152 + * Tests linkSourceIpAddress() getter method.
153 + */
154 + @Test
155 + public void testLinkSourceIpAddress() throws Exception {
156 + linkInformation.setLinkSourceIpAddress(Ip4Address.valueOf("1.1.1.1"));
157 + assertThat(linkInformation.linkSourceIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
158 + }
159 +
160 + /**
161 + * Tests linkSourceIpAddress() setter method.
162 + */
163 + @Test
164 + public void testSetLinkSourceIpAddress() throws Exception {
165 + linkInformation.setLinkSourceIpAddress(Ip4Address.valueOf("1.1.1.1"));
166 + assertThat(linkInformation.linkSourceIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
167 + }
168 +
169 + /**
170 + * Tests linkDestinationId() getter method.
171 + */
172 + @Test
173 + public void testLinkDestinationIpAddress() throws Exception {
174 + linkInformation.setLinkDestinationIpAddress(Ip4Address.valueOf("1.1.1.1"));
175 + assertThat(linkInformation.linkDestinationIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
176 + }
177 +
178 + /**
179 + * Tests linkDestinationId() setter method.
180 + */
181 + @Test
182 + public void testSetLinkDestinationIpAddress() throws Exception {
183 + linkInformation.setLinkDestinationIpAddress(Ip4Address.valueOf("1.1.1.1"));
184 + assertThat(linkInformation.linkDestinationIpAddress(), is(Ip4Address.valueOf("1.1.1.1")));
185 + }
186 +}
...\ 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.impl;
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.OspfArea;
25 +import org.onosproject.ospf.controller.OspfInterface;
26 +import org.onosproject.ospf.controller.OspfLinkListener;
27 +import org.onosproject.ospf.controller.OspfProcess;
28 +import org.onosproject.ospf.controller.OspfRouter;
29 +import org.onosproject.ospf.controller.OspfRouterListener;
30 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
31 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
32 +import org.onosproject.ospf.controller.area.OspfProcessImpl;
33 +
34 +import java.util.ArrayList;
35 +import java.util.List;
36 +
37 +import static org.hamcrest.CoreMatchers.is;
38 +import static org.hamcrest.CoreMatchers.notNullValue;
39 +import static org.hamcrest.MatcherAssert.assertThat;
40 +
41 +/**
42 + * Unit test class for OspfRouterId.
43 + */
44 +public class OspfControllerImplTest {
45 +
46 + private OspfControllerImpl ospfController;
47 + private OspfRouterListener ospfRouterListener;
48 + private OspfLinkListener ospfLinkListener;
49 + private Controller controller;
50 + private List<OspfProcess> ospfProcesses;
51 + private OspfProcess process1;
52 + private OspfProcess process2;
53 + private List<OspfArea> areas;
54 + private OspfAreaImpl ospfArea;
55 + private List<OspfInterface> ospfInterfaces;
56 + private OspfInterfaceImpl ospfInterface;
57 + private OspfProcess ospfProcess;
58 + private OspfArea ospfArea1;
59 + private OspfRouter ospfRouter;
60 +
61 + @Before
62 + public void setUp() throws Exception {
63 + ospfController = new OspfControllerImpl();
64 + controller = new Controller();
65 + }
66 +
67 + @After
68 + public void tearDown() throws Exception {
69 + ospfController = null;
70 + ospfRouterListener = null;
71 + ospfLinkListener = null;
72 + controller = null;
73 + ospfProcesses = null;
74 + areas = null;
75 + ospfArea = null;
76 + ospfInterfaces = null;
77 + ospfInterface = null;
78 + ospfProcess = null;
79 + ospfProcess = null;
80 + ospfArea1 = null;
81 + ospfRouter = null;
82 + }
83 +
84 + /**
85 + * Tests activate() method.
86 + */
87 + @Test
88 + public void testActivate() throws Exception {
89 + ospfController.activate();
90 + assertThat(ospfController, is(notNullValue()));
91 + }
92 +
93 + @Test(expected = Exception.class)
94 + public void testDeactivate() throws Exception {
95 + ospfController.activate();
96 + ospfController.deactivate();
97 + assertThat(ospfController, is(notNullValue()));
98 + }
99 +
100 + /**
101 + * Tests addRouterListener() method.
102 + */
103 + @Test
104 + public void testAddRouterListener() throws Exception {
105 + ospfRouterListener = EasyMock.createMock(OspfRouterListener.class);
106 + ospfController.addRouterListener(ospfRouterListener);
107 + assertThat(ospfController, is(notNullValue()));
108 + }
109 +
110 + /**
111 + * Tests removeRouterListener() method.
112 + */
113 + @Test
114 + public void testRemoveRouterListener() throws Exception {
115 + ospfRouterListener = EasyMock.createMock(OspfRouterListener.class);
116 + ospfController.addRouterListener(ospfRouterListener);
117 + ospfController.removeRouterListener(ospfRouterListener);
118 + assertThat(ospfController, is(notNullValue()));
119 + }
120 +
121 + /**
122 + * Tests addLinkListener() method.
123 + */
124 + @Test
125 + public void testAddLinkListener() throws Exception {
126 + ospfLinkListener = EasyMock.createMock(OspfLinkListener.class);
127 + ospfController.addLinkListener(ospfLinkListener);
128 + assertThat(ospfController, is(notNullValue()));
129 + }
130 +
131 + /**
132 + * Tests removeLinkListener() method.
133 + */
134 + @Test
135 + public void testRemoveLinkListener() throws Exception {
136 + ospfLinkListener = EasyMock.createMock(OspfLinkListener.class);
137 + ospfController.addLinkListener(ospfLinkListener);
138 + ospfController.removeLinkListener(ospfLinkListener);
139 + assertThat(ospfController, is(notNullValue()));
140 + }
141 +
142 + /**
143 + * Tests updateConfig() method.
144 + */
145 + @Test
146 + public void testUpdateConfig() throws Exception {
147 + ospfProcess = new OspfProcessImpl();
148 + ospfArea = new OspfAreaImpl();
149 + ospfInterface = new OspfInterfaceImpl();
150 + ospfInterfaces = new ArrayList();
151 + ospfInterface.setIpAddress(Ip4Address.valueOf("11.11.11.11"));
152 + ospfInterfaces.add(ospfInterface);
153 + ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
154 + ospfArea.setInterfacesLst(ospfInterfaces);
155 + ospfProcess.setProcessId("10.10.10.10");
156 + areas = new ArrayList();
157 + areas.add(ospfArea);
158 + ospfProcess.setAreas(areas);
159 + ospfProcesses = new ArrayList();
160 + ospfProcesses.add(ospfProcess);
161 + process1 = new OspfProcessImpl();
162 + process1.setProcessId("11.11.11.11");
163 + ospfArea1 = new OspfAreaImpl();
164 + ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
165 + ospfArea1.setInterfacesLst(ospfInterfaces);
166 + areas.add(ospfArea1);
167 + process1.setAreas(areas);
168 + ospfProcesses.add(process1);
169 + ospfController.updateConfig(ospfProcesses);
170 + assertThat(ospfController, is(notNullValue()));
171 +
172 + }
173 +
174 + /**
175 + * Tests deleteConfig() method.
176 + */
177 + @Test
178 + public void testDeleteConfig() throws Exception {
179 + ospfProcess = new OspfProcessImpl();
180 + ospfArea = new OspfAreaImpl();
181 + ospfInterface = new OspfInterfaceImpl();
182 + ospfInterfaces = new ArrayList();
183 + ospfInterface.setIpAddress(Ip4Address.valueOf("10.10.10.5"));
184 + ospfInterfaces.add(ospfInterface);
185 + ospfArea.setAreaId(Ip4Address.valueOf("2.2.2.2"));
186 + ospfArea.setInterfacesLst(ospfInterfaces);
187 + ospfProcess.setProcessId("10.10.10.10");
188 + areas = new ArrayList();
189 + areas.add(ospfArea);
190 + ospfProcess.setAreas(areas);
191 + ospfProcesses = new ArrayList();
192 + ospfProcesses.add(ospfProcess);
193 + process1 = new OspfProcessImpl();
194 + process1.setProcessId("11.11.11.11");
195 + ospfArea1 = new OspfAreaImpl();
196 + ospfArea1.setAreaId(Ip4Address.valueOf("2.2.2.2"));
197 + ospfArea1.setInterfacesLst(ospfInterfaces);
198 + areas.add(ospfArea1);
199 + process1.setAreas(areas);
200 + ospfProcesses.add(process1);
201 + ospfController.deleteConfig(ospfProcesses, "INTERFACE");
202 + assertThat(ospfController, is(notNullValue()));
203 + }
204 +
205 + /**
206 + * Tests addLink() method.
207 + */
208 + @Test
209 + public void testAddLink() throws Exception {
210 + ospfRouter = new OspfRouterImpl();
211 +
212 + ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl());
213 + assertThat(ospfController, is(notNullValue()));
214 + }
215 +
216 + /**
217 + * Tests deleteLink() method.
218 + */
219 + @Test
220 + public void testDeleteLink() throws Exception {
221 + ospfRouter = new OspfRouterImpl();
222 +
223 + ospfController.agent.addLink(ospfRouter, new OspfLinkTedImpl());
224 + ospfController.agent.deleteLink(ospfRouter);
225 + assertThat(ospfController, is(notNullValue()));
226 + }
227 +
228 + /**
229 + * Tests listener() method.
230 + */
231 + @Test
232 + public void testListener() throws Exception {
233 + assertThat(ospfController.listener().size(), is(0));
234 + }
235 +
236 + /**
237 + * Tests linkListener() method.
238 + */
239 + @Test
240 + public void testLinkListener() throws Exception {
241 + assertThat(ospfController.linkListener().size(), is(0));
242 + }
243 +
244 + /**
245 + * Tests addConnectedRouter() method.
246 + */
247 + @Test
248 + public void testaddConnectedRouter() throws Exception {
249 + ospfRouter = new OspfRouterImpl();
250 +
251 + ospfController.agent.addConnectedRouter(ospfRouter);
252 + assertThat(ospfController, is(notNullValue()));
253 + }
254 +
255 + /**
256 + * Tests removeConnectedRouter() method.
257 + */
258 + @Test
259 + public void testRemoveConnectedRouter() throws Exception {
260 + ospfRouter = new OspfRouterImpl();
261 +
262 + ospfController.agent.addConnectedRouter(ospfRouter);
263 + ospfController.agent.removeConnectedRouter(ospfRouter);
264 + assertThat(ospfController, is(notNullValue()));
265 + }
266 +
267 + /**
268 + * Tests getAllConfiguredProcesses() method.
269 + */
270 + @Test(expected = Exception.class)
271 + public void testGetAllConfiguredProcesses() throws Exception {
272 + assertThat(ospfController.getAllConfiguredProcesses().size(), is(0));
273 + }
274 +}
...\ 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.impl;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onlab.packet.Ip6Address;
23 +
24 +import java.net.InetAddress;
25 +import java.util.ArrayList;
26 +import java.util.List;
27 +
28 +import static org.hamcrest.CoreMatchers.is;
29 +import static org.junit.Assert.assertThat;
30 +
31 +/**
32 + * Unit test class for OspfDeviceTedImpl.
33 + */
34 +public class OspfDeviceTedImplTest {
35 + private OspfDeviceTedImpl ospfDeviceTed;
36 +
37 + @Before
38 + public void setUp() throws Exception {
39 + ospfDeviceTed = new OspfDeviceTedImpl();
40 + }
41 +
42 + @After
43 + public void tearDown() throws Exception {
44 + ospfDeviceTed = null;
45 + }
46 +
47 + /**
48 + * Tests ipv4RouterIds() getter method.
49 + */
50 + @Test
51 + public void testIpv4RouterIds() throws Exception {
52 + List list = new ArrayList();
53 + list.add(Ip4Address.valueOf("1.1.1.1"));
54 + ospfDeviceTed.setIpv4RouterIds(list);
55 + assertThat(ospfDeviceTed.ipv4RouterIds().size(), is(1));
56 + }
57 +
58 + /**
59 + * Tests ipv4RouterIds() setter method.
60 + */
61 + @Test
62 + public void testSetIpv4RouterIds() throws Exception {
63 + List list = new ArrayList();
64 + list.add(Ip4Address.valueOf("1.1.1.1"));
65 + ospfDeviceTed.setIpv4RouterIds(list);
66 + assertThat(ospfDeviceTed.ipv4RouterIds().size(), is(1));
67 + }
68 +
69 + /**
70 + * Tests abr() getter method.
71 + */
72 + @Test
73 + public void testAbr() throws Exception {
74 + ospfDeviceTed.setAbr(true);
75 + assertThat(ospfDeviceTed.abr(), is(true));
76 + }
77 +
78 + /**
79 + * Tests abr() setter method.
80 + */
81 + @Test
82 + public void testSetAbr() throws Exception {
83 + ospfDeviceTed.setAbr(true);
84 + assertThat(ospfDeviceTed.abr(), is(true));
85 + }
86 +
87 + /**
88 + * Tests asbr() getter method.
89 + */
90 + @Test
91 + public void testAsbr() throws Exception {
92 + ospfDeviceTed.setAsbr(true);
93 + assertThat(ospfDeviceTed.asbr(), is(true));
94 + }
95 +
96 + /**
97 + * Tests asbr() setter method.
98 + */
99 + @Test
100 + public void testSetAsbr() throws Exception {
101 + ospfDeviceTed.setAsbr(true);
102 + assertThat(ospfDeviceTed.asbr(), is(true));
103 + }
104 +
105 + /**
106 + * Tests topologyIds() getter method.
107 + */
108 + @Test
109 + public void testTopologyIds() throws Exception {
110 + List list = new ArrayList();
111 + list.add(Ip4Address.valueOf("1.1.1.1"));
112 + ospfDeviceTed.setTopologyIds(list);
113 + assertThat(ospfDeviceTed.topologyIds().size(), is(1));
114 + }
115 +
116 + /**
117 + * Tests topologyIds() setter method.
118 + */
119 + @Test
120 + public void testSetTopologyIds() throws Exception {
121 + List list = new ArrayList();
122 + list.add(Ip4Address.valueOf("1.1.1.1"));
123 + ospfDeviceTed.setTopologyIds(list);
124 + assertThat(ospfDeviceTed.topologyIds().size(), is(1));
125 + }
126 +
127 + /**
128 + * Tests ipv6RouterIds() getter method.
129 + */
130 + @Test(expected = Exception.class)
131 + public void testIpv6RouterIds() throws Exception {
132 + List list = new ArrayList();
133 + list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
134 + ospfDeviceTed.setIpv6RouterIds(list);
135 + assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
136 + }
137 +
138 + /**
139 + * Tests ipv6RouterIds() setter method.
140 + */
141 + @Test(expected = Exception.class)
142 + public void testSetIpv6RouterIds() throws Exception {
143 + List list = new ArrayList();
144 + list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
145 + ospfDeviceTed.setIpv6RouterIds(list);
146 + assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
147 + }
148 +}
...\ 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.impl;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onlab.util.Bandwidth;
23 +
24 +import java.net.InetAddress;
25 +import java.util.ArrayList;
26 +import java.util.List;
27 +
28 +import static org.hamcrest.CoreMatchers.is;
29 +import static org.hamcrest.CoreMatchers.notNullValue;
30 +import static org.junit.Assert.assertThat;
31 +
32 +/**
33 + * Unit test class for OspfDeviceTedImpl.
34 + */
35 +public class OspfLinkTedImplTest {
36 + private OspfLinkTedImpl ospfLinkTed;
37 +
38 + @Before
39 + public void setUp() throws Exception {
40 + ospfLinkTed = new OspfLinkTedImpl();
41 + }
42 +
43 + @After
44 + public void tearDown() throws Exception {
45 + ospfLinkTed = null;
46 + }
47 +
48 + /**
49 + * Tests maximumLink() getter method.
50 + */
51 + @Test
52 + public void testMaximumLink() throws Exception {
53 +
54 + ospfLinkTed.setMaximumLink(Bandwidth.bps(1234));
55 + assertThat(ospfLinkTed.maximumLink(), is(Bandwidth.bps(1234)));
56 + }
57 +
58 + /**
59 + * Tests maximumLink() setter method.
60 + */
61 + @Test
62 + public void testSetMaximumLink() throws Exception {
63 + ospfLinkTed.setMaximumLink(Bandwidth.bps(1234));
64 + assertThat(ospfLinkTed.maximumLink(), is(Bandwidth.bps(1234)));
65 + }
66 +
67 + /**
68 + * Tests ipv6RemRouterId() getter method.
69 + */
70 + @Test
71 + public void testIpv6RemRouterId() throws Exception {
72 + List list = new ArrayList();
73 + ospfLinkTed.setIpv6RemRouterId(list);
74 + assertThat(ospfLinkTed.ipv6RemRouterId().size(), is(0));
75 + }
76 +
77 + /**
78 + * Tests ipv6RemRouterId() setter method.
79 + */
80 + @Test
81 + public void testSetIpv6RemRouterId() throws Exception {
82 + List list = new ArrayList();
83 + ospfLinkTed.setIpv6RemRouterId(list);
84 + assertThat(ospfLinkTed.ipv6RemRouterId().size(), is(0));
85 + }
86 +
87 + /**
88 + * Tests ipv4RemRouterId() getter method.
89 + */
90 + @Test
91 + public void testIpv4RemRouterId() throws Exception {
92 + List list = new ArrayList();
93 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
94 + ospfLinkTed.setIpv4RemRouterId(list);
95 + assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
96 + }
97 +
98 + /**
99 + * Tests ipv4RemRouterId() setter method.
100 + */
101 + @Test
102 + public void testSetIpv4RemRouterId() throws Exception {
103 + List list = new ArrayList();
104 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
105 + ospfLinkTed.setIpv4RemRouterId(list);
106 + assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
107 + }
108 +
109 + /**
110 + * Tests ipv6LocRouterId() getter method.
111 + */
112 + @Test
113 + public void testIpv6LocRouterId() throws Exception {
114 + List list = new ArrayList();
115 + ospfLinkTed.setIpv4LocRouterId(list);
116 + assertThat(ospfLinkTed.ipv6LocRouterId().size(), is(0));
117 + }
118 +
119 + /**
120 + * Tests ipv6LocRouterId() setter method.
121 + */
122 + @Test
123 + public void testSetIpv6LocRouterId() throws Exception {
124 + List list = new ArrayList();
125 + ospfLinkTed.setIpv4LocRouterId(list);
126 + assertThat(ospfLinkTed.ipv6LocRouterId().size(), is(0));
127 + }
128 +
129 + /**
130 + * Tests ipv4LocRouterId() getter method.
131 + */
132 + @Test
133 + public void testIpv4LocRouterId() throws Exception {
134 + List list = new ArrayList();
135 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
136 + ospfLinkTed.setIpv4LocRouterId(list);
137 + assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
138 + }
139 +
140 + /**
141 + * Tests ipv4LocRouterId() setter method.
142 + */
143 + @Test
144 + public void testSetIpv4LocRouterId() throws Exception {
145 + List list = new ArrayList();
146 + list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
147 + ospfLinkTed.setIpv4LocRouterId(list);
148 + assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
149 + }
150 +
151 + /**
152 + * Tests teMetric() getter method.
153 + */
154 + @Test
155 + public void testTeMetric() throws Exception {
156 + ospfLinkTed.setTeMetric(1234);
157 + assertThat(ospfLinkTed.teMetric(), is(1234));
158 + }
159 +
160 + /**
161 + * Tests teMetric() setter method.
162 + */
163 + @Test
164 + public void testSetTeMetric() throws Exception {
165 + ospfLinkTed.setTeMetric(1234);
166 + assertThat(ospfLinkTed.teMetric(), is(1234));
167 + }
168 +
169 + /**
170 + * Tests maxReserved() getter method.
171 + */
172 + @Test
173 + public void testMaxReserved() throws Exception {
174 + ospfLinkTed.setMaxReserved(Bandwidth.bps(1234));
175 + assertThat(ospfLinkTed.maxReserved(), is(Bandwidth.bps(1234)));
176 + }
177 +
178 + /**
179 + * Tests maxReserved() setter method.
180 + */
181 + @Test
182 + public void testSetMaxReserved() throws Exception {
183 + ospfLinkTed.setMaxReserved(Bandwidth.bps(1234));
184 + assertThat(ospfLinkTed.maxReserved(), is(Bandwidth.bps(1234)));
185 + }
186 +
187 + /**
188 + * Tests maxUnResBandwidth() getter method.
189 + */
190 + @Test
191 + public void testMaxUnResBandwidth() throws Exception {
192 + ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234));
193 + assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue()));
194 + }
195 +
196 + /**
197 + * Tests maxUnResBandwidth() setter method.
198 + */
199 + @Test
200 + public void testSetMaxUnResBandwidth() throws Exception {
201 + ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234.0));
202 + assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue()));
203 + }
204 +}
...\ 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.impl;
17 +
18 +import org.easymock.EasyMock;
19 +import org.jboss.netty.buffer.ChannelBuffer;
20 +import org.jboss.netty.buffer.ChannelBuffers;
21 +import org.jboss.netty.channel.Channel;
22 +import org.jboss.netty.channel.ChannelHandlerContext;
23 +import org.junit.After;
24 +import org.junit.Before;
25 +import org.junit.Test;
26 +
27 +import java.net.InetSocketAddress;
28 +import java.net.SocketAddress;
29 +
30 +import static org.hamcrest.CoreMatchers.is;
31 +import static org.hamcrest.CoreMatchers.nullValue;
32 +import static org.hamcrest.MatcherAssert.assertThat;
33 +
34 +/**
35 + * Unit test class for OspfMessageDecoder.
36 + */
37 +public class OspfMessageDecoderTest {
38 +
39 + private final byte[] hellopacket = {0, 0, 0, 0, 2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59,
40 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0,
41 + 40, -64, -88, -86, 8, 0, 0, 0, 0};
42 + private final byte[] ddpacket = {0, 0, 0, 0, 2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
43 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
44 + private final byte[] ddpacket44 = {0, 0, 0, 0, 2, 2, 0, 10, -64, -88};
45 + private final byte[] lsAckpacket = {0, 0, 0, 0, 2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12,
46 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64,
47 + -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
48 + private final byte[] lsUpdatePacket = {0, 0, 0, 0, 2, 4, 0, 76, -64, -88, -86, 3, 0, 0, 0, 1, 7, 111,
49 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 14, 16, 2, 1, -64, -88,
50 + -86, 2, -64, -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48, 2, 0, 0, 2
51 + , -64, -88, -86, 0, -1, -1, -1, 0, 3, 0, 0, 10, -64, -88, -86, 0, -1, -1, -1, 0, 3, 0, 0, 10};
52 + private final byte[] lsRequestPacket = {0, 0, 0, 0, 2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57,
53 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8};
54 + private OspfMessageDecoder ospfMessageDecoder;
55 + private ChannelHandlerContext ctx;
56 + private Channel channel;
57 + private SocketAddress socketAddress;
58 + private ChannelBuffer channelBuffer;
59 +
60 + @Before
61 + public void setUp() throws Exception {
62 + ospfMessageDecoder = new OspfMessageDecoder();
63 + }
64 +
65 + @After
66 + public void tearDown() throws Exception {
67 + ospfMessageDecoder = null;
68 + channel = null;
69 + socketAddress = null;
70 + channelBuffer = null;
71 + }
72 +
73 + /**
74 + * Tests decode() method.
75 + */
76 + @Test
77 + public void testDecode() throws Exception {
78 +
79 + channel = EasyMock.createMock(Channel.class);
80 + socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 7000);
81 + channelBuffer = ChannelBuffers.copiedBuffer(hellopacket);
82 + assertThat(ospfMessageDecoder.decode(ctx, channel, channelBuffer), is(nullValue()));
83 +
84 +
85 + }
86 +}
...\ 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.impl;
17 +
18 +
19 +import org.easymock.EasyMock;
20 +import org.jboss.netty.buffer.ChannelBuffer;
21 +import org.jboss.netty.buffer.ChannelBuffers;
22 +import org.jboss.netty.channel.Channel;
23 +import org.jboss.netty.channel.ChannelHandlerContext;
24 +import org.junit.After;
25 +import org.junit.Before;
26 +import org.junit.Test;
27 +import org.onlab.packet.Ip4Address;
28 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
29 +import org.onosproject.ospf.protocol.ospfpacket.types.DdPacket;
30 +import org.onosproject.ospf.protocol.ospfpacket.types.HelloPacket;
31 +import org.onosproject.ospf.protocol.ospfpacket.types.LsAcknowledge;
32 +import org.onosproject.ospf.protocol.ospfpacket.types.LsRequest;
33 +import org.onosproject.ospf.protocol.ospfpacket.types.LsUpdate;
34 +import org.onosproject.ospf.protocol.util.OspfInterfaceState;
35 +
36 +import java.net.InetSocketAddress;
37 +import java.net.SocketAddress;
38 +
39 +import static org.hamcrest.CoreMatchers.is;
40 +import static org.hamcrest.CoreMatchers.notNullValue;
41 +import static org.hamcrest.MatcherAssert.assertThat;
42 +
43 +/**
44 + * Created by sdn on 13/1/16.
45 + */
46 +public class OspfMessageEncoderTest {
47 + private final byte[] hpacket = {2, 1, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, 39, 59,
48 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 10, 2, 1, 0, 0, 0,
49 + 40, -64, -88, -86, 8, 0, 0, 0, 0};
50 + private final byte[] dpacket = {2, 2, 0, 32, -64, -88, -86, 8, 0, 0, 0, 1, -96, 82,
51 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, -36, 2, 7, 65, 119, -87, 126};
52 + private final byte[] lrpacket = {2, 3, 0, 36, -64, -88, -86, 3, 0, 0, 0, 1, -67, -57,
53 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -64, -88, -86, 8, -64, -88, -86, 8};
54 + private byte[] lAckpacket = {2, 5, 0, 44, -64, -88, -86, 8, 0, 0, 0, 1, -30, -12,
55 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 16, 2, 1, -64, -88, -86, 2, -64,
56 + -88, -86, 2, -128, 0, 0, 1, 74, -114, 0, 48};
57 + private HelloPacket helloPacket;
58 + private DdPacket ddPacket;
59 + private LsAcknowledge lsAcknowledge;
60 + private LsRequest lsRequest;
61 + private LsUpdate lsUpdate;
62 + private ChannelHandlerContext ctx;
63 + private OspfMessageEncoder ospfMessageEncoder;
64 + private ChannelBuffer buf;
65 + private SocketAddress socketAddress;
66 + private Channel channel;
67 +
68 + @Before
69 + public void setUp() throws Exception {
70 + ospfMessageEncoder = new OspfMessageEncoder();
71 + helloPacket = new HelloPacket();
72 + ddPacket = new DdPacket();
73 + lsAcknowledge = new LsAcknowledge();
74 + lsRequest = new LsRequest();
75 + lsUpdate = new LsUpdate();
76 + helloPacket.setOspftype(1);
77 + ddPacket.setOspftype(2);
78 + lsAcknowledge.setOspftype(5);
79 + lsRequest.setOspftype(3);
80 + lsUpdate.setOspftype(4);
81 + OspfInterfaceImpl ospfInterface = new OspfInterfaceImpl();
82 + ospfInterface.setState(OspfInterfaceState.DROTHER);
83 + ospfMessageEncoder = new OspfMessageEncoder(ospfInterface);
84 +
85 + }
86 +
87 + @After
88 + public void tearDown() throws Exception {
89 + helloPacket = null;
90 + ddPacket = null;
91 + lsAcknowledge = null;
92 + lsRequest = null;
93 + lsUpdate = null;
94 + ospfMessageEncoder = null;
95 + buf = null;
96 + }
97 +
98 + /**
99 + * Tests encode() method.
100 + */
101 + @Test
102 + public void testEncode() throws Exception {
103 + socketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 8600);
104 + channel = EasyMock.createMock(Channel.class);
105 + helloPacket = new HelloPacket();
106 + helloPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
107 + buf = ChannelBuffers.buffer(hpacket.length);
108 + buf.writeBytes(hpacket);
109 + helloPacket.readFrom(buf);
110 + ospfMessageEncoder.encode(ctx, channel, helloPacket);
111 + ddPacket = new DdPacket();
112 + ddPacket.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
113 + buf = ChannelBuffers.buffer(dpacket.length);
114 + buf.writeBytes(dpacket);
115 + ddPacket.readFrom(buf);
116 + ospfMessageEncoder.encode(ctx, channel, ddPacket);
117 + lsRequest = new LsRequest();
118 + lsRequest.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
119 + buf = ChannelBuffers.buffer(lrpacket.length);
120 + buf.writeBytes(lrpacket);
121 + lsRequest.readFrom(buf);
122 + ospfMessageEncoder.encode(ctx, channel, lsRequest);
123 +
124 + lsAcknowledge = new LsAcknowledge();
125 + lsAcknowledge.setDestinationIp(Ip4Address.valueOf("15.15.15.15"));
126 + buf = ChannelBuffers.buffer(lAckpacket.length);
127 + buf.writeBytes(lAckpacket);
128 + lsAcknowledge.readFrom(buf);
129 + ospfMessageEncoder.encode(ctx, channel, lsAcknowledge);
130 + assertThat(ospfMessageEncoder, is(notNullValue()));
131 + }
132 +}
...\ 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.impl;
17 +
18 +import org.jboss.netty.channel.ChannelPipeline;
19 +import org.junit.After;
20 +import org.junit.Before;
21 +import org.junit.Test;
22 +import org.onosproject.ospf.controller.area.OspfAreaImpl;
23 +import org.onosproject.ospf.controller.area.OspfInterfaceImpl;
24 +
25 +import static org.hamcrest.CoreMatchers.*;
26 +import static org.hamcrest.MatcherAssert.assertThat;
27 +
28 +/**
29 + * Unit test class for OspfPipelineFactory.
30 + */
31 +public class OspfPipelineFactoryTest {
32 +
33 + private OspfPipelineFactory ospfPipelineFactory;
34 + private ChannelPipeline channelPipeline;
35 +
36 + @Before
37 + public void setUp() throws Exception {
38 + ospfPipelineFactory = new OspfPipelineFactory(new Controller(), new OspfAreaImpl(), new OspfInterfaceImpl());
39 +
40 + }
41 +
42 + @After
43 + public void tearDown() throws Exception {
44 + ospfPipelineFactory = null;
45 + channelPipeline = null;
46 + }
47 +
48 + /**
49 + * Tests getPipeline() method.
50 + */
51 + @Test
52 + public void testGetPipeline() throws Exception {
53 + channelPipeline = ospfPipelineFactory.getPipeline();
54 + assertThat(channelPipeline, is(notNullValue()));
55 + }
56 +
57 + /**
58 + * Tests releaseExternalResources() method.
59 + */
60 + @Test
61 + public void testReleaseExternalResources() throws Exception {
62 + ospfPipelineFactory.releaseExternalResources();
63 + assertThat(channelPipeline, is(nullValue()));
64 + }
65 +}
...\ 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.impl;
17 +
18 +import org.junit.After;
19 +import org.junit.Before;
20 +import org.junit.Test;
21 +import org.onlab.packet.Ip4Address;
22 +import org.onlab.packet.IpAddress;
23 +import org.onosproject.ospf.controller.OspfDeviceTed;
24 +
25 +import java.util.List;
26 +
27 +import static org.hamcrest.CoreMatchers.is;
28 +import static org.hamcrest.CoreMatchers.notNullValue;
29 +import static org.hamcrest.MatcherAssert.assertThat;
30 +
31 +/**
32 + * Unit test class for OspfRouterImpl.
33 + */
34 +public class OspfRouterImplTest {
35 + private OspfRouterImpl ospfRouter;
36 + private OspfDeviceTed ospfDeviceTed;
37 + private List<OspfDeviceTed> list;
38 +
39 + @Before
40 + public void setUp() throws Exception {
41 + ospfRouter = new OspfRouterImpl();
42 + }
43 +
44 + @After
45 + public void tearDown() throws Exception {
46 + ospfRouter = null;
47 + }
48 +
49 + /**
50 + * Tests routerIp() getter method.
51 + */
52 + @Test
53 + public void testRouterIp() throws Exception {
54 + ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1"));
55 + assertThat(ospfRouter.routerIp(), is(IpAddress.valueOf("1.1.1.1")));
56 + }
57 +
58 + /**
59 + * Tests routerIp() setter method.
60 + */
61 + @Test
62 + public void testSetRouterIp() throws Exception {
63 + ospfRouter.setRouterIp(Ip4Address.valueOf("1.1.1.1"));
64 + assertThat(ospfRouter.routerIp(), is(IpAddress.valueOf("1.1.1.1")));
65 + }
66 +
67 + /**
68 + * Tests areaIdOfInterface() getter method.
69 + */
70 + @Test
71 + public void testAreaIdOfInterface() throws Exception {
72 + ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("1.1.1.1"));
73 + assertThat(ospfRouter.areaIdOfInterface(), is(IpAddress.valueOf("1.1.1.1")));
74 + }
75 +
76 + /**
77 + * Tests areaIdOfInterface() setter method.
78 + */
79 + @Test
80 + public void testSetAreaIdOfInterface() throws Exception {
81 + ospfRouter.setAreaIdOfInterface(Ip4Address.valueOf("1.1.1.1"));
82 + assertThat(ospfRouter.areaIdOfInterface(), is(IpAddress.valueOf("1.1.1.1")));
83 + }
84 +
85 + /**
86 + * Tests interfaceId() getter method.
87 + */
88 + @Test
89 + public void testInterfaceId() throws Exception {
90 + ospfRouter.setInterfaceId(Ip4Address.valueOf("1.1.1.1"));
91 + assertThat(ospfRouter.interfaceId(), is(IpAddress.valueOf("1.1.1.1")));
92 + }
93 +
94 + /**
95 + * Tests interfaceId() setter method.
96 + */
97 + @Test
98 + public void testSetInterfaceId() throws Exception {
99 + ospfRouter.setInterfaceId(Ip4Address.valueOf("1.1.1.1"));
100 + assertThat(ospfRouter.interfaceId(), is(IpAddress.valueOf("1.1.1.1")));
101 + }
102 +
103 + /**
104 + * Tests isDr() setter method.
105 + */
106 + @Test
107 + public void testSetDr() throws Exception {
108 + ospfRouter.setDr(true);
109 + assertThat(ospfRouter.isDr(), is(true));
110 + }
111 +
112 + /**
113 + * Tests isDr() getter method.
114 + */
115 + @Test
116 + public void testIsDr() throws Exception {
117 + ospfRouter.setDr(true);
118 + assertThat(ospfRouter.isDr(), is(true));
119 + }
120 +
121 + /**
122 + * Tests isOpaque() setter method.
123 + */
124 + @Test
125 + public void testSetOpaque() throws Exception {
126 + ospfRouter.setOpaque(true);
127 + assertThat(ospfRouter.isOpaque(), is(true));
128 + }
129 +
130 + /**
131 + * Tests isOpaque() getter method.
132 + */
133 + @Test
134 + public void testisOpaque() throws Exception {
135 + ospfRouter.setOpaque(true);
136 + assertThat(ospfRouter.isOpaque(), is(true));
137 + }
138 +
139 + /**
140 + * Tests deviceTed() getter method.
141 + */
142 + @Test
143 + public void testDeviceTed() throws Exception {
144 + ospfRouter.setDeviceTed(new OspfDeviceTedImpl());
145 + assertThat(ospfRouter.deviceTed(), is(notNullValue()));
146 + }
147 +
148 + /**
149 + * Tests deviceTed() Setter method.
150 + */
151 + @Test
152 + public void testSetDeviceTed() throws Exception {
153 + ospfRouter.setDeviceTed(new OspfDeviceTedImpl());
154 + assertThat(ospfRouter.deviceTed(), is(notNullValue()));
155 + }
156 +
157 + /**
158 + * Tests neighborRouterId() getter method.
159 + */
160 + @Test
161 + public void testNeighborRouterId() throws Exception {
162 + ospfRouter.setNeighborRouterId(Ip4Address.valueOf("1.1.1.1"));
163 + assertThat(ospfRouter.neighborRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
164 + }
165 +
166 + /**
167 + * Tests neighborRouterId() Setter method.
168 + */
169 + @Test
170 + public void testSetNeighborRouterId() throws Exception {
171 + ospfRouter.setNeighborRouterId(Ip4Address.valueOf("1.1.1.1"));
172 + assertThat(ospfRouter.neighborRouterId(), is(Ip4Address.valueOf("1.1.1.1")));
173 + }
174 +}
...\ No newline at end of file ...\ No newline at end of file