Skip to content

Commit

Permalink
DATAMONGO-1062 - Fix failing test in ServerAddressPropertyEditorUnitT…
Browse files Browse the repository at this point in the history
…ests.

The test rejectsAddressConfigWithoutASingleParsableServerAddress fails because the supposedly non-existing hostname "bar" "now" resolves to a real host-address.

The addresses "gugu.nonexistant.example.org, gaga.nonexistant.example.org" shouldn't be resolvable TM.
  • Loading branch information
Thomas Darimont committed Sep 30, 2014
1 parent 02f737d commit fcb7633
Showing 1 changed file with 27 additions and 4 deletions.
Expand Up @@ -15,14 +15,19 @@
*/
package org.springframework.data.mongodb.config;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.Collection;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -49,11 +54,17 @@ public void setUp() {

/**
* @see DATAMONGO-454
* @see DATAMONGO-1062
*/
@Test(expected = IllegalArgumentException.class)
public void rejectsAddressConfigWithoutASingleParsableServerAddress() {
public void rejectsAddressConfigWithoutASingleParsableServerAddress() throws UnknownHostException {

editor.setAsText("foo, bar");
String unknownHost1 = "gugu.nonexistant.example.org";
String unknownHost2 = "gaga.nonexistant.example.org";

assertUnresolveableHostnames(unknownHost1, unknownHost2);

editor.setAsText(unknownHost1+","+unknownHost2);
}

/**
Expand Down Expand Up @@ -193,4 +204,16 @@ private static void assertSingleAddressWithPort(String hostAddress, Integer port
assertThat(addresses, hasItem(new ServerAddress(InetAddress.getByName(hostAddress), port)));
}
}

private void assertUnresolveableHostnames(String... hostnames) {

for (String hostname : hostnames) {
try {
InetAddress.getByName(hostname);
Assert.fail("Supposedly unresolveable hostname '" + hostname + "' can be resolved.");
} catch (UnknownHostException expected) {
// ok
}
}
}
}

0 comments on commit fcb7633

Please sign in to comment.