1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  
21  package org.apache.directory.server.dns.io.encoder;
22  
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.apache.directory.server.dns.store.DnsAttribute;
28  import org.apache.mina.common.ByteBuffer;
29  
30  
31  /**
32   * Tests for the SRV record encoder.
33   * 
34   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
35   * @version $Rev: 501160 $, $Date: 2007-01-29 12:41:33 -0700 (Mon, 29 Jan 2007) $
36   */
37  public class ServerSelectionRecordEncoderTest extends AbstractResourceRecordEncoderTest
38  {
39      String priority = "0";
40      String weight = "3";
41      String port = "9";
42      String srvName = "srv.apache.org";
43      String[] srvParts = srvName.split( "\\." );
44  
45  
46      @Override
47      protected Map getAttributes()
48      {
49          Map map = new HashMap();
50          map.put( DnsAttribute.SERVICE_PRIORITY.toLowerCase(), priority );
51          map.put( DnsAttribute.SERVICE_WEIGHT.toLowerCase(), weight );
52          map.put( DnsAttribute.SERVICE_PORT.toLowerCase(), port );
53          map.put( DnsAttribute.DOMAIN_NAME.toLowerCase(), srvName );
54          return map;
55      }
56  
57  
58      @Override
59      protected ResourceRecordEncoder getEncoder()
60      {
61          return new ServerSelectionRecordEncoder();
62      }
63  
64  
65      @Override
66      protected void putExpectedResourceData( ByteBuffer expectedData )
67      {
68          expectedData.put( ( byte ) 22 );
69          expectedData.putShort( Short.parseShort( priority ) );
70          expectedData.putShort( Short.parseShort( weight ) );
71          expectedData.putShort( Short.parseShort( port ) );
72          expectedData.put( ( byte ) srvParts[0].length() ); // 1
73          expectedData.put( srvParts[0].getBytes() ); // + 3
74          expectedData.put( ( byte ) srvParts[1].length() ); // + 1
75          expectedData.put( srvParts[1].getBytes() ); // + 6
76          expectedData.put( ( byte ) srvParts[2].length() ); // + 1
77          expectedData.put( srvParts[2].getBytes() ); // + 3
78          expectedData.put( ( byte ) 0x00 ); // + 1 = 16
79      }
80  }