Path: blob/master/test/jdk/javax/security/auth/x500/X500Principal/Parse.java
41155 views
/*1* Copyright (c) 2011, 2012, 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 7024771 702460426* @summary various X500Principal DN parsing tests27*/2829import javax.security.auth.x500.X500Principal;3031public class Parse {3233private static TestCase[] testCases = {34new TestCase("CN=prefix\\<>suffix", false),35new TestCase("OID.1=value", false),36new TestCase("oid.1=value", false),37new TestCase("OID.1.2=value", true),38new TestCase("oid.1.2=value", true),39new TestCase("1=value", false),40new TestCase("1.2=value", true)41};4243public static void main(String args[]) throws Exception {44for (TestCase testCase : testCases) {45testCase.run();46}47System.out.println("Test completed ok.");48}49}5051class TestCase {5253private String name;54private boolean expectedResult;5556TestCase(String name, boolean expectedResult) {57this.name = name;58this.expectedResult = expectedResult;59}6061void run() throws Exception {62Exception f = null;63try {64System.out.println("Parsing: \"" + name + "\"");65new X500Principal(name);66if (expectedResult == false) {67f = new Exception("Successfully parsed invalid name");68}69} catch (IllegalArgumentException e) {70if (expectedResult == true) {71throw e;72}73}74if (f != null) {75throw f;76}77}78}798081