SRVDNSResolver extends AbstractDNSResolver<SRVRecord> { @Override public Set<SRVRecord> resolve(final String name) { if (name == null) { return super.resolve(DEFAULT_RECORD_NAME); } return super.resolve(name); } SRVDNSResolver();  SRVDNSResolver(final DNSContextFactory factory);  SRVDNSResolver(final DNSContextFactory factory, final boolean ssl); @Override Set<SRVRecord> resolve(final String name); @Override String toString();  }
@Test public void resolve() { final SRVDNSResolver resolver = new SRVDNSResolver(contextFactory); final Set<SRVRecord> records = resolver.resolve("_ldap._tcp.ldaptive.org"); Assert.assertEquals(records.size(), 3); for (SRVRecord record : records) { Assert.assertEquals( record.getLdapURL().getHostnameWithSchemeAndPort(), "ldap: Assert.assertEquals(record.getPort(), 389); Assert.assertEquals(record.getPriority(), 0); Assert.assertTrue(record.getTarget().endsWith(".ldaptive.org")); Assert.assertEquals(record.getWeight(), 100); } }
@Test public void resolveSorted() { final SRVDNSResolver resolver = new SRVDNSResolver(contextFactory); final Set<SRVRecord> records = resolver.resolve("_ldap._tcp.sorted.ldaptive.org"); Assert.assertEquals(records.size(), 3); final Iterator<SRVRecord> i = records.iterator(); int count = 0; while (i.hasNext()) { final SRVRecord record = i.next(); if (count == 0) { Assert.assertEquals(record.getTarget(), "curly.ldaptive.org"); Assert.assertEquals(record.getPriority(), 1); Assert.assertEquals(record.getWeight(), 0); } else if (count == 1) { Assert.assertEquals(record.getTarget(), "moe.ldaptive.org"); Assert.assertEquals(record.getPriority(), 3); Assert.assertEquals(record.getWeight(), 200); } else if (count == 2) { Assert.assertEquals(record.getTarget(), "larry.ldaptive.org"); Assert.assertEquals(record.getPriority(), 5); Assert.assertEquals(record.getWeight(), 100); } else { throw new IllegalStateException("Unknown index:" + count); } count++; } }
@Test public void resolveDefault() { final SRVDNSResolver resolver = new SRVDNSResolver(contextFactory); final Set<SRVRecord> records = resolver.resolve(null); Assert.assertEquals(records.size(), 3); for (SRVRecord record : records) { Assert.assertEquals( record.getLdapURL().getHostnameWithSchemeAndPort(), "ldap: Assert.assertEquals(record.getPort(), 389); Assert.assertEquals(record.getPriority(), 0); Assert.assertTrue(record.getTarget().endsWith(".ldaptive.org")); Assert.assertEquals(record.getWeight(), 100); } }
@Test @Ignore public void resolveCustom() { final String nameserver = System.getProperty("SRVDNSResolverTest.nameserver"); final SRVDNSResolver resolver; if (nameserver == null) { resolver = new SRVDNSResolver(new DefaultDNSContextFactory()); } else { resolver = new SRVDNSResolver(new DefaultDNSContextFactory(nameserver)); } final String recordName = System.getProperty("SRVDNSResolverTest.name"); final Set<SRVRecord> records = resolver.resolve(recordName); Assert.assertTrue(records.size() > 0); }