Jonathan Hart

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
......@@ -21,7 +21,6 @@ import org.junit.Test;
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 @@ import static org.junit.Assert.assertThat;
* 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 @@ public class OspfDeviceTedImplTest {
/**
* 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,10 +139,10 @@ public class OspfDeviceTedImplTest {
/**
* 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));
}
......
......@@ -21,7 +21,6 @@ import org.junit.Test;
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 @@ import static org.junit.Assert.assertThat;
* 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 @@ public class OspfLinkTedImplTest {
@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 @@ public class OspfLinkTedImplTest {
@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 @@ public class OspfLinkTedImplTest {
@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 @@ public class OspfLinkTedImplTest {
@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));
}
......
......@@ -20,8 +20,6 @@ import org.junit.Before;
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 @@ import static org.hamcrest.Matchers.notNullValue;
*/
public class OspfExternalDestinationTest {
private static final Ip4Address LOCAL_ADDRESS = Ip4Address.valueOf("127.0.0.1");
private OspfExternalDestination ospfExternalDestination;
@Before
......@@ -84,8 +84,8 @@ public class OspfExternalDestinationTest {
*/
@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 @@ public class OspfExternalDestinationTest {
*/
@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));
}
/**
......
......@@ -25,8 +25,6 @@ import org.onosproject.ospf.controller.OspfLsaType;
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 @@ import static org.hamcrest.Matchers.notNullValue;
*/
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 @@ public class ExternalLsaTest {
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 @@ public class ExternalLsaTest {
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 @@ public class ExternalLsaTest {
ospfExternalDestination.setExternalRouterTag(1);
ospfExternalDestination.setMetric(10);
ospfExternalDestination.setType1orType2Metric(true);
ospfExternalDestination.setForwardingAddress(Ip4Address.valueOf(InetAddress.getLocalHost()));
ospfExternalDestination.setForwardingAddress(LOCAL_ADDRESS);
return ospfExternalDestination;
}
}
......
......@@ -24,8 +24,6 @@ import org.onlab.packet.Ip4Address;
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 @@ import static org.hamcrest.Matchers.notNullValue;
*/
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 @@ public class NetworkLsaTest {
*/
@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()));
}
......