Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Error when using junit to test dnsjava related code.

Reply
Thread Tools

Error when using junit to test dnsjava related code.

 
 
eelco.batterink@gmail.com
Guest
Posts: n/a
 
      06-03-2005
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.DNSHa ndler.register(DNSHandler.java:15)
at
com.nextcontrols.number6.domain.failover.CrossChec kerTest.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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debug junit test in eclipse give error kramer31 Java 0 03-05-2009 01:29 AM
How to run test cases in a jar file using junit? webzhao Java 3 12-14-2007 02:35 PM
question related to junit fork www Java 0 04-17-2007 04:48 PM
Using JUnit to test privately contained List? kk_oop@yahoo.com Java 14 03-02-2005 07:30 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments