Package net.windwards.dnsfrontend.backend

Source Code of net.windwards.dnsfrontend.backend.TestBinaryBackendProtocol

package net.windwards.dnsfrontend.backend;

import junit.framework.Assert;
import net.windwards.dnsfrontend.api.Protocol;
import net.windwards.dnsfrontend.util.TestingConfiguration;
import org.junit.Test;
import org.xbill.DNS.AAAARecord;
import org.xbill.DNS.ARecord;
import org.xbill.DNS.Record;

/**
*/
public class TestBinaryBackendProtocol {

    @Test
    public void decodeIPv4Update() throws Exception {
        byte[] ipv4message = {
                1, // IPv4 update
                (byte) 192, (byte) 168, 0, 1, // IPv4
                3, // host name length
                'f', 'o', 'o', // hostname
                3,
                'b', 'a', 'r' // domain moniker
        };

        TestingConfiguration conf = new TestingConfiguration("bar", "example.com.", 12345);

        Protocol protocol = new BinaryBackendProtocol();
        Record result = protocol.decode(ipv4message, conf);
        ARecord rec = (ARecord) result;
        Assert.assertEquals("foo.example.com.", rec.getName().toString());
        Assert.assertEquals("192.168.0.1", rec.getAddress().getHostAddress());
        Assert.assertEquals(12345, rec.getTTL());
    }

    @Test
    public void decodeIPv6Update() throws Exception {
        byte[] ipv6message = {
                2, // IPv6 update
                0x20, 0x2, 0x53, (byte) 0xfe, 0x52, (byte) 0xa1, 0x0, 0x7,
                0x2, 0x24, 0x1d, (byte) 0xff, (byte) 0xfe, 0x7d, 0x6b, (byte) 0xef,
                3, // host name length
                'f', 'o', 'o', // hostname
                3,
                'b', 'a', 'r'
        };

        TestingConfiguration conf = new TestingConfiguration("bar", "example.com.", 12345);

        Protocol protocol = new BinaryBackendProtocol();
        Record result = protocol.decode(ipv6message, conf);
        AAAARecord rec = (AAAARecord) result;
        Assert.assertEquals("foo.example.com.", rec.getName().toString());
        Assert.assertEquals("2002:53fe:52a1:7:224:1dff:fe7d:6bef", rec.getAddress().getHostAddress());
        Assert.assertEquals(12345, rec.getTTL());
    }

}
TOP

Related Classes of net.windwards.dnsfrontend.backend.TestBinaryBackendProtocol

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.