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.james.jspf;
22  
23  import org.apache.james.jspf.impl.DNSServiceXBillImpl;
24  import org.xbill.DNS.DClass;
25  import org.xbill.DNS.Lookup;
26  import org.xbill.DNS.Name;
27  import org.xbill.DNS.Record;
28  import org.xbill.DNS.SPFRecord;
29  import org.xbill.DNS.TXTRecord;
30  import org.xbill.DNS.TextParseException;
31  import org.xbill.DNS.Type;
32  
33  import java.net.InetAddress;
34  import java.net.UnknownHostException;
35  
36  import junit.framework.TestCase;
37  
38  public class DNSServiceXBillImplTest extends TestCase {
39  
40      protected void setUp() throws Exception {
41          super.setUp();
42      }
43  
44      protected void tearDown() throws Exception {
45          super.tearDown();
46      }
47  
48      /*
49       * Test method for
50       * 'org.apache.james.jspf.DNSServiceXBillImpl.getLocalDomainNames()'
51       */
52      public void testGetLocalDomainNames() throws UnknownHostException,
53              TextParseException {
54          // This write MACHINE-NAME/MACHINE-ADDRESS
55          System.out.println(InetAddress.getLocalHost());
56          // THIS WRITE localhost/127.0.0.1
57          System.out.println(InetAddress.getAllByName(null)[0]);
58          // THIS WRITE a fully qualified MACHINE-NAME.MACHINE-DOMAIN
59          System.out.println(InetAddress.getLocalHost().getCanonicalHostName());
60          // THIS WRITE localhost
61          System.out.println(InetAddress.getAllByName(null)[0]
62                  .getCanonicalHostName());
63          Record[] record = new Lookup(Name.root, Type.ANY).run();
64          if (record !=null) System.out.println(record[0]);
65      }
66      
67      public void testMultipleStrings() throws Exception {
68          Record[] rr = new Record[] { TXTRecord.fromString(Name.fromString("test.local."), Type.TXT, DClass.IN, 0, "\"string \" \"concatenated\"", Name.fromString("local.")) };
69          assertEquals("string concatenated", DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
70  
71          rr = new Record[] { TXTRecord.fromString(Name.fromString("test.local."), Type.TXT, DClass.IN, 0, "string", Name.fromString("local.")) };
72          assertEquals("string", DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
73  
74          rr = new Record[] { TXTRecord.fromString(Name.fromString("test.local."), Type.TXT, DClass.IN, 0, "\"quoted string\"", Name.fromString("local.")) };
75          assertEquals("quoted string", DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
76  
77          rr = new Record[] { SPFRecord.fromString(Name.fromString("test.local."), Type.SPF, DClass.IN, 0, "\"quot\" \"ed st\" \"ring\"", Name.fromString("local.")) };
78          assertEquals("quoted string", DNSServiceXBillImpl.convertRecordsToList(rr).get(0));
79      }
80  
81  }