Error when using junit to test dnsjava related code.

  • Thread starter eelco.batterink
  • Start date
E

eelco.batterink

I have the following class to register and deregister names from a DNS
server:

package com.nextcontrols.number6.domain.registration;

import org.xbill.DNS.*;
import java.io.*;


public class DNSHandler
{
public static final String DNS_SERVER = "192.168.16.215";
public static final String DNS_ZONE = "nextcontrols.test.";

public static boolean register(String pName, String pAddress) throws
Exception
{
Update update = new Update(zone());
update.add(host(pName), Type.A, 0, pAddress);
Message response = sendUpdate(update);
return true;
}

public static boolean deregister(String pName, String pAddress) throws
Exception
{
try
{

Update update = new Update(zone());
update.delete(host(pName), Type.A, pAddress);
Message response = sendUpdate(update);
return true;
}
catch(Exception e)
{
return false;
}
}

public static boolean clear(String pName) throws Exception
{
try
{
Update update = new Update(zone());
update.delete(host(pName));
Message response = sendUpdate(update);
return true;
}
catch(Exception e)
{
return false;
}
}

private static Name host(String pName) throws TextParseException
{
return Name.fromString(pName, zone());
}

private static Name zone() throws TextParseException
{
return Name.fromString(DNS_ZONE);
}

private static Message sendUpdate(Update pUpdate) throws IOException
{
Resolver res = new SimpleResolver(DNS_SERVER);
res.setTCP(true);
return res.send(pUpdate);
}
}

In ordinary programs, these methods work without any problem. Also, my
JUnit testcase for this class works fine.

However, the problem occurs when I have testcases for other classes
that use these methods.

I then get the following error:

java.lang.NullPointerException
at org.xbill.DNS.Record.getTypedObject(Record.java:64)
at org.xbill.DNS.Record.getEmptyRecord(Record.java:87)
at org.xbill.DNS.Record.fromString(Record.java:503)
at org.xbill.DNS.Record.fromString(Record.java:527)
at org.xbill.DNS.Update.add(Update.java:136)
at
com.nextcontrols.number6.domain.registration.DNSHandler.register(DNSHandler.java:15)
at
com.nextcontrols.number6.domain.failover.CrossCheckerTest.setUp(CrossCheckerTest.java:19)


Note that it works fine if it is not called from the JUnit framework.
The following works normally from any class.


public static void main(String args[])
{
try
{

DNSHandler.clear("number6");
DNSHandler.register("number6", "1.1.1.1");
DNSHandler.register("number6", "1.1.1.2");
DNSHandler.register("number6", "1.1.1.3");
}
catch(Exception e)
{
e.printStackTrace();
}
}
Has anyone had this problem before or knows how to solve it?

Eelco Batterink
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top