Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/crypto/dsig/keyinfo/KeyInfo/Marshal.java
38886 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* @compile -XDignore.symbol.file Marshal.java28* @run main Marshal29* @author Sean Mullan30*/3132import java.util.Collections;33import javax.xml.parsers.DocumentBuilderFactory;34import javax.xml.crypto.dom.DOMStructure;35import javax.xml.crypto.dsig.keyinfo.KeyInfo;36import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;37import org.w3c.dom.Document;38import org.w3c.dom.Element;39import org.jcp.xml.dsig.internal.dom.DOMUtils;4041public class Marshal {4243public static void main(String[] args) throws Exception {44KeyInfoFactory fac = KeyInfoFactory.getInstance();45KeyInfo ki = fac.newKeyInfo46(Collections.singletonList(fac.newKeyName("foo")), "keyid");47try {48ki.marshal(null, null);49throw new Exception("Should raise a NullPointerException");50} catch (NullPointerException npe) {}5152DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();53dbf.setNamespaceAware(true);54Document doc = dbf.newDocumentBuilder().newDocument();55Element elem = doc.createElementNS("http://acme.org", "parent");56doc.appendChild(elem);57DOMStructure parent = new DOMStructure(elem);58ki.marshal(parent, null);5960Element kiElem = DOMUtils.getFirstChildElement(elem);61if (!kiElem.getLocalName().equals("KeyInfo")) {62throw new Exception63("Should be KeyInfo element: " + kiElem.getLocalName());64}65Element knElem = DOMUtils.getFirstChildElement(kiElem);66if (!knElem.getLocalName().equals("KeyName")) {67throw new Exception68("Should be KeyName element: " + knElem.getLocalName());69}70}71}727374