1 /* 2 * Copyright (c) 2003, 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 /* 25 * @test 26 * @bug 4635618 27 * @summary Support for manipulating LDAP Names 28 */ 29 30 import javax.naming.ldap.*; 31 import java.util.ArrayList; 32 import java.util.List; 33 import javax.naming.InvalidNameException; 34 import javax.naming.directory.*; 35 36 /** 37 * These tests are for checking the LdapName and Rdn 38 * constructors. 39 */ 40 public class LdapNameConstruction { 41 42 public static void main(String args[]) 43 throws Exception { 44 /** 45 * Four ways of constructing the same Rdn 46 */ 47 Rdn rdn1 = new Rdn("ou= Juicy\\, Fruit"); 48 System.out.println("rdn1:" + rdn1.toString()); 49 50 Rdn rdn2 = new Rdn(rdn1); 51 System.out.println("rdn2:" + rdn2.toString()); 52 53 Attributes attrs = new BasicAttributes(); 54 attrs.put("ou", "Juicy, Fruit"); 55 attrs.put("cn", "Mango"); 56 Rdn rdn3 = new Rdn(attrs); 57 System.out.println("rdn3:" + rdn3.toString()); 58 59 Rdn rdn4 = new Rdn("ou", "Juicy, Fruit"); 60 System.out.println("rdn4:" + rdn4.toString()); 61 62 // Rdn with unicode value 63 Rdn rdn5 = new Rdn("SN=Lu\\C4\\8Di\\C4\\87"); 64 System.out.println("rdn5:" + rdn5.toString()); 65 66 /** 67 * LdapName creation tests 68 */ 69 List rdns = new ArrayList(); 70 rdns.add(new Rdn("o=Food")); 71 rdns.add(new Rdn("ou=Fruits")); 72 rdns.add(rdn3); 73 LdapName name1 = new LdapName(rdns); 74 System.out.println("ldapname1:" + name1.toString()); 75 76 LdapName name2 = new LdapName( 77 "ou=Juicy\\, Fruit + cn = Mango, ou=Fruits, o=Food"); 78 System.out.println("ldapName2:" + name2.toString()); 79 80 if (!name2.equals(name1)) { 81 throw new Exception("ldapname1 does not equals ldapname2"); 82 } 83 System.out.println("ldapname1 and ldapname2 are equal"); 84 85 LdapName name = new LdapName(new ArrayList()); 86 System.out.println("Empty ldapname:" + name); 87 } 88 }