package net.windwards.dnsfrontend.backend;
import junit.framework.Assert;
import net.sf.ehcache.Ehcache;
import net.windwards.dnsfrontend.api.Configuration;
import net.windwards.dnsfrontend.util.TestUtils;
import net.windwards.dnsfrontend.util.TestingConfiguration;
import org.junit.Test;
import org.xbill.DNS.ARecord;
import org.xbill.DNS.DClass;
import org.xbill.DNS.Name;
import org.xbill.DNS.Record;
import org.xbill.DNS.Type;
import java.net.InetAddress;
public class TestSimpleBackend {
@Test
public void basicOperation() throws Exception {
Ehcache cache = TestUtils.getEhcache();
Configuration conf = new TestingConfiguration("conf", "example.com.", 1);
ARecord arec = new ARecord(new Name("foo.example.com."),
DClass.IN, 1, InetAddress.getByName("localhost"));
SimpleBackend backend = new SimpleBackend("A", arec);
backend.setConfiguration(conf);
backend.setCache(cache);
Record question = Record.newRecord(new Name("foo.example.com."), Type.A, DClass.IN);
backend.notify(question);
Assert.assertNotNull(cache.get("A:foo.example.com."));
Thread.sleep(1010);
Assert.assertNull(cache.get("A:foo.example.com."));
Assert.assertEquals(0, cache.getSize());
}
}