@Test public void getDomainsShouldContainDetectedDomainsAndIps() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(true)); String detected = "detected.tld"; String detectedIp = "148.25.32.1"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); InetAddress detectedAddress = mock(InetAddress.class); when(detectedAddress.getHostAddress()).thenReturn(detectedIp); when(dnsService.getAllByName(detected)).thenReturn(ImmutableList.of(detectedAddress)); assertThat(domainList.getDomains()).contains(Domain.of(detected), Domain.of(detectedIp)); }
@Test public void getDomainsShouldContainDetectedDomainsAndIpsOfAddedDomains() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(true)); String added = "added.tld"; String detected = "detected.tld"; String detectedIp1 = "148.25.32.1"; String detectedIp2 = "148.25.32.2"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); InetAddress detectedAddress1 = mock(InetAddress.class); InetAddress detectedAddress2 = mock(InetAddress.class); when(detectedAddress1.getHostAddress()).thenReturn(detectedIp1); when(detectedAddress2.getHostAddress()).thenReturn(detectedIp2); when(dnsService.getAllByName(detected)).thenReturn(ImmutableList.of(detectedAddress1)); when(dnsService.getAllByName(added)).thenReturn(ImmutableList.of(detectedAddress2)); domainList.addDomain(Domain.of(added)); assertThat(domainList.getDomains()) .extracting(Domain::name) .contains(detected, detectedIp1, added, detectedIp2); }
@Test public void getDomainsShouldContainDetectedDomains() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(true) .autoDetectIp(false)); String detected = "detected.tld"; when(dnsService.getLocalHost()).thenReturn(InetAddress.getByName("127.0.0.1")); when(dnsService.getHostName(any(InetAddress.class))).thenReturn(detected); assertThat(domainList.getDomains()).contains(Domain.of(detected)); }
@Test public void getDomainsShouldNotInteractWithDNSWhenDisabled() throws Exception { domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false)); domainList.getDomains(); verifyZeroInteractions(dnsService); }
@Test public void getDomainsShouldNotDetectDomainsWhenDisabled() throws Exception { Domain domain = Domain.of("domain.tld"); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(domain)); assertThat(domainList.getDomains()).containsOnly(domain); }
@Test public void configuredDomainShouldBeAddedUponConfiguration() throws Exception { Domain domain1 = Domain.of("conf1.tld"); Domain domain2 = Domain.of("conf2.tld"); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .addConfiguredDomains(domain1, domain2)); assertThat(domainList.getDomains()).contains(domain1, domain2); }
@Test public void getDomainsShouldListAddedDomain() throws Exception { Domain defaultDomain = Domain.of("default.tld"); Domain domain = Domain.of("added.tld"); domainList.addDomain(domain); domainList.configure(DomainListConfiguration.builder() .autoDetect(false) .autoDetectIp(false) .defaultDomain(defaultDomain)); assertThat(domainList.getDomains()).containsOnly(domain, defaultDomain); }