Path: blob/master/test/jdk/javax/xml/crypto/dsig/keyinfo/KeyInfo/Marshal.java
41161 views
/*1* Copyright (c) 2006, 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 637250026* @summary Test that KeyInfo.marshal works correctly27* @modules java.xml.crypto/org.jcp.xml.dsig.internal.dom28* @compile -XDignore.symbol.file Marshal.java29* @run main/othervm/java.security.policy==test.policy Marshal30* @author Sean Mullan31*/3233import java.util.Collections;34import javax.xml.parsers.DocumentBuilderFactory;35import javax.xml.crypto.dom.DOMStructure;36import javax.xml.crypto.dsig.keyinfo.KeyInfo;37import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;38import org.w3c.dom.Document;39import org.w3c.dom.Element;40import org.jcp.xml.dsig.internal.dom.DOMUtils;4142public class Marshal {4344public static void main(String[] args) throws Exception {45KeyInfoFactory fac = KeyInfoFactory.getInstance();46KeyInfo ki = fac.newKeyInfo47(Collections.singletonList(fac.newKeyName("foo")), "keyid");48try {49ki.marshal(null, null);50throw new Exception("Should raise a NullPointerException");51} catch (NullPointerException npe) {}5253DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();54dbf.setNamespaceAware(true);55Document doc = dbf.newDocumentBuilder().newDocument();56Element elem = doc.createElementNS("http://acme.org", "parent");57doc.appendChild(elem);58DOMStructure parent = new DOMStructure(elem);59ki.marshal(parent, null);6061Element kiElem = DOMUtils.getFirstChildElement(elem);62if (!kiElem.getLocalName().equals("KeyInfo")) {63throw new Exception64("Should be KeyInfo element: " + kiElem.getLocalName());65}66Element knElem = DOMUtils.getFirstChildElement(kiElem);67if (!knElem.getLocalName().equals("KeyName")) {68throw new Exception69("Should be KeyName element: " + knElem.getLocalName());70}71}72}737475