You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2006/02/24 22:18:16 UTC
svn commit: r380818 -
/xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
Author: mullan
Date: Fri Feb 24 13:18:13 2006
New Revision: 380818
URL: http://svn.apache.org/viewcvs?rev=380818&view=rev
Log:
Add new unit test for KeyInfo.marshal.
Modified:
xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
Modified: xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
URL: http://svn.apache.org/viewcvs/xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java?rev=380818&r1=380817&r2=380818&view=diff
==============================================================================
--- xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java (original)
+++ xml/security/trunk/src_unitTests/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java Fri Feb 24 13:18:13 2006
@@ -24,7 +24,11 @@
import javax.xml.crypto.dsig.*;
import javax.xml.crypto.dom.*;
import javax.xml.crypto.dsig.keyinfo.*;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.jcp.xml.dsig.internal.dom.DOMUtils;
import junit.framework.*;
/**
@@ -109,5 +113,35 @@
} catch (NullPointerException npe) {}
assertTrue(!ki.isFeatureSupported("not supported"));
+ }
+
+ public void testMarshal() throws Exception {
+ KeyInfo ki = fac.newKeyInfo
+ (Collections.singletonList(fac.newKeyName("foo")), "keyid");
+ try {
+ ki.marshal(null, null);
+ fail("Should raise a NullPointerException");
+ } catch (NullPointerException npe) {}
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ Document doc = dbf.newDocumentBuilder().newDocument();
+ Element elem = doc.createElementNS("http://acme.org", "parent");
+ doc.appendChild(elem);
+ DOMStructure parent = new DOMStructure(elem);
+ try {
+ ki.marshal(parent, null);
+ } catch (Exception e) {
+ fail("Should not throw an exception: " + e);
+ }
+
+ Element kiElem = DOMUtils.getFirstChildElement(elem);
+ if (!kiElem.getLocalName().equals("KeyInfo")) {
+ fail("Should be KeyInfo element: " + kiElem.getLocalName());
+ }
+ Element knElem = DOMUtils.getFirstChildElement(kiElem);
+ if (!knElem.getLocalName().equals("KeyName")) {
+ fail("Should be KeyName element: " + knElem.getLocalName());
+ }
}
}