Remove usage of InetAddress.getLocalHost() in unit tests.
This does a DNS lookup which causes the test to fail if the DNS lookup fails. Change-Id: I9fb3898e7b846e68915d90368849734ad61922f4
Showing
5 changed files
with
32 additions
and
32 deletions
... | @@ -21,7 +21,6 @@ import org.junit.Test; | ... | @@ -21,7 +21,6 @@ import org.junit.Test; |
21 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
22 | import org.onlab.packet.Ip6Address; | 22 | import org.onlab.packet.Ip6Address; |
23 | 23 | ||
24 | -import java.net.InetAddress; | ||
25 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
26 | import java.util.List; | 25 | import java.util.List; |
27 | 26 | ||
... | @@ -32,6 +31,8 @@ import static org.junit.Assert.assertThat; | ... | @@ -32,6 +31,8 @@ import static org.junit.Assert.assertThat; |
32 | * Unit test class for OspfDeviceTedImpl. | 31 | * Unit test class for OspfDeviceTedImpl. |
33 | */ | 32 | */ |
34 | public class OspfDeviceTedImplTest { | 33 | public class OspfDeviceTedImplTest { |
34 | + private static final Ip6Address LOCAL_ADDRESS = Ip6Address.valueOf("::1"); | ||
35 | + | ||
35 | private OspfDeviceTedImpl ospfDeviceTed; | 36 | private OspfDeviceTedImpl ospfDeviceTed; |
36 | 37 | ||
37 | @Before | 38 | @Before |
... | @@ -127,10 +128,10 @@ public class OspfDeviceTedImplTest { | ... | @@ -127,10 +128,10 @@ public class OspfDeviceTedImplTest { |
127 | /** | 128 | /** |
128 | * Tests ipv6RouterIds() getter method. | 129 | * Tests ipv6RouterIds() getter method. |
129 | */ | 130 | */ |
130 | - @Test(expected = Exception.class) | 131 | + @Test |
131 | public void testIpv6RouterIds() throws Exception { | 132 | public void testIpv6RouterIds() throws Exception { |
132 | List list = new ArrayList(); | 133 | List list = new ArrayList(); |
133 | - list.add(Ip6Address.valueOf(InetAddress.getLocalHost())); | 134 | + list.add(LOCAL_ADDRESS); |
134 | ospfDeviceTed.setIpv6RouterIds(list); | 135 | ospfDeviceTed.setIpv6RouterIds(list); |
135 | assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); | 136 | assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); |
136 | } | 137 | } |
... | @@ -138,11 +139,11 @@ public class OspfDeviceTedImplTest { | ... | @@ -138,11 +139,11 @@ public class OspfDeviceTedImplTest { |
138 | /** | 139 | /** |
139 | * Tests ipv6RouterIds() setter method. | 140 | * Tests ipv6RouterIds() setter method. |
140 | */ | 141 | */ |
141 | - @Test(expected = Exception.class) | 142 | + @Test |
142 | public void testSetIpv6RouterIds() throws Exception { | 143 | public void testSetIpv6RouterIds() throws Exception { |
143 | List list = new ArrayList(); | 144 | List list = new ArrayList(); |
144 | - list.add(Ip6Address.valueOf(InetAddress.getLocalHost())); | 145 | + list.add(LOCAL_ADDRESS); |
145 | ospfDeviceTed.setIpv6RouterIds(list); | 146 | ospfDeviceTed.setIpv6RouterIds(list); |
146 | assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); | 147 | assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1)); |
147 | } | 148 | } |
148 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
149 | +} | ... | ... |
... | @@ -21,7 +21,6 @@ import org.junit.Test; | ... | @@ -21,7 +21,6 @@ import org.junit.Test; |
21 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
22 | import org.onlab.util.Bandwidth; | 22 | import org.onlab.util.Bandwidth; |
23 | 23 | ||
24 | -import java.net.InetAddress; | ||
25 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
26 | import java.util.List; | 25 | import java.util.List; |
27 | 26 | ||
... | @@ -33,6 +32,8 @@ import static org.junit.Assert.assertThat; | ... | @@ -33,6 +32,8 @@ import static org.junit.Assert.assertThat; |
33 | * Unit test class for OspfDeviceTedImpl. | 32 | * Unit test class for OspfDeviceTedImpl. |
34 | */ | 33 | */ |
35 | public class OspfLinkTedImplTest { | 34 | public class OspfLinkTedImplTest { |
35 | + private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1"); | ||
36 | + | ||
36 | private OspfLinkTedImpl ospfLinkTed; | 37 | private OspfLinkTedImpl ospfLinkTed; |
37 | 38 | ||
38 | @Before | 39 | @Before |
... | @@ -90,7 +91,7 @@ public class OspfLinkTedImplTest { | ... | @@ -90,7 +91,7 @@ public class OspfLinkTedImplTest { |
90 | @Test | 91 | @Test |
91 | public void testIpv4RemRouterId() throws Exception { | 92 | public void testIpv4RemRouterId() throws Exception { |
92 | List list = new ArrayList(); | 93 | List list = new ArrayList(); |
93 | - list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | 94 | + list.add(LOCAL_ADDRESS); |
94 | ospfLinkTed.setIpv4RemRouterId(list); | 95 | ospfLinkTed.setIpv4RemRouterId(list); |
95 | assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); | 96 | assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); |
96 | } | 97 | } |
... | @@ -101,7 +102,7 @@ public class OspfLinkTedImplTest { | ... | @@ -101,7 +102,7 @@ public class OspfLinkTedImplTest { |
101 | @Test | 102 | @Test |
102 | public void testSetIpv4RemRouterId() throws Exception { | 103 | public void testSetIpv4RemRouterId() throws Exception { |
103 | List list = new ArrayList(); | 104 | List list = new ArrayList(); |
104 | - list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | 105 | + list.add(LOCAL_ADDRESS); |
105 | ospfLinkTed.setIpv4RemRouterId(list); | 106 | ospfLinkTed.setIpv4RemRouterId(list); |
106 | assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); | 107 | assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1)); |
107 | } | 108 | } |
... | @@ -132,7 +133,7 @@ public class OspfLinkTedImplTest { | ... | @@ -132,7 +133,7 @@ public class OspfLinkTedImplTest { |
132 | @Test | 133 | @Test |
133 | public void testIpv4LocRouterId() throws Exception { | 134 | public void testIpv4LocRouterId() throws Exception { |
134 | List list = new ArrayList(); | 135 | List list = new ArrayList(); |
135 | - list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | 136 | + list.add(LOCAL_ADDRESS); |
136 | ospfLinkTed.setIpv4LocRouterId(list); | 137 | ospfLinkTed.setIpv4LocRouterId(list); |
137 | assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); | 138 | assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); |
138 | } | 139 | } |
... | @@ -143,7 +144,7 @@ public class OspfLinkTedImplTest { | ... | @@ -143,7 +144,7 @@ public class OspfLinkTedImplTest { |
143 | @Test | 144 | @Test |
144 | public void testSetIpv4LocRouterId() throws Exception { | 145 | public void testSetIpv4LocRouterId() throws Exception { |
145 | List list = new ArrayList(); | 146 | List list = new ArrayList(); |
146 | - list.add(Ip4Address.valueOf(InetAddress.getLocalHost())); | 147 | + list.add(LOCAL_ADDRESS); |
147 | ospfLinkTed.setIpv4LocRouterId(list); | 148 | ospfLinkTed.setIpv4LocRouterId(list); |
148 | assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); | 149 | assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1)); |
149 | } | 150 | } |
... | @@ -201,4 +202,4 @@ public class OspfLinkTedImplTest { | ... | @@ -201,4 +202,4 @@ public class OspfLinkTedImplTest { |
201 | ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234.0)); | 202 | ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234.0)); |
202 | assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue())); | 203 | assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue())); |
203 | } | 204 | } |
204 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
205 | +} | ... | ... |
... | @@ -20,8 +20,6 @@ import org.junit.Before; | ... | @@ -20,8 +20,6 @@ import org.junit.Before; |
20 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | import org.onlab.packet.Ip4Address; | 21 | import org.onlab.packet.Ip4Address; |
22 | 22 | ||
23 | -import java.net.InetAddress; | ||
24 | - | ||
25 | import static org.hamcrest.MatcherAssert.assertThat; | 23 | import static org.hamcrest.MatcherAssert.assertThat; |
26 | import static org.hamcrest.Matchers.is; | 24 | import static org.hamcrest.Matchers.is; |
27 | import static org.hamcrest.Matchers.notNullValue; | 25 | import static org.hamcrest.Matchers.notNullValue; |
... | @@ -31,6 +29,8 @@ import static org.hamcrest.Matchers.notNullValue; | ... | @@ -31,6 +29,8 @@ import static org.hamcrest.Matchers.notNullValue; |
31 | */ | 29 | */ |
32 | public class OspfExternalDestinationTest { | 30 | public class OspfExternalDestinationTest { |
33 | 31 | ||
32 | + private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1"); | ||
33 | + | ||
34 | private OspfExternalDestination ospfExternalDestination; | 34 | private OspfExternalDestination ospfExternalDestination; |
35 | 35 | ||
36 | @Before | 36 | @Before |
... | @@ -84,8 +84,8 @@ public class OspfExternalDestinationTest { | ... | @@ -84,8 +84,8 @@ public class OspfExternalDestinationTest { |
84 | */ | 84 | */ |
85 | @Test | 85 | @Test |
86 | public void testGetForwardingAddress() throws Exception { | 86 | public void testGetForwardingAddress() throws Exception { |
87 | - ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost())); | 87 | + ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS); |
88 | - assertThat(ospfExternalDestination.forwardingAddress(), is(Ip4Address.valueOf(InetAddress.getLocalHost()))); | 88 | + assertThat(ospfExternalDestination.forwardingAddress(), is(LOCAL_ADDRESS)); |
89 | 89 | ||
90 | } | 90 | } |
91 | 91 | ||
... | @@ -94,8 +94,8 @@ public class OspfExternalDestinationTest { | ... | @@ -94,8 +94,8 @@ public class OspfExternalDestinationTest { |
94 | */ | 94 | */ |
95 | @Test | 95 | @Test |
96 | public void testSetForwardingAddress() throws Exception { | 96 | public void testSetForwardingAddress() throws Exception { |
97 | - ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost())); | 97 | + ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS); |
98 | - assertThat(ospfExternalDestination.forwardingAddress(), is(Ip4Address.valueOf(InetAddress.getLocalHost()))); | 98 | + assertThat(ospfExternalDestination.forwardingAddress(), is(LOCAL_ADDRESS)); |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
... | @@ -123,4 +123,4 @@ public class OspfExternalDestinationTest { | ... | @@ -123,4 +123,4 @@ public class OspfExternalDestinationTest { |
123 | public void testToString() throws Exception { | 123 | public void testToString() throws Exception { |
124 | assertThat(ospfExternalDestination.toString(), is(notNullValue())); | 124 | assertThat(ospfExternalDestination.toString(), is(notNullValue())); |
125 | } | 125 | } |
126 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
126 | +} | ... | ... |
... | @@ -25,8 +25,6 @@ import org.onosproject.ospf.controller.OspfLsaType; | ... | @@ -25,8 +25,6 @@ import org.onosproject.ospf.controller.OspfLsaType; |
25 | import org.onosproject.ospf.protocol.lsa.LsaHeader; | 25 | import org.onosproject.ospf.protocol.lsa.LsaHeader; |
26 | import org.onosproject.ospf.protocol.lsa.subtypes.OspfExternalDestination; | 26 | import org.onosproject.ospf.protocol.lsa.subtypes.OspfExternalDestination; |
27 | 27 | ||
28 | - | ||
29 | -import java.net.InetAddress; | ||
30 | import java.net.UnknownHostException; | 28 | import java.net.UnknownHostException; |
31 | import java.util.Vector; | 29 | import java.util.Vector; |
32 | 30 | ||
... | @@ -39,6 +37,8 @@ import static org.hamcrest.Matchers.notNullValue; | ... | @@ -39,6 +37,8 @@ import static org.hamcrest.Matchers.notNullValue; |
39 | */ | 37 | */ |
40 | public class ExternalLsaTest { | 38 | public class ExternalLsaTest { |
41 | 39 | ||
40 | + private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1"); | ||
41 | + | ||
42 | private ExternalLsa externalLsa; | 42 | private ExternalLsa externalLsa; |
43 | private Vector<OspfExternalDestination> externalDestinations = new Vector<OspfExternalDestination>(); | 43 | private Vector<OspfExternalDestination> externalDestinations = new Vector<OspfExternalDestination>(); |
44 | private Ip4Address result; | 44 | private Ip4Address result; |
... | @@ -127,7 +127,7 @@ public class ExternalLsaTest { | ... | @@ -127,7 +127,7 @@ public class ExternalLsaTest { |
127 | ospfExternalDestination.setMetric(50); | 127 | ospfExternalDestination.setMetric(50); |
128 | ospfExternalDestination.setType1orType2Metric(true); | 128 | ospfExternalDestination.setType1orType2Metric(true); |
129 | externalLsa.addExternalDestination(ospfExternalDestination1); | 129 | externalLsa.addExternalDestination(ospfExternalDestination1); |
130 | - ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost())); | 130 | + ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS); |
131 | inputByteArray = createByteForNetworkLsa(); | 131 | inputByteArray = createByteForNetworkLsa(); |
132 | lsaHeader = createLsaHeader(); | 132 | lsaHeader = createLsaHeader(); |
133 | externalLsa = new ExternalLsa(lsaHeader); | 133 | externalLsa = new ExternalLsa(lsaHeader); |
... | @@ -151,7 +151,7 @@ public class ExternalLsaTest { | ... | @@ -151,7 +151,7 @@ public class ExternalLsaTest { |
151 | ospfExternalDestination.setMetric(50); | 151 | ospfExternalDestination.setMetric(50); |
152 | ospfExternalDestination.setType1orType2Metric(true); | 152 | ospfExternalDestination.setType1orType2Metric(true); |
153 | externalLsa.addExternalDestination(ospfExternalDestination1); | 153 | externalLsa.addExternalDestination(ospfExternalDestination1); |
154 | - ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost())); | 154 | + ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS); |
155 | byte[] temp = {0, 0, 0}; | 155 | byte[] temp = {0, 0, 0}; |
156 | inputByteArray = temp; | 156 | inputByteArray = temp; |
157 | lsaHeader = createLsaHeader(); | 157 | lsaHeader = createLsaHeader(); |
... | @@ -261,7 +261,7 @@ public class ExternalLsaTest { | ... | @@ -261,7 +261,7 @@ public class ExternalLsaTest { |
261 | ospfExternalDestination.setExternalRouterTag(1); | 261 | ospfExternalDestination.setExternalRouterTag(1); |
262 | ospfExternalDestination.setMetric(10); | 262 | ospfExternalDestination.setMetric(10); |
263 | ospfExternalDestination.setType1orType2Metric(true); | 263 | ospfExternalDestination.setType1orType2Metric(true); |
264 | - ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost())); | 264 | + ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS); |
265 | return ospfExternalDestination; | 265 | return ospfExternalDestination; |
266 | } | 266 | } |
267 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
267 | +} | ... | ... |
... | @@ -24,8 +24,6 @@ import org.onlab.packet.Ip4Address; | ... | @@ -24,8 +24,6 @@ import org.onlab.packet.Ip4Address; |
24 | import org.onosproject.ospf.controller.OspfLsaType; | 24 | import org.onosproject.ospf.controller.OspfLsaType; |
25 | import org.onosproject.ospf.protocol.lsa.LsaHeader; | 25 | import org.onosproject.ospf.protocol.lsa.LsaHeader; |
26 | 26 | ||
27 | - | ||
28 | -import java.net.InetAddress; | ||
29 | import java.util.Vector; | 27 | import java.util.Vector; |
30 | 28 | ||
31 | import static org.hamcrest.MatcherAssert.assertThat; | 29 | import static org.hamcrest.MatcherAssert.assertThat; |
... | @@ -37,6 +35,8 @@ import static org.hamcrest.Matchers.notNullValue; | ... | @@ -37,6 +35,8 @@ import static org.hamcrest.Matchers.notNullValue; |
37 | */ | 35 | */ |
38 | public class NetworkLsaTest { | 36 | public class NetworkLsaTest { |
39 | 37 | ||
38 | + private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1"); | ||
39 | + | ||
40 | private Vector<String> attachedRouters = new Vector(); | 40 | private Vector<String> attachedRouters = new Vector(); |
41 | private NetworkLsa networkLsa; | 41 | private NetworkLsa networkLsa; |
42 | private Ip4Address result; | 42 | private Ip4Address result; |
... | @@ -112,10 +112,8 @@ public class NetworkLsaTest { | ... | @@ -112,10 +112,8 @@ public class NetworkLsaTest { |
112 | */ | 112 | */ |
113 | @Test | 113 | @Test |
114 | public void testAddAttachedRouter() throws Exception { | 114 | public void testAddAttachedRouter() throws Exception { |
115 | - inetAddres = Ip4Address.valueOf(InetAddress.getLocalHost()); | 115 | + networkLsa.addAttachedRouter(LOCAL_ADDRESS); |
116 | - networkLsa.addAttachedRouter(inetAddres); | 116 | + networkLsa.addAttachedRouter(LOCAL_ADDRESS); |
117 | - inetAddres = Ip4Address.valueOf(InetAddress.getLocalHost()); | ||
118 | - networkLsa.addAttachedRouter(inetAddres); | ||
119 | assertThat(networkLsa, is(notNullValue())); | 117 | assertThat(networkLsa, is(notNullValue())); |
120 | } | 118 | } |
121 | 119 | ||
... | @@ -227,4 +225,4 @@ public class NetworkLsaTest { | ... | @@ -227,4 +225,4 @@ public class NetworkLsaTest { |
227 | lsaHeader.setOptions(2); | 225 | lsaHeader.setOptions(2); |
228 | return lsaHeader; | 226 | return lsaHeader; |
229 | } | 227 | } |
230 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
228 | +} | ... | ... |
-
Please register or login to post a comment