Path: blob/master/test/jdk/javax/xml/crypto/dsig/GetInstanceTests.java
41152 views
/*1* Copyright (c) 2016, 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 815948826* @summary Basic tests for the various getInstance() methods of27* XMLSignatureFactory, TransformService, and KeyInfoFactory classes28* @run main GetInstanceTests29*/30import java.security.*;31import javax.xml.crypto.dsig.*;32import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;333435public class GetInstanceTests {3637public static void main(String[] argv) throws Exception {38TestTransformService(CanonicalizationMethod.INCLUSIVE, "DOM");39TestTransformService(CanonicalizationMethod.EXCLUSIVE_WITH_COMMENTS, "DOM");40TestTransformService(Transform.BASE64, "DOM");41TestTransformService(Transform.XPATH2, "DOM");42TestXMLSignatureFactory();43TestKeyInfoFactory();44}4546private static void TestTransformService(String algo,47String mechType) throws Exception {48TransformService ts = TransformService.getInstance(algo, mechType);49Provider p = ts.getProvider();50try {51ts = TransformService.getInstance(algo, mechType, p);52ts = TransformService.getInstance(algo, mechType, p.getName());53} catch (Exception ex) {54throw new RuntimeException("Error: Unexpected exception", ex);55}56}5758private static void TestXMLSignatureFactory() throws Exception {59XMLSignatureFactory fac = XMLSignatureFactory.getInstance();60Provider p = fac.getProvider();61String mechType = fac.getMechanismType();62Provider p2;63try {64fac = XMLSignatureFactory.getInstance(mechType);65p2 = fac.getProvider();66fac = XMLSignatureFactory.getInstance(mechType, p);67fac = XMLSignatureFactory.getInstance(mechType, p.getName());68} catch (Exception ex) {69throw new RuntimeException("Error: Unexpected exception", ex);70}71if (p2.getName() != p.getName()) {72throw new RuntimeException("Error: Provider equality check failed");73}74if (p2.getName() != p.getName()) {75throw new RuntimeException("Error: Provider equality check failed");76}77}7879private static void TestKeyInfoFactory() throws Exception {80KeyInfoFactory fac = KeyInfoFactory.getInstance();81Provider p = fac.getProvider();82String mechType = fac.getMechanismType();83Provider p2;84try {85fac = KeyInfoFactory.getInstance(mechType);86p2 = fac.getProvider();87fac = KeyInfoFactory.getInstance(mechType, p);88fac = KeyInfoFactory.getInstance(mechType, p.getName());89} catch (Exception ex) {90throw new RuntimeException("Error: Unexpected exception", ex);91}92if (p2.getName() != p.getName()) {93throw new RuntimeException("Error: Provider equality check failed");94}95}96}979899