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 GetAttrsBase { 30 private String[] keys; 31 private String[][] numAttrs; 32 private String[][] attrs; 33 34 { 35 // set default test data 36 setKeys(new String[] { "host1", "", "ipv6", "sun", "_ftp._Tcp", 37 "1.4.2.1.in-addr.arpa", }); 38 setNumAttrs(new String[][] { { "IN 1", "IN 15", "IN 13", "IN 16" }, 39 { "IN 2", "IN 6" }, { "IN 28" }, { "IN 5" }, { "IN 33" }, 40 { "IN 12" }, }); 41 setAttrs( 42 new String[][] { { "A", "MX", "HINFO", "TXT" }, { "NS", "SOA" }, 43 { "AAAA" }, { "CNAME" }, { "SRV" }, { "PTR" }, }); 44 } 45 46 private static final int ROOT_LIMIT = 5; // point at which to use root ctx 47 48 private int index; 49 50 public void testAgainstNonRootUrl() throws Exception { 51 for (index = 0; index < ROOT_LIMIT; index++) { 52 Attributes retAttrs = getAttributes(); 53 verifyAttributes(retAttrs); 54 } 55 } 56 57 public void switchToRootUrl() throws NamingException { 58 DNSTestUtils.cleanup(context()); 59 env().put(Context.PROVIDER_URL, DNSTestUtils.getRootUrl(env())); 60 setContext(new InitialDirContext(env())); 61 } 62 63 public void testAgainstRootUrl() throws Exception { 64 for (index = ROOT_LIMIT; index < keys.length; index++) { 65 Attributes retAttrs = getAttributes(); 66 verifyAttributes(retAttrs); 67 } 68 } 69 70 @Override public void verifyAttributes(Attributes retAttrs) 71 throws Exception { 72 DNSTestUtils.verifySchema(retAttrs, attrs[index], new String[] {}); 73 } 74 75 public int getIndex() { 76 return index; 77 } 78 79 public String[] getKeys() { 80 return keys; 81 } 82 83 public void setKeys(String[] keys) { 84 this.keys = keys; 85 } 86 87 public String[][] getNumAttrs() { 88 return numAttrs; 89 } 90 91 public void setNumAttrs(String[][] numAttrs) { 92 this.numAttrs = numAttrs; 93 } 94 95 public String[][] getAttrs() { 96 return attrs; 97 } 98 99 public void setAttrs(String[][] attrs) { 100 this.attrs = attrs; 101 } 102 }