Error when using junit to test dnsjava related code.

Discussion in 'Java' started by eelco.batterink@gmail.com, Jun 3, 2005.

  1. Guest

    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
    , Jun 3, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Koenning
    Replies:
    0
    Views:
    1,433
    Tom Koenning
    Jul 28, 2003
  2. Replies:
    14
    Views:
    800
    Andrew McDonagh
    Mar 2, 2005
  3. www
    Replies:
    0
    Views:
    473
  4. webzhao
    Replies:
    3
    Views:
    1,138
    proudbug
    Dec 14, 2007
  5. kramer31
    Replies:
    0
    Views:
    461
    kramer31
    Mar 5, 2009
Loading...

Share This Page