use of org.opennms.core.test.dns.annotations.DNSZone in project opennms by OpenNMS.
the class JUnitDNSServerExecutionListener method beforeTestMethod.
/** {@inheritDoc} */
@Override
public void beforeTestMethod(final TestContext testContext) throws Exception {
super.beforeTestMethod(testContext);
final JUnitDNSServer config = findTestAnnotation(JUnitDNSServer.class, testContext);
if (config == null) {
return;
}
LOG.info("initializing DNS on port {}", config.port());
m_server = new DNSServer();
m_server.addPort(config.port());
for (final DNSZone dnsZone : config.zones()) {
String name = dnsZone.name();
if (!name.endsWith(".")) {
name = name + ".";
}
final Name zoneName = Name.fromString(name, Name.root);
LOG.debug("zoneName = {}", zoneName);
final Zone zone = new Zone(zoneName, new Record[] { new SOARecord(zoneName, DClass.IN, DEFAULT_TTL, zoneName, Name.fromString("admin." + name), 1, DEFAULT_TTL, DEFAULT_TTL, DEFAULT_TTL, DEFAULT_TTL), new NSRecord(zoneName, DClass.IN, DEFAULT_TTL, Name.fromString("resolver1.opendns.com.")), new NSRecord(zoneName, DClass.IN, DEFAULT_TTL, Name.fromString("resolver2.opendns.com.")), new ARecord(zoneName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(dnsZone.v4address())), new AAAARecord(zoneName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(dnsZone.v6address())) });
LOG.debug("zone = {}", zone);
for (final DNSEntry entry : dnsZone.entries()) {
LOG.debug("adding entry: {}", entry);
String hostname = entry.hostname();
final Name recordName = Name.fromString(hostname, zoneName);
LOG.debug("name = {}", recordName);
if (entry.ipv6()) {
zone.addRecord(new AAAARecord(recordName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(entry.address())));
} else {
zone.addRecord(new ARecord(recordName, DClass.IN, DEFAULT_TTL, InetAddressUtils.addr(entry.address())));
}
}
m_server.addZone(zone);
}
LOG.debug("starting DNS server");
m_server.start();
}
Aggregations