use of org.opennms.core.test.dns.annotations.JUnitDNSServer in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoUrlAsResource.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", address = "72.14.204.99") }) })
public void dwoUrlAsResource() throws IOException, JAXBException {
Resource resource = new UrlResource(TEST_URL);
Assert.assertEquals(TEST_URL, resource.getURL().toString());
Requisition req = null;
Assert.assertNotNull(resource);
InputStream resourceStream = resource.getInputStream();
JAXBContext context = JAXBContext.newInstance(Requisition.class);
Unmarshaller um = context.createUnmarshaller();
um.setSchema(null);
req = (Requisition) um.unmarshal(resourceStream);
Assert.assertEquals("should have 2 A records: 1 for example.com, and 1 for www.example.com", 2, req.getNodeCount());
resourceStream.close();
}
use of org.opennms.core.test.dns.annotations.JUnitDNSServer in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoConnect.
/**
* Just test that connection doesn't get implementation without fixing this test
* @throws IOException
*/
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", address = "72.14.204.99") }) })
public void dwoConnect() throws IOException {
URLConnection c = new DnsRequisitionUrlConnection(new URL(TEST_URL));
c.connect();
}
use of org.opennms.core.test.dns.annotations.JUnitDNSServer in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoGetInputStream.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", address = "72.14.204.99") }) })
public void dwoGetInputStream() throws IOException {
URLConnection c = new DnsRequisitionUrlConnection(new URL(TEST_URL));
InputStream s = c.getInputStream();
Assert.assertNotNull(s);
s.close();
}
use of org.opennms.core.test.dns.annotations.JUnitDNSServer 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();
}
use of org.opennms.core.test.dns.annotations.JUnitDNSServer in project opennms by OpenNMS.
the class DnsRequisitionUrlConnectionIT method dwoUrlAsResourceUsingComplexMatchingExpression.
@Test
@JUnitDNSServer(port = 9153, zones = { @DNSZone(name = "example.com", entries = { @DNSEntry(hostname = "www", address = "72.14.204.99") }) })
public void dwoUrlAsResourceUsingComplexMatchingExpression() throws IOException, JAXBException {
String urlString = "dns://localhost:9153/example.com/?expression=(%3Fi)^WWW.EXAM.*";
Resource resource = new UrlResource(urlString);
Assert.assertEquals(urlString, resource.getURL().toString());
Requisition req = null;
Assert.assertNotNull(resource);
InputStream resourceStream = resource.getInputStream();
JAXBContext context = JAXBContext.newInstance(Requisition.class);
Unmarshaller um = context.createUnmarshaller();
um.setSchema(null);
req = (Requisition) um.unmarshal(resourceStream);
Assert.assertEquals(1, req.getNodeCount());
resourceStream.close();
}
Aggregations