Search in sources :

Example 1 with MX

use of org.minidns.record.MX in project minidns by MiniDNS.

the class DNSMessageTest method testMXLookup.

@Test
public void testMXLookup() throws Exception {
    DNSMessage m = getMessageFromResource("gmail-mx");
    assertFalse(m.authoritativeAnswer);
    List<Record<? extends Data>> answers = m.answerSection;
    assertEquals(5, answers.size());
    Map<Integer, DNSName> mxes = new TreeMap<>();
    for (Record<? extends Data> r : answers) {
        assertCsEquals("gmail.com", r.name);
        Data d = r.getPayload();
        assertTrue(d instanceof MX);
        assertEquals(TYPE.MX, d.getType());
        mxes.put(((MX) d).priority, ((MX) d).target);
    }
    assertCsEquals("gmail-smtp-in.l.google.com", mxes.get(5));
    assertCsEquals("alt1.gmail-smtp-in.l.google.com", mxes.get(10));
    assertCsEquals("alt2.gmail-smtp-in.l.google.com", mxes.get(20));
    assertCsEquals("alt3.gmail-smtp-in.l.google.com", mxes.get(30));
    assertCsEquals("alt4.gmail-smtp-in.l.google.com", mxes.get(40));
}
Also used : Record(org.minidns.record.Record) Data(org.minidns.record.Data) MX(org.minidns.record.MX) DNSName(org.minidns.dnsname.DNSName) TreeMap(java.util.TreeMap) DNSMessage(org.minidns.dnsmessage.DNSMessage) Test(org.junit.Test)

Aggregations

TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1 DNSMessage (org.minidns.dnsmessage.DNSMessage)1 DNSName (org.minidns.dnsname.DNSName)1 Data (org.minidns.record.Data)1 MX (org.minidns.record.MX)1 Record (org.minidns.record.Record)1