test/jdk/javax/naming/ldap/LdapName/NameTests.java
author rbackman
Thu, 18 Jan 2018 19:21:11 +0100
changeset 48809 a81c930a8838
parent 47216 71c04702a3d5
permissions -rw-r--r--
8191915: JCK tests produce incorrect results with C2 Reviewed-by: thartmann, vlivanov, goetz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4635618
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Support for manipulating LDAP Names
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.ldap.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * LdapName tests- These tests are for testing the methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * javax.naming.Name interface as it applied to LdapName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class NameTests {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        String[] rdnStr = new String[] {"one=voilet"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        ArrayList rdnList = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        for (int i = 0; i < rdnStr.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
            rdnList.add(i, new Rdn(rdnStr[i]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        LdapName dn = new LdapName(rdnList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        Collection rdns = dn.getRdns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        System.out.println("size is :" + dn.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        System.out.println("isEmpty :" + dn.isEmpty());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        System.out.println("************Printing as Rdns*********");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        Iterator iter = rdns.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            System.out.println(iter.next());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.out.println("************Printing the Enumeration*********");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Enumeration dnEnum = dn.getAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        while (dnEnum.hasMoreElements()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            System.out.println(dnEnum.nextElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        // addAll tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        LdapName nameSuffix = new LdapName("two=Indigo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        System.out.println("addAll():" + dn.addAll(nameSuffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        ArrayList list = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        list.add(new Rdn("five=Yellow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        System.out.println("Rdn- addAll():" + dn.addAll(list));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        nameSuffix = new LdapName("three=Blue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        System.out.println("addAll at pos = 2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        System.out.println("addAll():" + dn.addAll(2, nameSuffix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        list = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        list.add(new Rdn("four=Green"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        System.out.println("addAll at pos = 3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        System.out.println("Rdn- addAll():" + dn.addAll(3, list));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // add() tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        Rdn rdn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        System.out.println("add():" + dn.add("eight=white"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        rdn = new Rdn("nine=Black");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        System.out.println("Rdn- add():" + dn.add(rdn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Rdn nullRdn = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        System.out.println("Rdn- add() with null RDN:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                        dn.add(nullRdn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        System.out.println("add() at pos 5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        System.out.println("add():" + dn.add(5, "six=Orange"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        rdn = new Rdn("six=Orange");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        System.out.println("add() at pos 6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        System.out.println("Rdn- add():" + dn.add(6, "seven=Red"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        // remove tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        System.out.println("Removing entries at positions: 7, 8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        System.out.println("Removed:" + dn.remove(8));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        System.out.println("Removed:" + dn.remove(7));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // get tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        System.out.println("toString():" + dn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int size  = dn.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        System.out.println("get(0):" + dn.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        System.out.println("get(size() - 1):" + dn.get(size - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        System.out.println("getRdn(0):" + dn.getRdn(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        System.out.println("getRdn(size() - 1):" + dn.getRdn(size - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        System.out.println("********Prefixes**********");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        System.out.println("getPrefix(0):" + dn.getPrefix(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        System.out.println("getPrefix(size / 2):" + dn.getPrefix(size / 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        System.out.println("getPrefix(size):" + dn.getPrefix(size));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        System.out.println("********Suffixes**********");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        System.out.println("getSuffix(0):" + dn.getSuffix(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        System.out.println("getSuffix(size/2):" + dn.getSuffix(size / 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        System.out.println("getSuffix(size):" + dn.getSuffix(size));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        System.out.println("startsWith(" + rdnStr[0] + "):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                dn.startsWith(new LdapName(rdnStr[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        String lastEntry = "seven=red";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        System.out.println("startsWith(" + lastEntry + "):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                dn.startsWith(new LdapName(lastEntry)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        System.out.println("compositeName- startsWith(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                        rdnStr[0] + "): " + dn.startsWith(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                                        new CompositeName(rdnStr[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        java.util.List prefixList = (dn.getRdns()).subList(0, size /2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        System.out.println("Rdn - startsWith(" + prefixList + "):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                dn.startsWith(prefixList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        System.out.println("Rdn - startsWith() - empty RDN list:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                                dn.startsWith(new ArrayList()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        System.out.println("endsWith(" + rdnStr[0] + "):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                dn.endsWith(new LdapName(rdnStr[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        System.out.println("endsWith(" + lastEntry + "):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                dn.endsWith(new LdapName(lastEntry)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        System.out.println("compositeName- endsWith(" + rdnStr[0] + "):    " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                dn.endsWith(new CompositeName(rdnStr[0])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        System.out.println("Rdn - endsWith(" + prefixList + "):" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                                dn.endsWith(prefixList));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        System.out.println("Rdn - endsWith() empty RDN list:" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                                dn.endsWith(new ArrayList()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        // test clone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        System.out.println("cloned name:" + dn.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        // test serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        ObjectOutputStream out = new ObjectOutputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                    new FileOutputStream("dn.ser"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        out.writeObject(dn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        ObjectInputStream in = new ObjectInputStream(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                    new FileInputStream("dn.ser"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        System.out.println("Deserialized name:" + in.readObject());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
}