aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/net
diff options
context:
space:
mode:
Diffstat (limited to 'vespajlib/src/test/java/com/yahoo/net')
-rw-r--r--vespajlib/src/test/java/com/yahoo/net/DomainNameTest.java35
-rw-r--r--vespajlib/src/test/java/com/yahoo/net/HostnameTest.java35
-rw-r--r--vespajlib/src/test/java/com/yahoo/net/HostnamesTestCase.java (renamed from vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java)4
3 files changed, 72 insertions, 2 deletions
diff --git a/vespajlib/src/test/java/com/yahoo/net/DomainNameTest.java b/vespajlib/src/test/java/com/yahoo/net/DomainNameTest.java
new file mode 100644
index 00000000000..d8e76b71d7e
--- /dev/null
+++ b/vespajlib/src/test/java/com/yahoo/net/DomainNameTest.java
@@ -0,0 +1,35 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.net;
+
+import com.yahoo.net.DomainName;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * @author jonmv
+ */
+class DomainNameTest {
+
+ @Test
+ void testNames() {
+ DomainName.of("name-123.0.321-eman");
+ DomainName.of(("." + "a".repeat(63)).repeat(4).substring(1));
+ DomainName.of("123");
+
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("_"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("-"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("."));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("-foo"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("foo-"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of(".foo"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("foo."));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("foo..bar"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("foo.-.bar"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("foo/"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("foo%"));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of(("." + "a".repeat(32)).repeat(8).substring(1, 257)));
+ assertThrows(IllegalArgumentException.class, () -> DomainName.of("a".repeat(64)));
+ }
+
+}
diff --git a/vespajlib/src/test/java/com/yahoo/net/HostnameTest.java b/vespajlib/src/test/java/com/yahoo/net/HostnameTest.java
new file mode 100644
index 00000000000..ef502aea2cd
--- /dev/null
+++ b/vespajlib/src/test/java/com/yahoo/net/HostnameTest.java
@@ -0,0 +1,35 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.net;
+
+import com.yahoo.net.Hostname;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+/**
+ * @author jonmv
+ */
+public class HostnameTest {
+
+ @Test
+ void testNames() {
+ Hostname.of("name-123.0.321-eman");
+ Hostname.of(("." + "a".repeat(32)).repeat(2).substring(1, 65));
+ Hostname.of("123");
+
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("_"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("-"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("."));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("-foo"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("foo-"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of(".foo"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("foo."));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("foo..bar"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("foo.-.bar"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("foo/"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("foo%"));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of(("." + "a".repeat(32)).repeat(2).substring(1, 66)));
+ assertThrows(IllegalArgumentException.class, () -> Hostname.of("a".repeat(64)));
+ }
+
+}
diff --git a/vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java b/vespajlib/src/test/java/com/yahoo/net/HostnamesTestCase.java
index ee26b357db8..2e942605e3e 100644
--- a/vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/net/HostnamesTestCase.java
@@ -8,11 +8,11 @@ import static org.junit.Assert.assertFalse;
/**
* @author Ulf Lilleengen
*/
-public class HostNameTestCase {
+public class HostnamesTestCase {
@Test
public void testHostnameIsFound() {
- assertFalse(HostName.getLocalhost().isEmpty());
+ assertFalse(Hostnames.getLocalhost().isEmpty());
}
}