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
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfDeviceTedImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfDeviceTedImplTest.java
index d919fc0..3c2d416 100755
--- a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfDeviceTedImplTest.java
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfDeviceTedImplTest.java
@@ -21,7 +21,6 @@
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
-import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
@@ -32,6 +31,8 @@
* Unit test class for OspfDeviceTedImpl.
*/
public class OspfDeviceTedImplTest {
+ private static final Ip6Address LOCAL_ADDRESS = Ip6Address.valueOf("::1");
+
private OspfDeviceTedImpl ospfDeviceTed;
@Before
@@ -127,10 +128,10 @@
/**
* Tests ipv6RouterIds() getter method.
*/
- @Test(expected = Exception.class)
+ @Test
public void testIpv6RouterIds() throws Exception {
List list = new ArrayList();
- list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
+ list.add(LOCAL_ADDRESS);
ospfDeviceTed.setIpv6RouterIds(list);
assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
}
@@ -138,11 +139,11 @@
/**
* Tests ipv6RouterIds() setter method.
*/
- @Test(expected = Exception.class)
+ @Test
public void testSetIpv6RouterIds() throws Exception {
List list = new ArrayList();
- list.add(Ip6Address.valueOf(InetAddress.getLocalHost()));
+ list.add(LOCAL_ADDRESS);
ospfDeviceTed.setIpv6RouterIds(list);
assertThat(ospfDeviceTed.ipv6RouterIds().size(), is(1));
}
-}
\ No newline at end of file
+}
diff --git a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfLinkTedImplTest.java b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfLinkTedImplTest.java
index 72180af..278dfca 100755
--- a/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfLinkTedImplTest.java
+++ b/protocols/ospf/ctl/src/test/java/org/onosproject/ospf/controller/impl/OspfLinkTedImplTest.java
@@ -21,7 +21,6 @@
import org.onlab.packet.Ip4Address;
import org.onlab.util.Bandwidth;
-import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
@@ -33,6 +32,8 @@
* Unit test class for OspfDeviceTedImpl.
*/
public class OspfLinkTedImplTest {
+ private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1");
+
private OspfLinkTedImpl ospfLinkTed;
@Before
@@ -90,7 +91,7 @@
@Test
public void testIpv4RemRouterId() throws Exception {
List list = new ArrayList();
- list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ list.add(LOCAL_ADDRESS);
ospfLinkTed.setIpv4RemRouterId(list);
assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
}
@@ -101,7 +102,7 @@
@Test
public void testSetIpv4RemRouterId() throws Exception {
List list = new ArrayList();
- list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ list.add(LOCAL_ADDRESS);
ospfLinkTed.setIpv4RemRouterId(list);
assertThat(ospfLinkTed.ipv4RemRouterId().size(), is(1));
}
@@ -132,7 +133,7 @@
@Test
public void testIpv4LocRouterId() throws Exception {
List list = new ArrayList();
- list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ list.add(LOCAL_ADDRESS);
ospfLinkTed.setIpv4LocRouterId(list);
assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
}
@@ -143,7 +144,7 @@
@Test
public void testSetIpv4LocRouterId() throws Exception {
List list = new ArrayList();
- list.add(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ list.add(LOCAL_ADDRESS);
ospfLinkTed.setIpv4LocRouterId(list);
assertThat(ospfLinkTed.ipv4LocRouterId().size(), is(1));
}
@@ -201,4 +202,4 @@
ospfLinkTed.setMaxUnResBandwidth(Bandwidth.bps(1234.0));
assertThat(ospfLinkTed.maxUnResBandwidth(), is(notNullValue()));
}
-}
\ No newline at end of file
+}
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestinationTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestinationTest.java
index 947f34a..fcaafad 100644
--- a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestinationTest.java
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/subtypes/OspfExternalDestinationTest.java
@@ -20,8 +20,6 @@
import org.junit.Test;
import org.onlab.packet.Ip4Address;
-import java.net.InetAddress;
-
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
@@ -31,6 +29,8 @@
*/
public class OspfExternalDestinationTest {
+ private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1");
+
private OspfExternalDestination ospfExternalDestination;
@Before
@@ -84,8 +84,8 @@
*/
@Test
public void testGetForwardingAddress() throws Exception {
- ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
- assertThat(ospfExternalDestination.forwardingAddress(), is(Ip4Address.valueOf(InetAddress.getLocalHost())));
+ ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
+ assertThat(ospfExternalDestination.forwardingAddress(), is(LOCAL_ADDRESS));
}
@@ -94,8 +94,8 @@
*/
@Test
public void testSetForwardingAddress() throws Exception {
- ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
- assertThat(ospfExternalDestination.forwardingAddress(), is(Ip4Address.valueOf(InetAddress.getLocalHost())));
+ ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
+ assertThat(ospfExternalDestination.forwardingAddress(), is(LOCAL_ADDRESS));
}
/**
@@ -123,4 +123,4 @@
public void testToString() throws Exception {
assertThat(ospfExternalDestination.toString(), is(notNullValue()));
}
-}
\ No newline at end of file
+}
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsaTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsaTest.java
index 5796f34..d8b3d57 100644
--- a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsaTest.java
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/ExternalLsaTest.java
@@ -25,8 +25,6 @@
import org.onosproject.ospf.protocol.lsa.LsaHeader;
import org.onosproject.ospf.protocol.lsa.subtypes.OspfExternalDestination;
-
-import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Vector;
@@ -39,6 +37,8 @@
*/
public class ExternalLsaTest {
+ private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1");
+
private ExternalLsa externalLsa;
private Vector<OspfExternalDestination> externalDestinations = new Vector<OspfExternalDestination>();
private Ip4Address result;
@@ -127,7 +127,7 @@
ospfExternalDestination.setMetric(50);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination1);
- ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
inputByteArray = createByteForNetworkLsa();
lsaHeader = createLsaHeader();
externalLsa = new ExternalLsa(lsaHeader);
@@ -151,7 +151,7 @@
ospfExternalDestination.setMetric(50);
ospfExternalDestination.setType1orType2Metric(true);
externalLsa.addExternalDestination(ospfExternalDestination1);
- ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
byte[] temp = {0, 0, 0};
inputByteArray = temp;
lsaHeader = createLsaHeader();
@@ -261,7 +261,7 @@
ospfExternalDestination.setExternalRouterTag(1);
ospfExternalDestination.setMetric(10);
ospfExternalDestination.setType1orType2Metric(true);
- ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
+ ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
return ospfExternalDestination;
}
-}
\ No newline at end of file
+}
diff --git a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsaTest.java b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsaTest.java
index d2f1a2c..3f25792 100644
--- a/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsaTest.java
+++ b/protocols/ospf/protocol/src/test/java/org/onosproject/ospf/protocol/lsa/types/NetworkLsaTest.java
@@ -24,8 +24,6 @@
import org.onosproject.ospf.controller.OspfLsaType;
import org.onosproject.ospf.protocol.lsa.LsaHeader;
-
-import java.net.InetAddress;
import java.util.Vector;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -37,6 +35,8 @@
*/
public class NetworkLsaTest {
+ private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1");
+
private Vector<String> attachedRouters = new Vector();
private NetworkLsa networkLsa;
private Ip4Address result;
@@ -112,10 +112,8 @@
*/
@Test
public void testAddAttachedRouter() throws Exception {
- inetAddres = Ip4Address.valueOf(InetAddress.getLocalHost());
- networkLsa.addAttachedRouter(inetAddres);
- inetAddres = Ip4Address.valueOf(InetAddress.getLocalHost());
- networkLsa.addAttachedRouter(inetAddres);
+ networkLsa.addAttachedRouter(LOCAL_ADDRESS);
+ networkLsa.addAttachedRouter(LOCAL_ADDRESS);
assertThat(networkLsa, is(notNullValue()));
}
@@ -227,4 +225,4 @@
lsaHeader.setOptions(2);
return lsaHeader;
}
-}
\ No newline at end of file
+}