blob: ff3d8d207971284a278b903f079ec3b7d8f6b104 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.athenz.api;
import org.junit.Test;
import java.util.function.Supplier;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author bjorncs
*/
public class AthenzDomainTest {
@Test
public void domain_can_be_constructed_from_valid_string() {
new AthenzDomain("home.john.my-app");
}
@Test
public void invalid_domain_throws_exception() {
assertInvalid(() -> new AthenzDomain("endswithdot."));
assertInvalid(() -> new AthenzDomain(".startswithdot"));
}
@Test
public void parent_domain_is_without_name_suffix() {
assertEquals(new AthenzDomain("home.john"), new AthenzDomain("home.john.myapp").getParent());
}
@Test
public void domain_name_suffix_is_the_suffix_after_last_dot() {
assertEquals("myapp", new AthenzDomain("home.john.myapp").getNameSuffix());
}
@Test
public void domain_without_dot_is_toplevel() {
assertTrue(new AthenzDomain("toplevel").isTopLevelDomain());
assertFalse(new AthenzDomain("not.toplevel").isTopLevelDomain());
}
private static void assertInvalid(Supplier<AthenzDomain> domainCreator) {
try {
AthenzDomain domain = domainCreator.get();
fail("Expected IllegalArgumentException for domain: " + domain.getName());
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Not a valid domain name"));
}
}
}
|