< prev index next >

test/jdk/javax/naming/ldap/LdapName/CompareToEqualsTests.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2011, 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  */


  57                 "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob",
  58                 "ou=Sales+cn=Scott+c=US", "cn=config"};
  59 
  60             String names2[] = new String [] {
  61                 "ou=Sales+cn=Bob", "cn=Bob+ou=Sales", "ou=Sales+cn=Scott",
  62                 "ou=Sales+cn=Scott", "Cn=COnFIG"};
  63 
  64             int expectedResults[] = {0, 0, -1, -1, 0};
  65 
  66             for (Locale locale : Locale.getAvailableLocales()) {
  67                 // reset the default locale
  68                 Locale.setDefault(locale);
  69 
  70                 for (int i = 0; i < names1.length; i++) {
  71                     checkResults(new LdapName(names1[i]),
  72                         new LdapName(names2[i]), expectedResults[i]);
  73                 }
  74 
  75                 byte[] value = "abcxyz".getBytes();
  76                 Rdn rdn1 = new Rdn("binary", value);
  77                 ArrayList rdns1 = new ArrayList();
  78                 rdns1.add(rdn1);
  79                 LdapName l1 = new LdapName(rdns1);
  80 
  81                 Rdn rdn2 = new Rdn("binary", value);
  82                 ArrayList rdns2 = new ArrayList();
  83                 rdns2.add(rdn2);
  84                 LdapName l2 = new LdapName(rdns2);
  85                 checkResults(l1, l2, 0);
  86 
  87                 l2 = new LdapName("binary=#61626378797A");
  88                 checkResults(l1, l2, 0);
  89 
  90                 l2 = new LdapName("binary=#61626378797B");
  91                 checkResults(l1, l2, -1);
  92 
  93                 System.out.println("Tests passed");
  94             }
  95         } finally {
  96             // restore the reserved locale
  97             Locale.setDefault(reservedLocale);
  98         }
  99     }
 100 
 101 
 102     static void checkResults(LdapName name1, LdapName name2, int expectedResult)


   1 /*
   2  * Copyright (c) 2003, 2020, 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  */


  57                 "ou=Sales+cn=Bob", "ou=Sales+cn=Bob", "ou=Sales+cn=Bob",
  58                 "ou=Sales+cn=Scott+c=US", "cn=config"};
  59 
  60             String names2[] = new String [] {
  61                 "ou=Sales+cn=Bob", "cn=Bob+ou=Sales", "ou=Sales+cn=Scott",
  62                 "ou=Sales+cn=Scott", "Cn=COnFIG"};
  63 
  64             int expectedResults[] = {0, 0, -1, -1, 0};
  65 
  66             for (Locale locale : Locale.getAvailableLocales()) {
  67                 // reset the default locale
  68                 Locale.setDefault(locale);
  69 
  70                 for (int i = 0; i < names1.length; i++) {
  71                     checkResults(new LdapName(names1[i]),
  72                         new LdapName(names2[i]), expectedResults[i]);
  73                 }
  74 
  75                 byte[] value = "abcxyz".getBytes();
  76                 Rdn rdn1 = new Rdn("binary", value);
  77                 ArrayList<Rdn> rdns1 = new ArrayList<>();
  78                 rdns1.add(rdn1);
  79                 LdapName l1 = new LdapName(rdns1);
  80 
  81                 Rdn rdn2 = new Rdn("binary", value);
  82                 ArrayList<Rdn> rdns2 = new ArrayList<>();
  83                 rdns2.add(rdn2);
  84                 LdapName l2 = new LdapName(rdns2);
  85                 checkResults(l1, l2, 0);
  86 
  87                 l2 = new LdapName("binary=#61626378797A");
  88                 checkResults(l1, l2, 0);
  89 
  90                 l2 = new LdapName("binary=#61626378797B");
  91                 checkResults(l1, l2, -1);
  92 
  93                 System.out.println("Tests passed");
  94             }
  95         } finally {
  96             // restore the reserved locale
  97             Locale.setDefault(reservedLocale);
  98         }
  99     }
 100 
 101 
 102     static void checkResults(LdapName name1, LdapName name2, int expectedResult)


< prev index next >