J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 21 | * have any 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 javax.naming.InvalidNameException; |
| 32 | import java.util.*; |
| 33 | import javax.naming.directory.*; |
| 34 | import java.io.*; |
| 35 | |
| 36 | /** |
| 37 | * Miscelleneous tests of Rdn methods and serialization test |
| 38 | */ |
| 39 | public class RdnMisc { |
| 40 | |
| 41 | public static void main(String args[]) |
| 42 | throws Exception { |
| 43 | Attributes attrs = new BasicAttributes(); |
| 44 | attrs.put("a", "Mango"); |
| 45 | attrs.put("l", "Yellow<right"); |
| 46 | attrs.put("b", "Juicy, Fruit"); |
| 47 | attrs.put("k", "Orange>ripe"); |
| 48 | attrs.put("c", "Favourite+Fruit"); |
| 49 | attrs.put("j", "Green#raw"); |
| 50 | attrs.put("d", "Tropical\\Fruit"); |
| 51 | attrs.put("i", "Alfanso;expensive"); |
| 52 | attrs.put("e", "Seasonal\"Fruit"); |
| 53 | attrs.put("h", "Summer"); |
| 54 | attrs.put("f", "Smell=Great"); |
| 55 | attrs.put("g", "Taste==Yummy"); |
| 56 | |
| 57 | byte[] mangoJuice = new byte[6]; |
| 58 | for (int i = 0; i < mangoJuice.length; i++) { |
| 59 | mangoJuice[i] = (byte) i; |
| 60 | } |
| 61 | attrs.put("m", mangoJuice); |
| 62 | Rdn rdn = new Rdn(attrs); |
| 63 | |
| 64 | System.out.println(); |
| 65 | System.out.println("size:" + rdn.size()); |
| 66 | System.out.println("toString():" + rdn.toString()); |
| 67 | System.out.println("getType(): " + rdn.getType()); |
| 68 | System.out.println("getValue(): " + rdn.getValue()); |
| 69 | |
| 70 | // test toAttributes |
| 71 | System.out.println(); |
| 72 | System.out.println("toAttributes(): " + rdn.toAttributes()); |
| 73 | |
| 74 | // serialization test |
| 75 | Rdn rdn2 = new Rdn("cn=Juicy\\, Fruit"); |
| 76 | System.out.println("Serializing rdn:" + rdn2); |
| 77 | ObjectOutputStream out = new ObjectOutputStream( |
| 78 | new FileOutputStream("rdn.ser")); |
| 79 | out.writeObject(rdn2); |
| 80 | out.close(); |
| 81 | |
| 82 | ObjectInputStream in = new ObjectInputStream( |
| 83 | new FileInputStream("rdn.ser")); |
| 84 | |
| 85 | System.out.println(); |
| 86 | System.out.println("Deserialized RDN:" + in.readObject()); |
| 87 | in.close(); |
| 88 | } |
| 89 | } |