Path: blob/master/test/jdk/java/security/cert/URICertStoreParameters/TestBasic.java
41153 views
/*1* Copyright (c) 2015, 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*/2223import java.security.cert.CertStore;24import java.security.cert.URICertStoreParameters;25import java.net.URI;2627/*28* @test29* @bug 803808430* @summary Basic testing for URICertStoreParameters31* @run main TestBasic32*/33public class TestBasic {3435public static void main(String[] args) throws Exception {36String str1 = "ldap://myownhost:5000/";37String str2 = "ldap://myownhost:5000/cn=foo";38test(str1, str2);39System.out.println("Test passed");40}4142private static void test(String str1, String str2) throws Exception {43System.out.println("Testing clone");44URICertStoreParameters p1 = new URICertStoreParameters(new URI(str1));45URICertStoreParameters p1Too = p1.clone();46if (!(p1.getURI().equals(p1Too.getURI())) ||47!(p1.equals(p1Too))) {48throw new Exception("Error: problem with clone");49}50System.out.println("Testing equal and hashCode");51p1Too = new URICertStoreParameters(new URI(str1));52URICertStoreParameters p2 = new URICertStoreParameters(new URI(str2));5354if (p1.equals(null)) {55throw new Exception("Error: p1 should NOT equal null");56}57if ((!p1.equals(p1)) || (p1.hashCode() != p1.hashCode())) {58throw new Exception("Error: p1 should equal p1");59}60if ((!p1.equals(p1Too)) || (p1.hashCode() != p1Too.hashCode())) {61throw new Exception("Error: p1 should equal p1Too");62}63if ((!p1Too.equals(p1)) || (p1Too.hashCode() != p1.hashCode())) {64throw new Exception("Error: p1Too should equal p1");65}66if (p1.equals(p2) || p1Too.equals(p2)) {67throw new Exception("Error: p1/p1Too should NOT equal p2");68}69}70}717273