1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.directory.server.dns.io.encoder;
22
23
24 import junit.framework.TestCase;
25
26 import org.apache.directory.server.dns.messages.QuestionRecord;
27 import org.apache.directory.server.dns.messages.RecordClass;
28 import org.apache.directory.server.dns.messages.RecordType;
29 import org.apache.mina.common.ByteBuffer;
30
31
32
33
34
35
36
37
38 public class QuestionRecordEncoderTest extends TestCase
39 {
40 ByteBuffer expectedData;
41
42 QuestionRecordEncoder encoder;
43
44 String name = "www.apache.org";
45 String[] nameParts = name.split( "\\." );
46 RecordType type = RecordType.A;
47 RecordClass rClass = RecordClass.IN;
48
49 QuestionRecord record = new QuestionRecord( name, type, rClass );
50
51
52 public void setUp()
53 {
54 encoder = new QuestionRecordEncoder();
55
56 expectedData = ByteBuffer.allocate( 128 );
57 expectedData.put( ( byte ) nameParts[0].length() );
58 expectedData.put( nameParts[0].getBytes() );
59 expectedData.put( ( byte ) nameParts[1].length() );
60 expectedData.put( nameParts[1].getBytes() );
61 expectedData.put( ( byte ) nameParts[2].length() );
62 expectedData.put( nameParts[2].getBytes() );
63 expectedData.put( ( byte ) 0x00 );
64 expectedData.putShort( type.convert() );
65 expectedData.putShort( rClass.convert() );
66 }
67
68
69 public void testEncode()
70 {
71 ByteBuffer out = ByteBuffer.allocate( 128 );
72 encoder.put( out, record );
73 assertEquals( expectedData, out );
74 }
75 }