8208483: Add 5 JNDI tests to com/sun/jndi/dns/FactoryTests/

Reviewed-by: vtewari, rriggs
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/DirAFactory.java b/test/jdk/com/sun/jndi/dns/FactoryTests/DirAFactory.java
new file mode 100644
index 0000000..ece6691
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/DirAFactory.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.spi.DirObjectFactory;
+import java.util.Hashtable;
+
+public class DirAFactory implements DirObjectFactory {
+    @Override
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+            Hashtable<?, ?> environment, Attributes attrs) {
+        System.out.println(this.getClass().getName()
+                + "(DirObjectFactory).getObjectInstance(): " + name + ": "
+                + attrs);
+
+        if (attrs != null) {
+            Attribute txt = attrs.get("A");
+            if (txt != null) {
+                return new TestDnsObject(txt);
+            }
+        }
+
+        // return null to indicate other factories should be tried
+        return null;
+    }
+
+    @Override
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+            Hashtable<?, ?> environment) {
+        System.out.println(this.getClass().getName()
+                + "(ObjectFactory).getObjectInstance(): " + name);
+
+        return null;
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/DirTxtFactory.java b/test/jdk/com/sun/jndi/dns/FactoryTests/DirTxtFactory.java
new file mode 100644
index 0000000..b1c22b0
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/DirTxtFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.spi.DirObjectFactory;
+import java.util.Hashtable;
+
+public class DirTxtFactory extends TxtFactory implements DirObjectFactory {
+    @Override
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+            Hashtable<?, ?> environment, Attributes attrs) {
+        System.out.println(this.getClass().getName()
+                + "(DirObjectFactory).getObjectInstance(): " + name + ": "
+                + attrs);
+
+        if (attrs != null) {
+            Attribute txt = attrs.get("TXT");
+            if (txt != null) {
+                return new TestDnsObject(txt);
+            }
+        }
+
+        // return null to indicate other factories should be tried
+        return null;
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/GetAttrsWithFactory.dns b/test/jdk/com/sun/jndi/dns/FactoryTests/GetAttrsWithFactory.dns
new file mode 100644
index 0000000..3d70cba
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/GetAttrsWithFactory.dns
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for GetAttrsWithFactory.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the GetAttrsWithFactory application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: FB 13 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF                                           ...
+
+
+# DNS Response
+
+0000: FB 13 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/GetAttrsWithFactory.java b/test/jdk/com/sun/jndi/dns/FactoryTests/GetAttrsWithFactory.java
new file mode 100644
index 0000000..faaa6b2
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/GetAttrsWithFactory.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.InitialDirContext;
+
+/*
+ * @test
+ * @bug 8208483
+ * @summary Tests that setting the object factory and
+ *          com.sun.jndi.dns.lookup.attr properties does not affect how
+ *          we can get the attributes of a DNS entry.
+ *          Use getAttributes form that has no attrIds parameter.
+ * @library ../lib/ ../AttributeTests/
+ * @modules java.base/sun.security.util
+ * @build TestDnsObject TxtFactory
+ * @run main/othervm GetAttrsWithFactory
+ */
+
+public class GetAttrsWithFactory extends GetAttrsBase {
+
+    public static void main(String[] args) throws Exception {
+        new GetAttrsWithFactory().run(args);
+    }
+
+    /*
+     * Tests that setting the object factory and
+     * com.sun.jndi.dns.lookup.attr properties does not affect how
+     * we can get the attributes of a DNS entry.
+     */
+    @Override
+    public void runTest() throws Exception {
+        // initial context with object factory and lookup attr
+        env().put(Context.OBJECT_FACTORIES, "TxtFactory");
+        env().put(LookupFactoryBase.DNS_LOOKUP_ATTR, "A");
+        setContext(new InitialDirContext(env()));
+
+        Attributes retAttrs = getAttributes();
+        verifyAttributes(retAttrs);
+    }
+
+    /*
+     * Use getAttributes form that has no attrIds parameter.
+     */
+    @Override
+    public Attributes getAttributes() throws NamingException {
+        return context().getAttributes(getKey());
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupFactoryBase.java b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupFactoryBase.java
new file mode 100644
index 0000000..5913d68
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupFactoryBase.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * Abstract test base for Factory related Tests, this class extends DNSTestBase.
+ *
+ * This test base will also been referenced outside of current open test folder,
+ * please double check all usages when modify this.
+ *
+ * @see DNSTestBase
+ * @see TestBase
+ */
+public abstract class LookupFactoryBase extends DNSTestBase {
+    // pre defined attribute value for 'A'
+    public static final String ATTRIBUTE_VALUE = "1.2.4.1";
+
+    public static final String DNS_LOOKUP_ATTR = "com.sun.jndi.dns.lookup.attr";
+
+    private String key;
+
+    public LookupFactoryBase() {
+        // set default test data
+        setKey("host1");
+    }
+
+    /**
+     * Overload method of verifyLookupObject, specify class type TestDnsObject.
+     *
+     * @param obj given lookup returned object
+     */
+    public void verifyLookupObject(Object obj) {
+        verifyLookupObject(obj, TestDnsObject.class);
+    }
+
+    /**
+     * Verify given lookup returned object whether match class type, will throw
+     * RuntimeException if verify failed.
+     *
+     * @param obj       given lookup returned object
+     * @param classType given class type
+     * @param <T>       given type
+     */
+    public <T> void verifyLookupObject(Object obj, Class<T> classType) {
+        DNSTestUtils.debug("Object is: " + obj);
+        if (!classType.isInstance(obj)) {
+            throw new RuntimeException(
+                    "Expected " + classType + ", but found " + obj.getClass());
+        }
+    }
+
+    /**
+     * Verify given lookup returned object match class type TestDnsObject, then
+     * verify the object toString() value match with given value, will throw
+     * RuntimeException if any verification step failed.
+     *
+     * @param obj   given lookup returned object
+     * @param value given expected value
+     */
+    public void verifyLookupObjectAndValue(Object obj, String value) {
+        verifyLookupObject(obj);
+        if (!obj.toString().equals(value)) {
+            throw new RuntimeException(
+                    "Expected " + value + ", but found " + obj.toString());
+        }
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    public void setKey(String key) {
+        this.key = key;
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAnyAttrProp.dns b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAnyAttrProp.dns
new file mode 100644
index 0000000..afd7689
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAnyAttrProp.dns
@@ -0,0 +1,58 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for LookupWithAnyAttrProp.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the LookupWithAnyAttrProp application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 14 F4 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01                                           ...
+
+
+# DNS Response
+
+0000: 14 F4 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 12 00 14 05 72 65  ..............re
+0090: 6C 61 79 05 74 65 78 61   73 02 75 73 00 C0 0C 00  lay.texas.us....
+00A0: 0F 00 01 00 00 8C A0 00   0F 00 0A 05 72 65 6C 61  ............rela
+00B0: 79 04 6F 68 69 6F C0 99   C0 0C 00 01 00 01 00 01  y.ohio..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAnyAttrProp.java b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAnyAttrProp.java
new file mode 100644
index 0000000..67c28c18
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAnyAttrProp.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.directory.InitialDirContext;
+
+/*
+ * @test
+ * @bug 8208483
+ * @summary Tests that we can look up a DNS node
+ *          and use an DirObjectFactory to return an object from it.
+ *          Specify the all attributes to retrieve from the DNS node by using
+ *          the com.sun.jndi.dns.lookup.attr property.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @build TestDnsObject DirAFactory
+ * @run main/othervm LookupWithAnyAttrProp
+ */
+
+public class LookupWithAnyAttrProp extends LookupFactoryBase {
+
+    public static void main(String[] args) throws Exception {
+        new LookupWithAnyAttrProp().run(args);
+    }
+
+    /*
+     * Tests that we can look up a DNS node
+     * and use an DirObjectFactory to return an object from it.
+     * Specify the all attributes to retrieve from the DNS node by using
+     * the com.sun.jndi.dns.lookup.attr property.
+     */
+    @Override
+    public void runTest() throws Exception {
+        // initial context with object factory and lookup attr
+        env().put(Context.OBJECT_FACTORIES, "DirAFactory");
+        env().put(DNS_LOOKUP_ATTR, "*");
+        setContext(new InitialDirContext(env()));
+
+        Object obj = context().lookup(getKey());
+        verifyLookupObjectAndValue(obj, ATTRIBUTE_VALUE);
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAttrProp.dns b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAttrProp.dns
new file mode 100644
index 0000000..6de95c939f
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAttrProp.dns
@@ -0,0 +1,49 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for LookupWithAttrProp.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the LookupWithAttrProp application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: A4 14 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 01 00 01                                           ...
+
+
+# DNS Response
+
+0000: A4 14 85 80 00 01 00 01   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 01 00 01 C0 0C 00 01 00   01 00 01 51 80 00 04 01  ...........Q....
+0030: 02 04 01 C0 12 00 02 00   01 00 00 8C A0 00 05 02  ................
+0040: 6E 73 C0 12 C0 3F 00 01   00 01 00 00 8C A0 00 04  ns...?..........
+0050: 7F 00 00 01                                        ....
+
+
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAttrProp.java b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAttrProp.java
new file mode 100644
index 0000000..58868fc
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithAttrProp.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.directory.InitialDirContext;
+
+/*
+ * @test
+ * @bug 8208483
+ * @summary Tests that we can look up a DNS node
+ *          and use an DirObjectFactory to return an object from it.
+ *          Specify the "A" attribute to retrieve from the DNS node by using
+ *          the com.sun.jndi.dns.lookup.attr property.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @build TestDnsObject DirAFactory
+ * @run main/othervm LookupWithAttrProp
+ */
+
+public class LookupWithAttrProp extends LookupFactoryBase {
+
+    public static void main(String[] args) throws Exception {
+        new LookupWithAttrProp().run(args);
+    }
+
+    /*
+     * Tests that we can look up a DNS node
+     * and use an DirObjectFactory to return an object from it.
+     * Specify the "A" attribute to retrieve from the DNS node by using
+     * the com.sun.jndi.dns.lookup.attr property.
+     */
+    @Override
+    public void runTest() throws Exception {
+        // initial context with object factory and lookup attr
+        env().put(Context.OBJECT_FACTORIES, "DirAFactory");
+        env().put(DNS_LOOKUP_ATTR, "A");
+        setContext(new InitialDirContext(env()));
+
+        Object obj = context().lookup(getKey());
+        verifyLookupObjectAndValue(obj, ATTRIBUTE_VALUE);
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithDirFactory.dns b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithDirFactory.dns
new file mode 100644
index 0000000..548036f
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithDirFactory.dns
@@ -0,0 +1,50 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for LookupWithDirFactory.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the LookupWithDirFactory application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 12 78 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .x...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: 12 78 85 80 00 01 00 01   00 01 00 01 05 68 6F 73  .x...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithDirFactory.java b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithDirFactory.java
new file mode 100644
index 0000000..ec02827
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithDirFactory.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.directory.InitialDirContext;
+
+/*
+ * @test
+ * @bug 8208483
+ * @summary Tests that we can look up a DNS node that contains TXT records
+ *          and use an DirObjectFactory to return an object from it.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @build TestDnsObject DirTxtFactory
+ * @run main/othervm LookupWithDirFactory
+ */
+
+public class LookupWithDirFactory extends LookupFactoryBase {
+
+    public static void main(String[] args) throws Exception {
+        new LookupWithDirFactory().run(args);
+    }
+
+    /*
+     * Tests that we can look up a DNS node that contains TXT records
+     * and use an DirObjectFactory to return an object from it.
+     */
+    @Override
+    public void runTest() throws Exception {
+        // initial context with object factory
+        env().put(Context.OBJECT_FACTORIES, "DirTxtFactory");
+        setContext(new InitialDirContext(env()));
+
+        Object obj = context().lookup(getKey());
+        verifyLookupObject(obj);
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithFactory.dns b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithFactory.dns
new file mode 100644
index 0000000..0e074d1
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithFactory.dns
@@ -0,0 +1,76 @@
+#
+# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+################################################################################
+# Capture file for LookupWithFactory.java
+#
+# NOTE: This hexadecimal dump of DNS protocol messages was generated by
+#       running the LookupWithFactory application program against a real DNS
+#       server along with DNSTracer
+#
+################################################################################
+
+# DNS Request
+
+0000: 09 EA 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01                                           ...
+
+
+# DNS Response
+
+0000: 09 EA 85 80 00 01 00 01   00 01 00 01 05 68 6F 73  .............hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: 10 00 01 C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 12 00 02   00 01 00 00 8C A0 00 05  ost.............
+0050: 02 6E 73 C0 12 C0 50 00   01 00 01 00 00 8C A0 00  .ns...P.........
+0060: 04 7F 00 00 01                                     .....
+
+
+# DNS Request
+
+0000: 58 6C 01 00 00 01 00 00   00 00 00 00 05 68 6F 73  Xl...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF                                           ...
+
+
+# DNS Response
+
+0000: 58 6C 85 80 00 01 00 06   00 01 00 01 05 68 6F 73  Xl...........hos
+0010: 74 31 07 64 6F 6D 61 69   6E 31 03 63 6F 6D 00 00  t1.domain1.com..
+0020: FF 00 FF C0 0C 00 10 00   01 00 00 8C A0 00 15 14  ................
+0030: 41 20 76 65 72 79 20 70   6F 70 75 6C 61 72 20 68  A very popular h
+0040: 6F 73 74 2E C0 0C 00 1D   00 01 00 00 8C A0 00 10  ost.............
+0050: 00 12 16 13 88 97 1A 35   69 68 41 38 00 9B 16 58  .......5ihA8...X
+0060: C0 0C 00 0D 00 01 00 00   8C A0 00 13 0C 54 68 65  .............The
+0070: 20 4F 72 69 67 69 6E 61   6C 05 53 75 6E 6E 79 C0   Original.Sunny.
+0080: 0C 00 0F 00 01 00 00 8C   A0 00 11 00 0A 05 72 65  ..............re
+0090: 6C 61 79 04 6F 68 69 6F   02 75 73 00 C0 0C 00 0F  lay.ohio.us.....
+00A0: 00 01 00 00 8C A0 00 10   00 14 05 72 65 6C 61 79  ...........relay
+00B0: 05 74 65 78 61 73 C0 98   C0 0C 00 01 00 01 00 01  .texas..........
+00C0: 51 80 00 04 01 02 04 01   C0 12 00 02 00 01 00 00  Q...............
+00D0: 8C A0 00 05 02 6E 73 C0   12 C0 D4 00 01 00 01 00  .....ns.........
+00E0: 00 8C A0 00 04 7F 00 00   01                       .........
+
+
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithFactory.java b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithFactory.java
new file mode 100644
index 0000000..305d52c
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/LookupWithFactory.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.directory.InitialDirContext;
+
+/*
+ * @test
+ * @bug 8208483
+ * @summary Tests that we can look up a DNS node that contains TXT records
+ *          and use an ObjectFactory to return an object from it.
+ *          Since an ObjectFactory doesn't have access to attributes, the
+ *          factory must looking the attributes.
+ * @library ../lib/
+ * @modules java.base/sun.security.util
+ * @build TestDnsObject TxtFactory
+ * @run main/othervm LookupWithFactory
+ */
+
+public class LookupWithFactory extends LookupFactoryBase {
+
+    public static void main(String[] args) throws Exception {
+        new LookupWithFactory().run(args);
+    }
+
+    /*
+     * Tests that we can look up a DNS node that contains TXT records
+     * and use an ObjectFactory to return an object from it.
+     * Since an ObjectFactory doesn't have access to attributes, the
+     * factory must looking the attributes.
+     */
+    @Override
+    public void runTest() throws Exception {
+        // initial context with object factory
+        env().put(Context.OBJECT_FACTORIES, "TxtFactory");
+        setContext(new InitialDirContext(env()));
+
+        Object obj = context().lookup(getKey());
+        verifyLookupObject(obj);
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/TestDnsObject.java b/test/jdk/com/sun/jndi/dns/FactoryTests/TestDnsObject.java
new file mode 100644
index 0000000..c6212f5
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/TestDnsObject.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+
+public class TestDnsObject {
+    private String value;
+
+    public TestDnsObject(Attribute attr) {
+        StringBuilder buf = new StringBuilder();
+        try {
+            NamingEnumeration enumObj = attr.getAll();
+            while (enumObj.hasMore()) {
+                buf.append(enumObj.next());
+            }
+        } catch (NamingException e) {
+            // debug
+            e.printStackTrace();
+        }
+
+        value = buf.toString();
+    }
+
+    public String toString() {
+        return value;
+    }
+}
diff --git a/test/jdk/com/sun/jndi/dns/FactoryTests/TxtFactory.java b/test/jdk/com/sun/jndi/dns/FactoryTests/TxtFactory.java
new file mode 100644
index 0000000..832fdf9
--- /dev/null
+++ b/test/jdk/com/sun/jndi/dns/FactoryTests/TxtFactory.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import javax.naming.Context;
+import javax.naming.Name;
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+
+public class TxtFactory implements ObjectFactory {
+    @Override
+    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
+            Hashtable<?, ?> environment) {
+        System.out.println(
+                this.getClass().getName() + ".getObjectInstance(): " + name);
+
+        // alternatively, could use ctx/name pair
+
+        if (obj instanceof DirContext) {
+            DirContext thisCtx = (DirContext) obj;
+            try {
+                Attributes attrs = thisCtx.getAttributes("");
+                Attribute txt = attrs.get("TXT");
+                if (txt != null) {
+                    return new TestDnsObject(txt);
+                }
+            } catch (NamingException e) {
+                // debug
+                e.printStackTrace();
+            }
+        }
+
+        // return null to indicate other factories should be tried
+        return null;
+    }
+}