Path: blob/master/test/jdk/javax/naming/ldap/LdapName/LdapNameConstruction.java
41153 views
/*1* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 463561826* @summary Support for manipulating LDAP Names27*/2829import javax.naming.ldap.*;30import java.util.ArrayList;31import java.util.List;32import javax.naming.InvalidNameException;33import javax.naming.directory.*;3435/**36* These tests are for checking the LdapName and Rdn37* constructors.38*/39public class LdapNameConstruction {4041public static void main(String args[])42throws Exception {43/**44* Four ways of constructing the same Rdn45*/46Rdn rdn1 = new Rdn("ou= Juicy\\, Fruit");47System.out.println("rdn1:" + rdn1.toString());4849Rdn rdn2 = new Rdn(rdn1);50System.out.println("rdn2:" + rdn2.toString());5152Attributes attrs = new BasicAttributes();53attrs.put("ou", "Juicy, Fruit");54attrs.put("cn", "Mango");55Rdn rdn3 = new Rdn(attrs);56System.out.println("rdn3:" + rdn3.toString());5758Rdn rdn4 = new Rdn("ou", "Juicy, Fruit");59System.out.println("rdn4:" + rdn4.toString());6061// Rdn with unicode value62Rdn rdn5 = new Rdn("SN=Lu\\C4\\8Di\\C4\\87");63System.out.println("rdn5:" + rdn5.toString());6465/**66* LdapName creation tests67*/68List<Rdn> rdns = new ArrayList<>();69rdns.add(new Rdn("o=Food"));70rdns.add(new Rdn("ou=Fruits"));71rdns.add(rdn3);72LdapName name1 = new LdapName(rdns);73System.out.println("ldapname1:" + name1.toString());7475LdapName name2 = new LdapName(76"ou=Juicy\\, Fruit + cn = Mango, ou=Fruits, o=Food");77System.out.println("ldapName2:" + name2.toString());7879if (!name2.equals(name1)) {80throw new Exception("ldapname1 does not equals ldapname2");81}82System.out.println("ldapname1 and ldapname2 are equal");8384LdapName name = new LdapName(new ArrayList<>());85System.out.println("Empty ldapname:" + name);86}87}888990