Path: blob/master/test/jdk/javax/naming/ldap/LdapName/RdnMisc.java
41153 views
/*1* Copyright (c) 2003, 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 javax.naming.InvalidNameException;31import java.util.*;32import javax.naming.directory.*;33import java.io.*;3435/**36* Miscelleneous tests of Rdn methods and serialization test37*/38public class RdnMisc {3940public static void main(String args[])41throws Exception {42Attributes attrs = new BasicAttributes();43attrs.put("a", "Mango");44attrs.put("l", "Yellow<right");45attrs.put("b", "Juicy, Fruit");46attrs.put("k", "Orange>ripe");47attrs.put("c", "Favourite+Fruit");48attrs.put("j", "Green#raw");49attrs.put("d", "Tropical\\Fruit");50attrs.put("i", "Alfanso;expensive");51attrs.put("e", "Seasonal\"Fruit");52attrs.put("h", "Summer");53attrs.put("f", "Smell=Great");54attrs.put("g", "Taste==Yummy");5556byte[] mangoJuice = new byte[6];57for (int i = 0; i < mangoJuice.length; i++) {58mangoJuice[i] = (byte) i;59}60attrs.put("m", mangoJuice);61Rdn rdn = new Rdn(attrs);6263System.out.println();64System.out.println("size:" + rdn.size());65System.out.println("toString():" + rdn.toString());66System.out.println("getType(): " + rdn.getType());67System.out.println("getValue(): " + rdn.getValue());6869// test toAttributes70System.out.println();71System.out.println("toAttributes(): " + rdn.toAttributes());7273// serialization test74Rdn rdn2 = new Rdn("cn=Juicy\\, Fruit");75System.out.println("Serializing rdn:" + rdn2);76ObjectOutputStream out = new ObjectOutputStream(77new FileOutputStream("rdn.ser"));78out.writeObject(rdn2);79out.close();8081ObjectInputStream in = new ObjectInputStream(82new FileInputStream("rdn.ser"));8384System.out.println();85System.out.println("Deserialized RDN:" + in.readObject());86in.close();87}88}899091