1 /*
2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  */
23 
24 import javax.naming.Context;
25 import javax.naming.NamingException;
26 import javax.naming.directory.Attributes;
27 import javax.naming.directory.InitialDirContext;
28 
29 public abstract class GetRRsBase extends DNSTestBase {
30     public static final int ROOT_LIMIT = 5; // point at which to use root ctx
31     private String[] keys;
32     private String[][] numAttrs;
33     private String[][] attrs;
34 
GetRRsBase()35     public GetRRsBase() {
36         // set default test data
37         setKeys(new String[] { "host1", "", "ipv6", "sun", "_ftp._Tcp",
38                 "1.4.2.1.in-addr.arpa", });
39         setNumAttrs(new String[][] { { "IN 1", "IN 15", "IN 13", "IN 16" },
40                 { "IN 2", "IN 6" }, { "IN 28" }, { "IN 5" }, { "IN 33" },
41                 { "IN 12" }, });
42         setAttrs(
43                 new String[][] { { "A", "MX", "HINFO", "TXT" }, { "NS", "SOA" },
44                         { "AAAA" }, { "CNAME" }, { "SRV" }, { "PTR" }, });
45     }
46 
initContext()47     public void initContext() throws Exception {
48         setContext(new InitialDirContext(env()));
49     }
50 
switchToRootUrl()51     public void switchToRootUrl() throws NamingException {
52         DNSTestUtils.cleanup(context());
53         env().put(Context.PROVIDER_URL, DNSTestUtils.getRootUrl(env()));
54         setContext(new InitialDirContext(env()));
55     }
56 
verifyAttributes(Attributes attrs, String[] mandatory)57     public void verifyAttributes(Attributes attrs, String[] mandatory) {
58         DNSTestUtils.verifySchema(attrs, mandatory, new String[] {});
59     }
60 
getAttributes(String name, String[] attrIds)61     public Attributes getAttributes(String name, String[] attrIds)
62             throws Exception {
63         return context().getAttributes(name, attrIds);
64     }
65 
setKeys(String[] keys)66     public void setKeys(String[] keys) {
67         this.keys = keys;
68     }
69 
getKeys()70     public String[] getKeys() {
71         return keys;
72     }
73 
setNumAttrs(String[][] numAttrs)74     public void setNumAttrs(String[][] numAttrs) {
75         this.numAttrs = numAttrs;
76     }
77 
getNumAttrs()78     public String[][] getNumAttrs() {
79         return numAttrs;
80     }
81 
setAttrs(String[][] attrs)82     public void setAttrs(String[][] attrs) {
83         this.attrs = attrs;
84     }
85 
getAttrs()86     public String[][] getAttrs() {
87         return attrs;
88     }
89 }
90