1 /*
   2  * Copyright (c) 2000, 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.Attribute;
  27 import javax.naming.directory.Attributes;
  28 import javax.naming.directory.InitialDirContext;
  29 
  30 /*
  31  * @test
  32  * @bug 8210339
  33  * @summary Tests that we can get the attributes of the interior node
  34  *          in the subordinate naming system of a DNS entry.
  35  *          Use getAttributes form that has no attrIds parameter.
  36  * @library ../lib/ ../AttributeTests/
  37  * @modules java.naming/com.sun.jndi.toolkit.dir
  38  *          java.base/sun.security.util
  39  * @build FedSubordinateNs FedObjectFactory
  40  * @run main/othervm GetAttrsSubInterior
  41  */
  42 
  43 public class GetAttrsSubInterior extends GetAttrsBase {
  44 
  45     // pre defined attribute value for '/a/b'
  46     public static final String ATTRIBUTE_VALUE = "b";
  47 
  48     public GetAttrsSubInterior() {
  49         setMandatoryAttrs("name", "description");
  50     }
  51 
  52     public static void main(String[] args) throws Exception {
  53         new GetAttrsSubInterior().run(args);
  54     }
  55 
  56     /*
  57      * Tests that we can get the attributes of the interior node
  58      * in the subordinate naming system of a DNS entry.
  59      */
  60     @Override
  61     public void runTest() throws Exception {
  62         env().put(Context.OBJECT_FACTORIES, "FedObjectFactory");
  63         setContext(new InitialDirContext(env()));
  64 
  65         Attributes retAttrs = getAttributes();
  66         Attribute attr = retAttrs.get("name");
  67         verifyAttributes(retAttrs);
  68         verifyAttribute(attr);
  69     }
  70 
  71     /*
  72      * Use getAttributes form that has no attrIds parameter.
  73      */
  74     @Override
  75     public Attributes getAttributes() throws NamingException {
  76         return context().getAttributes(getKey() + "/a/b");
  77     }
  78 
  79     private void verifyAttribute(Attribute attr) throws NamingException {
  80         if (attr == null || !ATTRIBUTE_VALUE.equals(attr.get())) {
  81             throw new RuntimeException(
  82                     "Expecting attribute value: " + ATTRIBUTE_VALUE
  83                             + ", but actual: " + (attr != null ?
  84                             attr.get() :
  85                             attr));
  86         }
  87     }
  88 }