You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/01/07 12:23:13 UTC
svn commit: r1056263 [5/10] - in /santuario/xml-security-java/trunk: ./
src/test/java/javax/xml/crypto/test/
src/test/java/javax/xml/crypto/test/dsig/
src/test/java/javax/xml/crypto/test/dsig/dom/
src/test/java/javax/xml/crypto/test/dsig/keyinfo/ src/t...
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/X509KeySelector.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/X509KeySelector.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/X509KeySelector.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/X509KeySelector.java Fri Jan 7 11:23:09 2011
@@ -71,15 +71,15 @@ public class X509KeySelector extends Key
* <code>null</code>
*/
public X509KeySelector(KeyStore keyStore) throws KeyStoreException {
- this(keyStore, true);
+ this(keyStore, true);
}
public X509KeySelector(KeyStore keyStore, boolean trusted)
- throws KeyStoreException {
+ throws KeyStoreException {
if (keyStore == null) {
throw new NullPointerException("keyStore is null");
}
- this.trusted = trusted;
+ this.trusted = trusted;
this.ks = keyStore;
// test to see if KeyStore has been initialized
this.ks.size();
@@ -127,8 +127,8 @@ public class X509KeySelector extends Key
* is not supported by this key selector
*/
public KeySelectorResult select(KeyInfo keyInfo,
- KeySelector.Purpose purpose, AlgorithmMethod method,
- XMLCryptoContext context) throws KeySelectorException {
+ KeySelector.Purpose purpose, AlgorithmMethod method,
+ XMLCryptoContext context) throws KeySelectorException {
SignatureMethod sm = (SignatureMethod) method;
@@ -142,50 +142,50 @@ public class X509KeySelector extends Key
Iterator i = keyInfo.getContent().iterator();
while (i.hasNext()) {
XMLStructure kiType = (XMLStructure) i.next();
- // check X509Data
+ // check X509Data
if (kiType instanceof X509Data) {
X509Data xd = (X509Data) kiType;
- KeySelectorResult ksr = x509DataSelect(xd, sm);
- if (ksr != null) {
- return ksr;
- }
- // check KeyName
+ KeySelectorResult ksr = x509DataSelect(xd, sm);
+ if (ksr != null) {
+ return ksr;
+ }
+ // check KeyName
} else if (kiType instanceof KeyName) {
- KeyName kn = (KeyName) kiType;
- Certificate cert = ks.getCertificate(kn.getName());
- if (cert != null && algEquals(sm.getAlgorithm(),
- cert.getPublicKey().getAlgorithm())) {
- return new SimpleKeySelectorResult(cert.getPublicKey());
- }
- // check RetrievalMethod
+ KeyName kn = (KeyName) kiType;
+ Certificate cert = ks.getCertificate(kn.getName());
+ if (cert != null && algEquals(sm.getAlgorithm(),
+ cert.getPublicKey().getAlgorithm())) {
+ return new SimpleKeySelectorResult(cert.getPublicKey());
+ }
+ // check RetrievalMethod
} else if (kiType instanceof RetrievalMethod) {
- RetrievalMethod rm = (RetrievalMethod) kiType;
+ RetrievalMethod rm = (RetrievalMethod) kiType;
try {
- KeySelectorResult ksr = null;
- if (rm.getType().equals
- (X509Data.RAW_X509_CERTIFICATE_TYPE)) {
- OctetStreamData data = (OctetStreamData)
- rm.dereference(context);
- CertificateFactory cf =
- CertificateFactory.getInstance("X.509");
- X509Certificate cert = (X509Certificate)
- cf.generateCertificate(data.getOctetStream());
- ksr = certSelect(cert, sm);
- } else if (rm.getType().equals(X509Data.TYPE)) {
- X509Data xd = (X509Data) ((DOMRetrievalMethod) rm).
- dereferenceAsXMLStructure(context);
- ksr = x509DataSelect(xd, sm);
- } else {
- // skip; keyinfo type is not supported
- continue;
- }
- if (ksr != null) {
- return ksr;
- }
+ KeySelectorResult ksr = null;
+ if (rm.getType().equals
+ (X509Data.RAW_X509_CERTIFICATE_TYPE)) {
+ OctetStreamData data = (OctetStreamData)
+ rm.dereference(context);
+ CertificateFactory cf =
+ CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate)
+ cf.generateCertificate(data.getOctetStream());
+ ksr = certSelect(cert, sm);
+ } else if (rm.getType().equals(X509Data.TYPE)) {
+ X509Data xd = (X509Data) ((DOMRetrievalMethod) rm).
+ dereferenceAsXMLStructure(context);
+ ksr = x509DataSelect(xd, sm);
+ } else {
+ // skip; keyinfo type is not supported
+ continue;
+ }
+ if (ksr != null) {
+ return ksr;
+ }
} catch (Exception e) {
- throw new KeySelectorException(e);
- }
- }
+ throw new KeySelectorException(e);
+ }
+ }
}
} catch (KeyStoreException kse) {
// throw exception if keystore is uninitialized
@@ -204,16 +204,16 @@ public class X509KeySelector extends Key
* is a match; otherwise null
*/
private KeySelectorResult keyStoreSelect(CertSelector cs)
- throws KeyStoreException {
+ throws KeyStoreException {
Enumeration aliases = ks.aliases();
while (aliases.hasMoreElements()) {
- String alias = (String) aliases.nextElement();
- Certificate cert = ks.getCertificate(alias);
- if (cert != null && cs.match(cert)) {
- return new SimpleKeySelectorResult(cert.getPublicKey());
- }
- }
- return null;
+ String alias = (String) aliases.nextElement();
+ Certificate cert = ks.getCertificate(alias);
+ if (cert != null && cs.match(cert)) {
+ return new SimpleKeySelectorResult(cert.getPublicKey());
+ }
+ }
+ return null;
}
/**
@@ -225,7 +225,7 @@ public class X509KeySelector extends Key
* is a match; otherwise null
*/
private KeySelectorResult certSelect(X509Certificate xcert,
- SignatureMethod sm) throws KeyStoreException {
+ SignatureMethod sm) throws KeyStoreException {
// skip non-signer certs
boolean[] keyUsage = xcert.getKeyUsage();
if (keyUsage != null && keyUsage[0] == false) {
@@ -239,7 +239,7 @@ public class X509KeySelector extends Key
return new SimpleKeySelectorResult(pk);
}
}
- return null;
+ return null;
}
/**
@@ -247,22 +247,22 @@ public class X509KeySelector extends Key
* signature algorithm URI.
*/
private String getPKAlgorithmOID(String algURI) {
- if (algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)) {
- return "1.2.840.10040.4.1";
- } else if (algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
- return "1.2.840.113549.1.1";
- } else {
- return null;
- }
+ if (algURI.equalsIgnoreCase(SignatureMethod.DSA_SHA1)) {
+ return "1.2.840.10040.4.1";
+ } else if (algURI.equalsIgnoreCase(SignatureMethod.RSA_SHA1)) {
+ return "1.2.840.113549.1.1";
+ } else {
+ return null;
+ }
}
/**
* A simple KeySelectorResult containing a public key.
*/
private static class SimpleKeySelectorResult implements KeySelectorResult {
- private final Key key;
- SimpleKeySelectorResult(Key key) { this.key = key; }
- public Key getKey() { return key; }
+ private final Key key;
+ SimpleKeySelectorResult(Key key) { this.key = key; }
+ public Key getKey() { return key; }
}
/**
@@ -291,82 +291,82 @@ public class X509KeySelector extends Key
* is a match; otherwise null
*/
private KeySelectorResult x509DataSelect(X509Data xd, SignatureMethod sm)
- throws KeyStoreException, KeySelectorException {
+ throws KeyStoreException, KeySelectorException {
- // convert signature algorithm to compatible public-key alg OID
- String algOID = getPKAlgorithmOID(sm.getAlgorithm());
+ // convert signature algorithm to compatible public-key alg OID
+ String algOID = getPKAlgorithmOID(sm.getAlgorithm());
X509CertSelector subjectcs = new X509CertSelector();
- try {
+ try {
subjectcs.setSubjectPublicKeyAlgID(algOID);
} catch (IOException ioe) {
- throw new KeySelectorException(ioe);
- }
+ throw new KeySelectorException(ioe);
+ }
Collection certs = new ArrayList();
Iterator xi = xd.getContent().iterator();
while (xi.hasNext()) {
Object o = xi.next();
- // check X509IssuerSerial
- if (o instanceof X509IssuerSerial) {
- X509IssuerSerial xis = (X509IssuerSerial) o;
- try {
- subjectcs.setSerialNumber(xis.getSerialNumber());
- String issuer = new X500Principal(xis.getIssuerName()).getName();
- // strip off newline
- if (issuer.endsWith("\n")) {
- issuer = new String
- (issuer.toCharArray(), 0, issuer.length()-1);
- }
- subjectcs.setIssuer(issuer);
- } catch (IOException ioe) {
- throw new KeySelectorException(ioe);
- }
- // check X509SubjectName
- } else if (o instanceof String) {
- String sn = (String) o;
- try {
- String subject = new X500Principal(sn).getName();
- // strip off newline
- if (subject.endsWith("\n")) {
- subject = new String
- (subject.toCharArray(), 0, subject.length()-1);
- }
- subjectcs.setSubject(subject);
- } catch (IOException ioe) {
- throw new KeySelectorException(ioe);
- }
- // check X509SKI
- } else if (o instanceof byte[]) {
- byte[] ski = (byte[]) o;
- // DER-encode ski - required by X509CertSelector
- byte[] encodedSki = new byte[ski.length+2];
- encodedSki[0] = 0x04; // OCTET STRING tag value
- encodedSki[1] = (byte) ski.length; // length
- System.arraycopy(ski, 0, encodedSki, 2, ski.length);
- subjectcs.setSubjectKeyIdentifier(encodedSki);
- } else if (o instanceof X509Certificate) {
- certs.add((X509Certificate) o);
- // check X509CRL
- // not supported: should use CertPath API
- } else {
- // skip all other entries
- continue;
- }
- }
- KeySelectorResult ksr = keyStoreSelect(subjectcs);
- if (ksr != null) {
- return ksr;
- }
- if (!certs.isEmpty() && !trusted) {
- // try to find public key in certs in X509Data
- Iterator i = certs.iterator();
- while (i.hasNext()) {
- X509Certificate cert = (X509Certificate) i.next();
- if (subjectcs.match(cert)) {
- return new SimpleKeySelectorResult(cert.getPublicKey());
- }
- }
- }
- return null;
+ // check X509IssuerSerial
+ if (o instanceof X509IssuerSerial) {
+ X509IssuerSerial xis = (X509IssuerSerial) o;
+ try {
+ subjectcs.setSerialNumber(xis.getSerialNumber());
+ String issuer = new X500Principal(xis.getIssuerName()).getName();
+ // strip off newline
+ if (issuer.endsWith("\n")) {
+ issuer = new String
+ (issuer.toCharArray(), 0, issuer.length()-1);
+ }
+ subjectcs.setIssuer(issuer);
+ } catch (IOException ioe) {
+ throw new KeySelectorException(ioe);
+ }
+ // check X509SubjectName
+ } else if (o instanceof String) {
+ String sn = (String) o;
+ try {
+ String subject = new X500Principal(sn).getName();
+ // strip off newline
+ if (subject.endsWith("\n")) {
+ subject = new String
+ (subject.toCharArray(), 0, subject.length()-1);
+ }
+ subjectcs.setSubject(subject);
+ } catch (IOException ioe) {
+ throw new KeySelectorException(ioe);
+ }
+ // check X509SKI
+ } else if (o instanceof byte[]) {
+ byte[] ski = (byte[]) o;
+ // DER-encode ski - required by X509CertSelector
+ byte[] encodedSki = new byte[ski.length+2];
+ encodedSki[0] = 0x04; // OCTET STRING tag value
+ encodedSki[1] = (byte) ski.length; // length
+ System.arraycopy(ski, 0, encodedSki, 2, ski.length);
+ subjectcs.setSubjectKeyIdentifier(encodedSki);
+ } else if (o instanceof X509Certificate) {
+ certs.add((X509Certificate) o);
+ // check X509CRL
+ // not supported: should use CertPath API
+ } else {
+ // skip all other entries
+ continue;
+ }
+ }
+ KeySelectorResult ksr = keyStoreSelect(subjectcs);
+ if (ksr != null) {
+ return ksr;
+ }
+ if (!certs.isEmpty() && !trusted) {
+ // try to find public key in certs in X509Data
+ Iterator i = certs.iterator();
+ while (i.hasNext()) {
+ X509Certificate cert = (X509Certificate) i.next();
+ if (subjectcs.match(cert)) {
+ return new SimpleKeySelectorResult(cert.getPublicKey());
+ }
+ }
+ }
+ return null;
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLObjectTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLObjectTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLObjectTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLObjectTest.java Fri Jan 7 11:23:09 2011
@@ -38,69 +38,69 @@ public class XMLObjectTest extends TestC
private String encoding = "encoding";
public XMLObjectTest() {
- super("XMLObjectTest");
+ super("XMLObjectTest");
}
public XMLObjectTest(String name) {
- super(name);
+ super(name);
}
public void setUp() throws Exception {
- factory = XMLSignatureFactory.getInstance
+ factory = XMLSignatureFactory.getInstance
("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
}
public void tearDown() {}
public void testConstructor() {
- // test XMLSignatureFactory.newXMLObject(List, String, String, String)
- XMLObject obj;
-
- obj = factory.newXMLObject(null, null, null, null);
- assertNotNull(obj);
-
- Vector list = new Vector();
- obj = factory.newXMLObject(list, null, null, null);
- assertNotNull(obj);
-
- String strEntry = "wrong type";
- list.add(strEntry);
- try {
- obj = factory.newXMLObject(list, null, null, null);
- fail("Should raise a CCE for content containing " +
- "invalid, i.e. non-XMLStructure, entries");
- } catch (ClassCastException cce) {
- } catch (Exception ex) {
- fail("Should raise a CCE for content with invalid entries " +
- "instead of " + ex);
- }
- list.remove(strEntry);
- list.add(new TestUtils.MyOwnXMLStructure());
- obj = factory.newXMLObject(list, id, mimeType, encoding);
- assertNotNull(obj);
- assertNotNull(obj.getContent());
- assertTrue(Arrays.equals(obj.getContent().toArray(), list.toArray()));
- assertEquals(obj.getId(), id);
- assertEquals(obj.getMimeType(), mimeType);
- assertEquals(obj.getEncoding(), encoding);
-
- List unmodifiable = obj.getContent();
- try {
- unmodifiable.add(new TestUtils.MyOwnXMLStructure());
- fail("Should return an unmodifiable List object");
- } catch (UnsupportedOperationException uoe) {}
- assertTrue(Arrays.equals(unmodifiable.toArray(), list.toArray()));
+ // test XMLSignatureFactory.newXMLObject(List, String, String, String)
+ XMLObject obj;
+
+ obj = factory.newXMLObject(null, null, null, null);
+ assertNotNull(obj);
+
+ Vector list = new Vector();
+ obj = factory.newXMLObject(list, null, null, null);
+ assertNotNull(obj);
+
+ String strEntry = "wrong type";
+ list.add(strEntry);
+ try {
+ obj = factory.newXMLObject(list, null, null, null);
+ fail("Should raise a CCE for content containing " +
+ "invalid, i.e. non-XMLStructure, entries");
+ } catch (ClassCastException cce) {
+ } catch (Exception ex) {
+ fail("Should raise a CCE for content with invalid entries " +
+ "instead of " + ex);
+ }
+ list.remove(strEntry);
+ list.add(new TestUtils.MyOwnXMLStructure());
+ obj = factory.newXMLObject(list, id, mimeType, encoding);
+ assertNotNull(obj);
+ assertNotNull(obj.getContent());
+ assertTrue(Arrays.equals(obj.getContent().toArray(), list.toArray()));
+ assertEquals(obj.getId(), id);
+ assertEquals(obj.getMimeType(), mimeType);
+ assertEquals(obj.getEncoding(), encoding);
+
+ List unmodifiable = obj.getContent();
+ try {
+ unmodifiable.add(new TestUtils.MyOwnXMLStructure());
+ fail("Should return an unmodifiable List object");
+ } catch (UnsupportedOperationException uoe) {}
+ assertTrue(Arrays.equals(unmodifiable.toArray(), list.toArray()));
}
public void testisFeatureSupported() {
- List list = new Vector();
- list.add(new TestUtils.MyOwnXMLStructure());
- XMLObject obj = factory.newXMLObject(list, id, mimeType, encoding);
- try {
- obj.isFeatureSupported(null);
- fail("Should raise a NPE for null feature");
- } catch (NullPointerException npe) {}
+ List list = new Vector();
+ list.add(new TestUtils.MyOwnXMLStructure());
+ XMLObject obj = factory.newXMLObject(list, id, mimeType, encoding);
+ try {
+ obj.isFeatureSupported(null);
+ fail("Should raise a NPE for null feature");
+ } catch (NullPointerException npe) {}
- assertTrue(!obj.isFeatureSupported("not supported"));
+ assertTrue(!obj.isFeatureSupported("not supported"));
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignContextTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignContextTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignContextTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignContextTest.java Fri Jan 7 11:23:09 2011
@@ -43,74 +43,74 @@ public class XMLSignContextTest extends
private Document doc;
public XMLSignContextTest() {
- super("XMLSignContextTest");
+ super("XMLSignContextTest");
}
public XMLSignContextTest(String name) {
- super(name);
+ super(name);
}
public void setUp() throws Exception {
- // set up the signingKeys
- KEYS = new Key[3];
- KEYS[0] = TestUtils.getPrivateKey("DSA");
- KEYS[1] = TestUtils.getPrivateKey("RSA");
- KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
- // set up the default XMLSignContext
- SecretKey sk = new SecretKeySpec(new byte[8], "DES");
- doc = TestUtils.newDocument();
- defContext = new DOMSignContext(sk, doc);
+ // set up the signingKeys
+ KEYS = new Key[3];
+ KEYS[0] = TestUtils.getPrivateKey("DSA");
+ KEYS[1] = TestUtils.getPrivateKey("RSA");
+ KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+ // set up the default XMLSignContext
+ SecretKey sk = new SecretKeySpec(new byte[8], "DES");
+ doc = TestUtils.newDocument();
+ defContext = new DOMSignContext(sk, doc);
}
public void tearDown() { }
public void testsetngetBaseURI() throws Exception {
- assertNull(defContext.getBaseURI());
+ assertNull(defContext.getBaseURI());
- String uri = "http://www.w3.org/2000/09/xmldsig#";
- defContext.setBaseURI(uri);
- assertEquals(defContext.getBaseURI(), uri);
- defContext.setBaseURI(null);
- assertNull(defContext.getBaseURI());
+ String uri = "http://www.w3.org/2000/09/xmldsig#";
+ defContext.setBaseURI(uri);
+ assertEquals(defContext.getBaseURI(), uri);
+ defContext.setBaseURI(null);
+ assertNull(defContext.getBaseURI());
}
public void testsetngetProperty() throws Exception {
- String name = "key";
- assertNull(defContext.getProperty(name));
- try {
- defContext.setProperty(null, null);
- fail("Should raise a NPE with a null name");
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should raise a NPE instead of " + ex);
- }
- String value1 = "value#1";
- String value2 = "value#2";
- assertNull(defContext.setProperty(name, value1));
- assertEquals(defContext.getProperty(name), value1);
- assertEquals(defContext.setProperty(name, value2), value1);
- assertEquals(defContext.getProperty(name), value2);
- assertEquals(defContext.setProperty(name, null), value2);
- assertNull(defContext.getProperty(name));
+ String name = "key";
+ assertNull(defContext.getProperty(name));
+ try {
+ defContext.setProperty(null, null);
+ fail("Should raise a NPE with a null name");
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should raise a NPE instead of " + ex);
+ }
+ String value1 = "value#1";
+ String value2 = "value#2";
+ assertNull(defContext.setProperty(name, value1));
+ assertEquals(defContext.getProperty(name), value1);
+ assertEquals(defContext.setProperty(name, value2), value1);
+ assertEquals(defContext.getProperty(name), value2);
+ assertEquals(defContext.setProperty(name, null), value2);
+ assertNull(defContext.getProperty(name));
}
public void testsetngetURIDereferencer() throws Exception {
- assertNull(defContext.getURIDereferencer());
- byte[] data = "simpleDereferencer".getBytes();
- URIDereferencer deref = new TestUtils.OctetStreamURIDereferencer(data);
-
- defContext.setURIDereferencer(deref);
- assertEquals(defContext.getURIDereferencer(), deref);
- defContext.setURIDereferencer(null);
- assertNull(defContext.getURIDereferencer());
+ assertNull(defContext.getURIDereferencer());
+ byte[] data = "simpleDereferencer".getBytes();
+ URIDereferencer deref = new TestUtils.OctetStreamURIDereferencer(data);
+
+ defContext.setURIDereferencer(deref);
+ assertEquals(defContext.getURIDereferencer(), deref);
+ defContext.setURIDereferencer(null);
+ assertNull(defContext.getURIDereferencer());
}
public void testsetngetKeySelector() throws Exception {
- defContext.setKeySelector(null);
- assertNull(defContext.getKeySelector());
- KeySelector ks = KeySelector.singletonKeySelector(KEYS[0]);
- defContext.setKeySelector(ks);
- assertEquals(defContext.getKeySelector(), ks);
+ defContext.setKeySelector(null);
+ assertNull(defContext.getKeySelector());
+ KeySelector ks = KeySelector.singletonKeySelector(KEYS[0]);
+ defContext.setKeySelector(ks);
+ assertEquals(defContext.getKeySelector(), ks);
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureFactoryTest.java Fri Jan 7 11:23:09 2011
@@ -50,141 +50,141 @@ public class XMLSignatureFactoryTest ext
}
public XMLSignatureFactoryTest(String name) {
- super(name);
+ super(name);
}
public void setUp() throws Exception {
- factory = XMLSignatureFactory.getInstance
+ factory = XMLSignatureFactory.getInstance
("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
}
public void tearDown() { }
public void testgetInstance() {
- try {
- XMLSignatureFactory.getInstance("non-existent");
- fail("Should throw NoSuchMechanismException if no impl found");
- } catch (NoSuchMechanismException ex) {}
-
- try {
- XMLSignatureFactory.getInstance(null);
- fail("Should raise a NPE for null mechanismType");
- } catch (NullPointerException npe) {}
-
- try {
- XMLSignatureFactory.getInstance("DOM", "non-existent");
- fail("Should throw NoSuchProviderException if specified " +
- "provider is not found");
- } catch (NoSuchProviderException nspe) {
- } catch (NoSuchMechanismException nse) {
- fail("Should raise a NoSuchProviderException instead of " + nse +
- " if specified provider is not found");
- }
-
- try {
- XMLSignatureFactory.getInstance(null);
- fail("Should raise a NPE for null mechanismType");
- } catch (NullPointerException npe) {}
-
- try {
- XMLSignatureFactory.getInstance("DOM", (Provider) null);
- fail("Should raise a NPE for null provider");
- } catch (NullPointerException npe) {}
+ try {
+ XMLSignatureFactory.getInstance("non-existent");
+ fail("Should throw NoSuchMechanismException if no impl found");
+ } catch (NoSuchMechanismException ex) {}
+
+ try {
+ XMLSignatureFactory.getInstance(null);
+ fail("Should raise a NPE for null mechanismType");
+ } catch (NullPointerException npe) {}
+
+ try {
+ XMLSignatureFactory.getInstance("DOM", "non-existent");
+ fail("Should throw NoSuchProviderException if specified " +
+ "provider is not found");
+ } catch (NoSuchProviderException nspe) {
+ } catch (NoSuchMechanismException nse) {
+ fail("Should raise a NoSuchProviderException instead of " + nse +
+ " if specified provider is not found");
+ }
+
+ try {
+ XMLSignatureFactory.getInstance(null);
+ fail("Should raise a NPE for null mechanismType");
+ } catch (NullPointerException npe) {}
+
+ try {
+ XMLSignatureFactory.getInstance("DOM", (Provider) null);
+ fail("Should raise a NPE for null provider");
+ } catch (NullPointerException npe) {}
}
public void testgetMechanismType() {
- assertNotNull(factory);
- assertEquals("DOM", factory.getMechanismType());
+ assertNotNull(factory);
+ assertEquals("DOM", factory.getMechanismType());
}
public void testisFeatureSupported() {
- try {
- factory.isFeatureSupported(null);
- fail("Should raise a NPE for null feature");
- } catch (NullPointerException npe) {}
+ try {
+ factory.isFeatureSupported(null);
+ fail("Should raise a NPE for null feature");
+ } catch (NullPointerException npe) {}
- assertTrue(!factory.isFeatureSupported("not supported"));
+ assertTrue(!factory.isFeatureSupported("not supported"));
}
public void testgetKeyInfoFactory() throws Exception {
- KeyInfoFactory kifac = factory.getKeyInfoFactory();
- assertEquals(kifac.getMechanismType(), factory.getMechanismType());
- assertEquals(kifac.getProvider(), factory.getProvider());
+ KeyInfoFactory kifac = factory.getKeyInfoFactory();
+ assertEquals(kifac.getMechanismType(), factory.getMechanismType());
+ assertEquals(kifac.getProvider(), factory.getProvider());
}
public void testunmarshalXMLSignature() throws Exception {
- XMLSignature stuff;
- try {
- stuff = factory.unmarshalXMLSignature((XMLValidateContext) null);
- fail("Should raise an NPE for null inputs");
- } catch (NullPointerException ex) {
- } catch (Exception ex) {
- fail("Should throw an NPE instead of " + ex +
- " for null inputs");
- }
-
- try {
- stuff = factory.unmarshalXMLSignature(
- new XMLValidateContext() {
- public Object getProperty(String name) { return null; }
- public Object setProperty(String name, Object property) {
- return null;
- }
- public String getBaseURI() { return null; }
- public void setBaseURI(String uri) { return; }
- public KeySelector getKeySelector() { return null; }
- public void setKeySelector(KeySelector ks) { return; }
- public URIDereferencer getURIDereferencer() { return null; }
- public void setURIDereferencer(URIDereferencer ud) {return;}
- public Object get(Object key) {return null;}
- public Object put(Object key, Object value) {return null;}
+ XMLSignature stuff;
+ try {
+ stuff = factory.unmarshalXMLSignature((XMLValidateContext) null);
+ fail("Should raise an NPE for null inputs");
+ } catch (NullPointerException ex) {
+ } catch (Exception ex) {
+ fail("Should throw an NPE instead of " + ex +
+ " for null inputs");
+ }
+
+ try {
+ stuff = factory.unmarshalXMLSignature(
+ new XMLValidateContext() {
+ public Object getProperty(String name) { return null; }
+ public Object setProperty(String name, Object property) {
+ return null;
+ }
+ public String getBaseURI() { return null; }
+ public void setBaseURI(String uri) { return; }
+ public KeySelector getKeySelector() { return null; }
+ public void setKeySelector(KeySelector ks) { return; }
+ public URIDereferencer getURIDereferencer() { return null; }
+ public void setURIDereferencer(URIDereferencer ud) {return;}
+ public Object get(Object key) {return null;}
+ public Object put(Object key, Object value) {return null;}
public void setDefaultNamespacePrefix(String defPrefix) {}
public String getDefaultNamespacePrefix() {return null;}
public String putNamespacePrefix
(String nsURI, String prefix) {return null;}
public String getNamespacePrefix
(String nsURI, String defPrefix) {return null;}
- });
- fail("Should throw a CCE for input of wrong type");
- } catch (ClassCastException ex) {
- } catch (Exception ex) {
- fail("Should raise a CCE instead of " + ex +
- " for wrong inputs");
- }
+ });
+ fail("Should throw a CCE for input of wrong type");
+ } catch (ClassCastException ex) {
+ } catch (Exception ex) {
+ fail("Should raise a CCE instead of " + ex +
+ " for wrong inputs");
+ }
DocumentBuilderFactory docFactory =
DocumentBuilderFactory.newInstance();
- docFactory.setNamespaceAware(true);
- DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
- String fs = System.getProperty("file.separator");
- String base = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
- File dir = new File(base + fs +
- "data" + fs + "ie" + fs + "baltimore" + fs + "merlin-examples",
- "merlin-xmldsig-twenty-three");
- Document doc = docBuilder.parse(new File(dir, "signature.xml"));
- NodeList nl = doc.getElementsByTagName("KeyInfo");
- try {
- stuff = factory.unmarshalXMLSignature
- (new DOMValidateContext(TestUtils.getPublicKey("RSA"), nl.item(0)));
- fail("Should throw a MarshalException for non-XMLSignature inputs");
- } catch (MarshalException ex) {}
-
- nl = doc.getElementsByTagName("Signature");
- try {
- stuff = factory.unmarshalXMLSignature
- (new DOMValidateContext(TestUtils.getPublicKey("DSA"), nl.item(0)));
- assertNotNull(stuff);
- } catch (MarshalException ex) {
- fail("Unmarshal failed: " + ex.getMessage());
- ex.printStackTrace();
- }
+ docFactory.setNamespaceAware(true);
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+ String fs = System.getProperty("file.separator");
+ String base = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
+ File dir = new File(base + fs +
+ "data" + fs + "ie" + fs + "baltimore" + fs + "merlin-examples",
+ "merlin-xmldsig-twenty-three");
+ Document doc = docBuilder.parse(new File(dir, "signature.xml"));
+ NodeList nl = doc.getElementsByTagName("KeyInfo");
+ try {
+ stuff = factory.unmarshalXMLSignature
+ (new DOMValidateContext(TestUtils.getPublicKey("RSA"), nl.item(0)));
+ fail("Should throw a MarshalException for non-XMLSignature inputs");
+ } catch (MarshalException ex) {}
+
+ nl = doc.getElementsByTagName("Signature");
+ try {
+ stuff = factory.unmarshalXMLSignature
+ (new DOMValidateContext(TestUtils.getPublicKey("DSA"), nl.item(0)));
+ assertNotNull(stuff);
+ } catch (MarshalException ex) {
+ fail("Unmarshal failed: " + ex.getMessage());
+ ex.printStackTrace();
+ }
}
// for debugging purposes
public static void main(String[] args) throws Exception {
- XMLSignatureFactoryTest test =
- new XMLSignatureFactoryTest("XMLSignatureFactoryTest");
- test.setUp();
- test.testunmarshalXMLSignature();
+ XMLSignatureFactoryTest test =
+ new XMLSignatureFactoryTest("XMLSignatureFactoryTest");
+ test.setUp();
+ test.testunmarshalXMLSignature();
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java Fri Jan 7 11:23:09 2011
@@ -58,189 +58,189 @@ public class XMLSignatureTest extends Te
}
public XMLSignatureTest() {
- super("XMLSignatureTest");
+ super("XMLSignatureTest");
}
public XMLSignatureTest(String name) {
- super(name);
+ super(name);
}
public void setUp() throws Exception {
- fac = XMLSignatureFactory.getInstance
+ fac = XMLSignatureFactory.getInstance
("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
- kifac = KeyInfoFactory.getInstance
+ kifac = KeyInfoFactory.getInstance
("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
- // set up the corresponding SignatureMethod
- SIG_METHODS = new SignatureMethod[3];
- SIG_METHODS[0] = fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
- SIG_METHODS[1] = fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
- SIG_METHODS[2] = fac.newSignatureMethod(SignatureMethod.HMAC_SHA1, null);
- // set up the signingKeys
- SIGN_KEYS = new Key[3];
- SIGN_KEYS[0] = TestUtils.getPrivateKey("DSA");
- SIGN_KEYS[1] = TestUtils.getPrivateKey("RSA");
- SIGN_KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
- // set up the validatingKeys
- VALIDATE_KEYS = new Key[3];
- VALIDATE_KEYS[0] = TestUtils.getPublicKey("DSA");
- VALIDATE_KEYS[1] = TestUtils.getPublicKey("RSA");
- VALIDATE_KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
- defSi = createSignedInfo(SIG_METHODS[0]);
- defKi = kifac.newKeyInfo
- (Collections.singletonList(kifac.newKeyName("Alice")));
- objs = Collections.singletonList
- (fac.newXMLObject(null, null, null, null));
+ // set up the corresponding SignatureMethod
+ SIG_METHODS = new SignatureMethod[3];
+ SIG_METHODS[0] = fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null);
+ SIG_METHODS[1] = fac.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
+ SIG_METHODS[2] = fac.newSignatureMethod(SignatureMethod.HMAC_SHA1, null);
+ // set up the signingKeys
+ SIGN_KEYS = new Key[3];
+ SIGN_KEYS[0] = TestUtils.getPrivateKey("DSA");
+ SIGN_KEYS[1] = TestUtils.getPrivateKey("RSA");
+ SIGN_KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+ // set up the validatingKeys
+ VALIDATE_KEYS = new Key[3];
+ VALIDATE_KEYS[0] = TestUtils.getPublicKey("DSA");
+ VALIDATE_KEYS[1] = TestUtils.getPublicKey("RSA");
+ VALIDATE_KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+ defSi = createSignedInfo(SIG_METHODS[0]);
+ defKi = kifac.newKeyInfo
+ (Collections.singletonList(kifac.newKeyName("Alice")));
+ objs = Collections.singletonList
+ (fac.newXMLObject(null, null, null, null));
}
public void tearDown() {}
public void testConstructor() throws Exception {
- XMLSignature sig = null;
- // test XMLSignatureFactory.newXMLSignature(SignedInfo, KeyInfo)
- // and XMLSignatureFactory.newXMLSignature(SignedInfo,
- // KeyInfo, List, String, String)
- // for generating XMLSignature objects
- for (int i = 0; i < 2; i++) {
- try {
- switch (i) {
- case 0:
- sig = fac.newXMLSignature(null, defKi);
- break;
- case 1:
- sig = fac.newXMLSignature(null, defKi, objs, id, sigValueId);
- break;
- }
- fail("Should throw a NPE for null references");
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should throw a NPE instead of " + ex +
- " for null references");
- }
- }
- try {
- sig = fac.newXMLSignature(defSi, defKi,
- Collections.singletonList("wrongType"), id, sigValueId);
- fail("Should throw a CCE for invalid objects");
- } catch (ClassCastException cce) {
- } catch (Exception ex) {
- fail("Should throw a CCE instead of " + ex +
- " for invalid objects");
- }
- sig = fac.newXMLSignature(defSi, defKi, objs, id, sigValueId);
- assertEquals(sig.getId(), id);
- assertEquals(sig.getKeyInfo(), defKi);
- assertTrue(Arrays.equals(sig.getObjects().toArray(), objs.toArray()));
- assertNull(sig.getSignatureValue().getValue());
- assertEquals(sig.getSignatureValue().getId(), sigValueId);
- assertEquals(sig.getSignedInfo(), defSi);
-
- sig = fac.newXMLSignature(defSi, defKi);
- assertNull(sig.getId());
- assertEquals(sig.getKeyInfo(), defKi);
- assertTrue(sig.getObjects().size()==0);
- assertNull(sig.getSignatureValue().getValue());
- assertNull(sig.getSignatureValue().getId());
- assertEquals(sig.getSignedInfo(), defSi);
+ XMLSignature sig = null;
+ // test XMLSignatureFactory.newXMLSignature(SignedInfo, KeyInfo)
+ // and XMLSignatureFactory.newXMLSignature(SignedInfo,
+ // KeyInfo, List, String, String)
+ // for generating XMLSignature objects
+ for (int i = 0; i < 2; i++) {
+ try {
+ switch (i) {
+ case 0:
+ sig = fac.newXMLSignature(null, defKi);
+ break;
+ case 1:
+ sig = fac.newXMLSignature(null, defKi, objs, id, sigValueId);
+ break;
+ }
+ fail("Should throw a NPE for null references");
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should throw a NPE instead of " + ex +
+ " for null references");
+ }
+ }
+ try {
+ sig = fac.newXMLSignature(defSi, defKi,
+ Collections.singletonList("wrongType"), id, sigValueId);
+ fail("Should throw a CCE for invalid objects");
+ } catch (ClassCastException cce) {
+ } catch (Exception ex) {
+ fail("Should throw a CCE instead of " + ex +
+ " for invalid objects");
+ }
+ sig = fac.newXMLSignature(defSi, defKi, objs, id, sigValueId);
+ assertEquals(sig.getId(), id);
+ assertEquals(sig.getKeyInfo(), defKi);
+ assertTrue(Arrays.equals(sig.getObjects().toArray(), objs.toArray()));
+ assertNull(sig.getSignatureValue().getValue());
+ assertEquals(sig.getSignatureValue().getId(), sigValueId);
+ assertEquals(sig.getSignedInfo(), defSi);
+
+ sig = fac.newXMLSignature(defSi, defKi);
+ assertNull(sig.getId());
+ assertEquals(sig.getKeyInfo(), defKi);
+ assertTrue(sig.getObjects().size()==0);
+ assertNull(sig.getSignatureValue().getValue());
+ assertNull(sig.getSignatureValue().getId());
+ assertEquals(sig.getSignedInfo(), defSi);
}
public void testisFeatureSupported() throws Exception {
- XMLSignature sig = fac.newXMLSignature(defSi, null);
-
- try {
- sig.isFeatureSupported(null);
- fail("Should raise a NPE for null feature");
- } catch (NullPointerException npe) {}
-
- assertTrue(!sig.isFeatureSupported("not supported"));
+ XMLSignature sig = fac.newXMLSignature(defSi, null);
+
+ try {
+ sig.isFeatureSupported(null);
+ fail("Should raise a NPE for null feature");
+ } catch (NullPointerException npe) {}
+
+ assertTrue(!sig.isFeatureSupported("not supported"));
}
public void testsignANDvalidate() throws Exception {
- XMLSignature sig;
- SignedInfo si;
- KeyInfo ki = null;
- XMLSignContext signContext;
- XMLValidateContext validateContext;
- boolean status = true;
- for (int i = SIGN_KEYS.length-1; i>=0 ; i--) {
- si = createSignedInfo(SIG_METHODS[i]);
- if (VALIDATE_KEYS[i] instanceof PublicKey) {
- ki = kifac.newKeyInfo(Collections.singletonList
- (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[i])));
- } else {
- ki = kifac.newKeyInfo(Collections.singletonList
- (kifac.newKeyName("testuser")));
- }
- sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
- Document doc = TestUtils.newDocument();
- signContext = new DOMSignContext(SIGN_KEYS[i], doc);
- sig.sign(signContext);
- validateContext = new DOMValidateContext
- (VALIDATE_KEYS[i], doc.getDocumentElement());
- if (sig.validate(validateContext) == false) {
- status = false;
- TestUtils.dumpDocument(doc, "signatureTest_out"+i+".xml");
- }
- }
- assertTrue(status);
+ XMLSignature sig;
+ SignedInfo si;
+ KeyInfo ki = null;
+ XMLSignContext signContext;
+ XMLValidateContext validateContext;
+ boolean status = true;
+ for (int i = SIGN_KEYS.length-1; i>=0 ; i--) {
+ si = createSignedInfo(SIG_METHODS[i]);
+ if (VALIDATE_KEYS[i] instanceof PublicKey) {
+ ki = kifac.newKeyInfo(Collections.singletonList
+ (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[i])));
+ } else {
+ ki = kifac.newKeyInfo(Collections.singletonList
+ (kifac.newKeyName("testuser")));
+ }
+ sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
+ Document doc = TestUtils.newDocument();
+ signContext = new DOMSignContext(SIGN_KEYS[i], doc);
+ sig.sign(signContext);
+ validateContext = new DOMValidateContext
+ (VALIDATE_KEYS[i], doc.getDocumentElement());
+ if (sig.validate(validateContext) == false) {
+ status = false;
+ TestUtils.dumpDocument(doc, "signatureTest_out"+i+".xml");
+ }
+ }
+ assertTrue(status);
}
public void testsignWithProvider() throws Exception {
- XMLSignature sig;
- SignedInfo si;
- KeyInfo ki = null;
- XMLSignContext signContext;
- Provider p = new TestProvider();
- for (int i = SIGN_KEYS.length-2; i>=0 ; i--) {
- si = createSignedInfo(SIG_METHODS[i]);
- if (VALIDATE_KEYS[i] instanceof PublicKey) {
- ki = kifac.newKeyInfo(Collections.singletonList
- (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[i])));
- } else {
- ki = kifac.newKeyInfo(Collections.singletonList
- (kifac.newKeyName("testuser")));
- }
- sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
- Document doc = TestUtils.newDocument();
- signContext = new DOMSignContext(SIGN_KEYS[i], doc);
- signContext.setProperty
- ("org.jcp.xml.dsig.internal.dom.SignatureProvider", p);
- try {
- sig.sign(signContext);
- fail("Should have failed because TestProvider does not " +
- "support " + SIGN_KEYS[i].getAlgorithm());
- } catch (Exception e) {
- assertTrue(e.getMessage(),
- e.getCause() instanceof NoSuchAlgorithmException);
- }
- }
+ XMLSignature sig;
+ SignedInfo si;
+ KeyInfo ki = null;
+ XMLSignContext signContext;
+ Provider p = new TestProvider();
+ for (int i = SIGN_KEYS.length-2; i>=0 ; i--) {
+ si = createSignedInfo(SIG_METHODS[i]);
+ if (VALIDATE_KEYS[i] instanceof PublicKey) {
+ ki = kifac.newKeyInfo(Collections.singletonList
+ (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[i])));
+ } else {
+ ki = kifac.newKeyInfo(Collections.singletonList
+ (kifac.newKeyName("testuser")));
+ }
+ sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
+ Document doc = TestUtils.newDocument();
+ signContext = new DOMSignContext(SIGN_KEYS[i], doc);
+ signContext.setProperty
+ ("org.jcp.xml.dsig.internal.dom.SignatureProvider", p);
+ try {
+ sig.sign(signContext);
+ fail("Should have failed because TestProvider does not " +
+ "support " + SIGN_KEYS[i].getAlgorithm());
+ } catch (Exception e) {
+ assertTrue(e.getMessage(),
+ e.getCause() instanceof NoSuchAlgorithmException);
+ }
+ }
}
public void testSignWithEmptyNSPrefix() throws Exception {
- SignedInfo si = createSignedInfo(SIG_METHODS[1]);
- KeyInfo ki = kifac.newKeyInfo(Collections.singletonList
- (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[1])));
- XMLSignature sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
- Document doc = TestUtils.newDocument();
- XMLSignContext signContext = new DOMSignContext(SIGN_KEYS[1], doc);
- signContext.putNamespacePrefix(XMLSignature.XMLNS, "");
+ SignedInfo si = createSignedInfo(SIG_METHODS[1]);
+ KeyInfo ki = kifac.newKeyInfo(Collections.singletonList
+ (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[1])));
+ XMLSignature sig = fac.newXMLSignature(si, ki, objs, id, sigValueId);
+ Document doc = TestUtils.newDocument();
+ XMLSignContext signContext = new DOMSignContext(SIGN_KEYS[1], doc);
+ signContext.putNamespacePrefix(XMLSignature.XMLNS, "");
sig.sign(signContext);
/*
- StringWriter sw = new StringWriter();
- dumpDocument(doc, sw);
- System.out.println(sw);
+ StringWriter sw = new StringWriter();
+ dumpDocument(doc, sw);
+ System.out.println(sw);
*/
}
public void testSignWithReferenceManifestDependencies() throws Exception {
// create references
- DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
+ DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
List refs = Collections.singletonList(fac.newReference("#object-1", dm));
// create SignedInfo
- CanonicalizationMethod cm = fac.newCanonicalizationMethod
- (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null);
+ CanonicalizationMethod cm = fac.newCanonicalizationMethod
+ (CanonicalizationMethod.INCLUSIVE, (C14NMethodParameterSpec) null);
SignedInfo si = fac.newSignedInfo(cm, SIG_METHODS[1], refs);
// create objects
@@ -260,8 +260,8 @@ public class XMLSignatureTest extends Te
objs.add(fac.newXMLObject(Collections.singletonList
(new DOMStructure(nc)), "object-2", null, null));
- KeyInfo ki = kifac.newKeyInfo(Collections.singletonList
- (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[1])));
+ KeyInfo ki = kifac.newKeyInfo(Collections.singletonList
+ (kifac.newKeyValue((PublicKey) VALIDATE_KEYS[1])));
// create XMLSignature
XMLSignature sig = fac.newXMLSignature(si, ki, objs, "signature", null);
@@ -270,13 +270,13 @@ public class XMLSignatureTest extends Te
sig.sign(dsc);
/*
- StringWriter sw = new StringWriter();
- dumpDocument(doc, sw);
- System.out.println(sw);
+ StringWriter sw = new StringWriter();
+ dumpDocument(doc, sw);
+ System.out.println(sw);
*/
DOMValidateContext dvc = new DOMValidateContext
- (VALIDATE_KEYS[1], doc.getDocumentElement());
+ (VALIDATE_KEYS[1], doc.getDocumentElement());
XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
if (sig.equals(sig2) == false) {
@@ -289,19 +289,19 @@ public class XMLSignatureTest extends Te
}
private SignedInfo createSignedInfo(SignatureMethod sm) throws Exception {
- // set up the building blocks
- CanonicalizationMethod cm = fac.newCanonicalizationMethod
- (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
- (C14NMethodParameterSpec) null);
- DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
- List refs = Collections.singletonList(fac.newReference
- ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", dm));
+ // set up the building blocks
+ CanonicalizationMethod cm = fac.newCanonicalizationMethod
+ (CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
+ (C14NMethodParameterSpec) null);
+ DigestMethod dm = fac.newDigestMethod(DigestMethod.SHA1, null);
+ List refs = Collections.singletonList(fac.newReference
+ ("http://www.w3.org/Signature/2002/04/xml-stylesheet.b64", dm));
return fac.newSignedInfo(cm, sm, refs);
}
static class TestProvider extends Provider {
- TestProvider() {
- super("TestProvider", 0, "TestProvider");
- }
+ TestProvider() {
+ super("TestProvider", 0, "TestProvider");
+ }
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLValidateContextTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLValidateContextTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLValidateContextTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLValidateContextTest.java Fri Jan 7 11:23:09 2011
@@ -41,80 +41,80 @@ public class XMLValidateContextTest exte
private KeySelector[] KEY_SELECTORS;
public XMLValidateContextTest() {
- super("XMLValidateContextTest");
+ super("XMLValidateContextTest");
}
public XMLValidateContextTest(String name) {
- super(name);
+ super(name);
}
public void setUp() throws Exception {
- // set up the validatingKeys
- KEYS = new Key[3];
- KEYS[0] = TestUtils.getPublicKey("DSA");
- KEYS[1] = TestUtils.getPublicKey("RSA");
- KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
-
- // set up the default XMLValidateContext
- SecretKey sk = new SecretKeySpec(new byte[8], "DES");
- defContext = new DOMValidateContext(sk, TestUtils.newDocument());
+ // set up the validatingKeys
+ KEYS = new Key[3];
+ KEYS[0] = TestUtils.getPublicKey("DSA");
+ KEYS[1] = TestUtils.getPublicKey("RSA");
+ KEYS[2] = new SecretKeySpec(new byte[16], "HmacSHA1");
+
+ // set up the default XMLValidateContext
+ SecretKey sk = new SecretKeySpec(new byte[8], "DES");
+ defContext = new DOMValidateContext(sk, TestUtils.newDocument());
- // set up the key selectors
- KEY_SELECTORS = new KeySelector[1];
+ // set up the key selectors
+ KEY_SELECTORS = new KeySelector[1];
KEY_SELECTORS[0] = KeySelector.singletonKeySelector(sk);
}
public void tearDown() { }
public void testsetngetKeySelector() throws Exception {
- defContext.setKeySelector(null);
- assertNull(defContext.getKeySelector());
+ defContext.setKeySelector(null);
+ assertNull(defContext.getKeySelector());
- for (int i = 0; i < KEY_SELECTORS.length; i++) {
- defContext.setKeySelector(KEY_SELECTORS[i]);
- assertEquals(defContext.getKeySelector(), KEY_SELECTORS[i]);
- }
+ for (int i = 0; i < KEY_SELECTORS.length; i++) {
+ defContext.setKeySelector(KEY_SELECTORS[i]);
+ assertEquals(defContext.getKeySelector(), KEY_SELECTORS[i]);
+ }
}
public void testsetngetBaseURI() throws Exception {
- assertNull(defContext.getBaseURI());
+ assertNull(defContext.getBaseURI());
- String uri = "http://www.w3.org/2000/09/xmldsig#";
- defContext.setBaseURI(uri);
- assertEquals(defContext.getBaseURI(), uri);
- defContext.setBaseURI(null);
- assertNull(defContext.getBaseURI());
+ String uri = "http://www.w3.org/2000/09/xmldsig#";
+ defContext.setBaseURI(uri);
+ assertEquals(defContext.getBaseURI(), uri);
+ defContext.setBaseURI(null);
+ assertNull(defContext.getBaseURI());
}
public void testsetngetProperty() throws Exception {
- String name = "key";
- assertNull(defContext.getProperty(name));
- try {
- defContext.setProperty(null, null);
- fail("Should raise a NPE with a null name");
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should raise a NPE instead of " + ex);
- }
- String value1 = "value#1";
- String value2 = "value#2";
- assertNull(defContext.setProperty(name, value1));
- assertEquals(defContext.getProperty(name), value1);
- assertEquals(defContext.setProperty(name, value2), value1);
- assertEquals(defContext.getProperty(name), value2);
- assertEquals(defContext.setProperty(name, null), value2);
- assertNull(defContext.getProperty(name));
+ String name = "key";
+ assertNull(defContext.getProperty(name));
+ try {
+ defContext.setProperty(null, null);
+ fail("Should raise a NPE with a null name");
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should raise a NPE instead of " + ex);
+ }
+ String value1 = "value#1";
+ String value2 = "value#2";
+ assertNull(defContext.setProperty(name, value1));
+ assertEquals(defContext.getProperty(name), value1);
+ assertEquals(defContext.setProperty(name, value2), value1);
+ assertEquals(defContext.getProperty(name), value2);
+ assertEquals(defContext.setProperty(name, null), value2);
+ assertNull(defContext.getProperty(name));
}
public void testsetngetURIDereferencer() throws Exception {
- assertNull(defContext.getURIDereferencer());
- byte[] data = "simpleDereferencer".getBytes();
- URIDereferencer deref = new TestUtils.OctetStreamURIDereferencer(data);
-
- defContext.setURIDereferencer(deref);
- assertEquals(defContext.getURIDereferencer(), deref);
- defContext.setURIDereferencer(null);
- assertNull(defContext.getURIDereferencer());
+ assertNull(defContext.getURIDereferencer());
+ byte[] data = "simpleDereferencer".getBytes();
+ URIDereferencer deref = new TestUtils.OctetStreamURIDereferencer(data);
+
+ defContext.setURIDereferencer(deref);
+ assertEquals(defContext.getURIDereferencer(), deref);
+ defContext.setURIDereferencer(null);
+ assertNull(defContext.getURIDereferencer());
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/dom/DOMValidateContextTest.java Fri Jan 7 11:23:09 2011
@@ -22,80 +22,71 @@ package javax.xml.crypto.test.dsig.dom;
import java.io.*;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
-import junit.framework.*;
-
import javax.xml.crypto.test.dsig.TestUtils;
/**
* Unit test for javax.xml.crypto.dsig.dom.DOMValidateContext
*
- * @version $Id$
* @author Valerie Peng
*/
-public class DOMValidateContextTest extends TestCase {
+public class DOMValidateContextTest extends org.junit.Assert {
private DOMValidateContext domVC;
- public DOMValidateContextTest() {
- super("DOMValidateContext");
- }
-
- public DOMValidateContextTest(String name) {
- super(name);
- }
-
- public void setUp() throws Exception {
- String fs = System.getProperty("file.separator");
- String base = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
- File dir = new File(base + fs +
- "data" + fs + "ie" + fs + "baltimore" + fs + "merlin-examples",
- "merlin-xmldsig-twenty-three");
- File input = new File(dir, "signature.xml");
- domVC = (DOMValidateContext)
- TestUtils.getXMLValidateContext("DOM", input, "Reference");
+ public DOMValidateContextTest() throws Exception {
+ String fs = System.getProperty("file.separator");
+ String base = System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
+ File dir = new File(base + fs +
+ "data" + fs + "ie" + fs + "baltimore" + fs + "merlin-examples",
+ "merlin-xmldsig-twenty-three");
+ File input = new File(dir, "signature.xml");
+ domVC = (DOMValidateContext)
+ TestUtils.getXMLValidateContext("DOM", input, "Reference");
}
- public void tearDown() {}
-
+ @org.junit.Test
public void testConstructor() throws Exception {
- assertNotNull(domVC);
- try {
- new DOMValidateContext(TestUtils.getPublicKey("RSA"), null);
- fail("Should throw a NPE for null node");
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should throw a NPE instead of " + ex + " for null node");
- }
- }
-
- public void testsetngetProperty() throws Exception {
- try {
- domVC.setProperty(null, "value");
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should throw a NPE instead of " + ex + " for null name");
- }
- try {
- domVC.getProperty(null);
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should throw a NPE instead of " + ex + " for null name");
- }
- String pname = "name";
- String pvalue1 = "value";
- String pvalue2 = "newvalue";
- assertNull(domVC.setProperty(pname, pvalue1));
- assertEquals((String)domVC.getProperty(pname), pvalue1);
- assertEquals(domVC.setProperty(pname, pvalue2), pvalue1);
- assertEquals((String)domVC.getProperty(pname), pvalue2);
- }
-
- public void testsetngetNode() throws Exception {
- try {
- domVC.setNode(null);
- } catch (NullPointerException npe) {
- } catch (Exception ex) {
- fail("Should throw a NPE instead of " + ex + " for null node");
- }
- assertNotNull(domVC.getNode());
+ assertNotNull(domVC);
+ try {
+ new DOMValidateContext(TestUtils.getPublicKey("RSA"), null);
+ fail("Should throw a NPE for null node");
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should throw a NPE instead of " + ex + " for null node");
+ }
+ }
+
+ @org.junit.Test
+ public void testSetGetProperty() throws Exception {
+ try {
+ domVC.setProperty(null, "value");
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should throw a NPE instead of " + ex + " for null name");
+ }
+ try {
+ domVC.getProperty(null);
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should throw a NPE instead of " + ex + " for null name");
+ }
+ String pname = "name";
+ String pvalue1 = "value";
+ String pvalue2 = "newvalue";
+ assertNull(domVC.setProperty(pname, pvalue1));
+ assertEquals((String)domVC.getProperty(pname), pvalue1);
+ assertEquals(domVC.setProperty(pname, pvalue2), pvalue1);
+ assertEquals((String)domVC.getProperty(pname), pvalue2);
+ }
+
+ @org.junit.Test
+ public void testSetGetNode() throws Exception {
+ try {
+ domVC.setNode(null);
+ } catch (NullPointerException npe) {
+ } catch (Exception ex) {
+ fail("Should throw a NPE instead of " + ex + " for null node");
+ }
+ assertNotNull(domVC.getNode());
}
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoFactoryTest.java Fri Jan 7 11:23:09 2011
@@ -26,172 +26,172 @@ import java.security.PublicKey;
import javax.xml.crypto.dsig.keyinfo.*;
import javax.xml.crypto.*;
-import junit.framework.*;
-
/**
* Unit test for javax.xml.crypto.dsig.keyinfo.KeyInfoFactory
*
* @version $Id$
* @author Valerie Peng
*/
-public class KeyInfoFactoryTest extends TestCase {
+public class KeyInfoFactoryTest extends org.junit.Assert {
KeyInfoFactory factory;
- public KeyInfoFactoryTest(String name) {
- super(name);
- }
-
- public void setUp() throws Exception {
- factory = KeyInfoFactory.getInstance
- ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
+ public KeyInfoFactoryTest() throws Exception {
+ factory = KeyInfoFactory.getInstance
+ ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
}
- public void tearDown() { }
-
+ @org.junit.Test
public void testgetInstance() {
- try {
- KeyInfoFactory.getInstance("non-existent");
- fail("Should throw NoSuchMechanismException if no impl found");
- } catch (NoSuchMechanismException ex) {}
-
- try {
- KeyInfoFactory.getInstance(null);
- fail("Should raise a NPE for null xmltype");
- } catch (NullPointerException npe) {}
+ try {
+ KeyInfoFactory.getInstance("non-existent");
+ fail("Should throw NoSuchMechanismException if no impl found");
+ } catch (NoSuchMechanismException ex) {}
+
+ try {
+ KeyInfoFactory.getInstance(null);
+ fail("Should raise a NPE for null xmltype");
+ } catch (NullPointerException npe) {}
}
+ @org.junit.Test
public void testgetMechanismType() {
- assertNotNull(factory);
- assertEquals("DOM", factory.getMechanismType());
+ assertNotNull(factory);
+ assertEquals("DOM", factory.getMechanismType());
}
-
+
+ @org.junit.Test
public void testisFeatureSupported() {
- try {
- factory.isFeatureSupported(null);
- fail("Should raise a NPE for null feature");
- } catch (NullPointerException npe) {}
+ try {
+ factory.isFeatureSupported(null);
+ fail("Should raise a NPE for null feature");
+ } catch (NullPointerException npe) {}
- assertTrue(!factory.isFeatureSupported("not supported"));
+ assertTrue(!factory.isFeatureSupported("not supported"));
}
+ @org.junit.Test
public void testnewKeyInfo() {
- String id = "keyId";
- // test newKeyInfo(List, String)
- KeyInfo ki = factory.newKeyInfo
- (Collections.singletonList(factory.newKeyName("foo")), id);
- assertEquals(id, ki.getId());
- try {
- ki = factory.newKeyInfo(null, id);
- fail("Should raise a NPE for null key info types");
- } catch (NullPointerException npe) {}
+ String id = "keyId";
+ // test newKeyInfo(List, String)
+ KeyInfo ki = factory.newKeyInfo
+ (Collections.singletonList(factory.newKeyName("foo")), id);
+ assertEquals(id, ki.getId());
+ try {
+ ki = factory.newKeyInfo(null, id);
+ fail("Should raise a NPE for null key info types");
+ } catch (NullPointerException npe) {}
}
+ @org.junit.Test
public void testnewKeyName() {
- final String name = "keyName";
- KeyName kn = factory.newKeyName(name);
- assertEquals(name, kn.getName());
- try {
- kn = factory.newKeyName(null);
- fail("Should raise a NPE for null key name");
- } catch (NullPointerException npe) {}
+ final String name = "keyName";
+ KeyName kn = factory.newKeyName(name);
+ assertEquals(name, kn.getName());
+ try {
+ kn = factory.newKeyName(null);
+ fail("Should raise a NPE for null key name");
+ } catch (NullPointerException npe) {}
}
+ @org.junit.Test
public void testnewKeyValue() {
- // test newKeyValue(PublicKey pk)
- PublicKey myPubKey = new PublicKey() {
- public byte[] getEncoded() {
- return new byte[20];
- }
- public String getFormat() {
- return "none";
- }
- public String getAlgorithm() {
- return "test";
- }
- };
- try {
- KeyValue kv = factory.newKeyValue(myPubKey);
- assertEquals(myPubKey, kv.getPublicKey());
- fail("Should throw a KeyException");
- } catch (KeyException ke) { }
+ // test newKeyValue(PublicKey pk)
+ PublicKey myPubKey = new PublicKey() {
+ public byte[] getEncoded() {
+ return new byte[20];
+ }
+ public String getFormat() {
+ return "none";
+ }
+ public String getAlgorithm() {
+ return "test";
+ }
+ };
+ try {
+ KeyValue kv = factory.newKeyValue(myPubKey);
+ assertEquals(myPubKey, kv.getPublicKey());
+ fail("Should throw a KeyException");
+ } catch (KeyException ke) { }
- try {
- factory.newKeyValue((PublicKey) null);
- fail("Should raise a NPE for null key");
- } catch (KeyException ke) {
- fail("Should raise a NPE for null key");
- } catch (NullPointerException npe) {}
+ try {
+ factory.newKeyValue((PublicKey) null);
+ fail("Should raise a NPE for null key");
+ } catch (KeyException ke) {
+ fail("Should raise a NPE for null key");
+ } catch (NullPointerException npe) {}
}
+ @org.junit.Test
public void testnewPGPKeyId() {
- byte[] valid_id = {
- 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08
- };
- byte[] invalid_id = {
- 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x08,
- 0x09
- };
- byte[] valid_packet = { (byte)0xc6, (byte)0x01, (byte)0x00 };
- byte[] invalid_packet = { (byte)0xc8, (byte)0x01, (byte)0x00 };
-
- // test newPGPData(byte[])
- PGPData pd = factory.newPGPData(valid_id);
- assertTrue(Arrays.equals(valid_id, pd.getKeyId()));
- try {
- pd = factory.newPGPData(invalid_id);
- fail("Should throw IAE for invalid key id values");
- } catch (IllegalArgumentException ex) {}
-
- // test newPGPData(byte[], byte[], List)
- pd = factory.newPGPData(valid_id, valid_packet, null);
- assertTrue(Arrays.equals(valid_id, pd.getKeyId()));
- assertTrue(Arrays.equals(valid_packet, pd.getKeyPacket()));
- try {
- pd = factory.newPGPData(invalid_id, valid_packet, null);
- fail("Should throw IAE for invalid key id values");
- } catch (IllegalArgumentException ex) {}
- try {
- pd = factory.newPGPData(valid_id, invalid_packet, null);
- fail("Should throw IAE for invalid key packet values");
- } catch (IllegalArgumentException ex) {}
- try {
- pd = factory.newPGPData(invalid_id, invalid_packet, null);
- fail("Should throw IAE for invalid key id and packet values");
- } catch (IllegalArgumentException ex) {}
-
- // test newPGPData(byte[], List)
- pd = factory.newPGPData(valid_packet, null);
- assertTrue(Arrays.equals(valid_packet, pd.getKeyPacket()));
- try {
- pd = factory.newPGPData(invalid_packet, null);
- fail("Should throw IAE for invalid key packet values");
- } catch (IllegalArgumentException ex) {}
+ byte[] valid_id = {
+ 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08
+ };
+ byte[] invalid_id = {
+ 0x01, 0x02, 0x03, 0x04,
+ 0x05, 0x06, 0x07, 0x08,
+ 0x09
+ };
+ byte[] valid_packet = { (byte)0xc6, (byte)0x01, (byte)0x00 };
+ byte[] invalid_packet = { (byte)0xc8, (byte)0x01, (byte)0x00 };
+
+ // test newPGPData(byte[])
+ PGPData pd = factory.newPGPData(valid_id);
+ assertTrue(Arrays.equals(valid_id, pd.getKeyId()));
+ try {
+ pd = factory.newPGPData(invalid_id);
+ fail("Should throw IAE for invalid key id values");
+ } catch (IllegalArgumentException ex) {}
+
+ // test newPGPData(byte[], byte[], List)
+ pd = factory.newPGPData(valid_id, valid_packet, null);
+ assertTrue(Arrays.equals(valid_id, pd.getKeyId()));
+ assertTrue(Arrays.equals(valid_packet, pd.getKeyPacket()));
+ try {
+ pd = factory.newPGPData(invalid_id, valid_packet, null);
+ fail("Should throw IAE for invalid key id values");
+ } catch (IllegalArgumentException ex) {}
+ try {
+ pd = factory.newPGPData(valid_id, invalid_packet, null);
+ fail("Should throw IAE for invalid key packet values");
+ } catch (IllegalArgumentException ex) {}
+ try {
+ pd = factory.newPGPData(invalid_id, invalid_packet, null);
+ fail("Should throw IAE for invalid key id and packet values");
+ } catch (IllegalArgumentException ex) {}
+
+ // test newPGPData(byte[], List)
+ pd = factory.newPGPData(valid_packet, null);
+ assertTrue(Arrays.equals(valid_packet, pd.getKeyPacket()));
+ try {
+ pd = factory.newPGPData(invalid_packet, null);
+ fail("Should throw IAE for invalid key packet values");
+ } catch (IllegalArgumentException ex) {}
}
+ @org.junit.Test
public void testnewRetrievalMethod() throws Exception {
final String uri = "#X509CertChain";
// test RetrievalMethod(String)
RetrievalMethod rm = factory.newRetrievalMethod(uri);
- assertEquals(uri, rm.getURI());
+ assertEquals(uri, rm.getURI());
- try {
- rm = factory.newRetrievalMethod(null);
- fail("Should raise a NPE for null URI");
- } catch (NullPointerException npe) {}
-
- // test RetrievalMethod(String, String, List)
- try {
- rm = factory.newRetrievalMethod(null, null, null);
- fail("Should raise a NPE for null URI");
- } catch (NullPointerException npe) {}
-
- String type = "http://www.w3.org/2000/09/xmldsig#X509Data";
- try {
- rm = factory.newRetrievalMethod(null, type, null);
- fail("Should raise a NPE for null URI");
+ try {
+ rm = factory.newRetrievalMethod(null);
+ fail("Should raise a NPE for null URI");
+ } catch (NullPointerException npe) {}
+
+ // test RetrievalMethod(String, String, List)
+ try {
+ rm = factory.newRetrievalMethod(null, null, null);
+ fail("Should raise a NPE for null URI");
+ } catch (NullPointerException npe) {}
+
+ String type = "http://www.w3.org/2000/09/xmldsig#X509Data";
+ try {
+ rm = factory.newRetrievalMethod(null, type, null);
+ fail("Should raise a NPE for null URI");
} catch (NullPointerException npe) {}
rm = factory.newRetrievalMethod(uri, type, null);
@@ -199,52 +199,48 @@ public class KeyInfoFactoryTest extends
assertEquals(type, rm.getType());
}
+ @org.junit.Test
public void testnewX509Data() {
- // test newX509Data(List)
- X509Data x509 =
- factory.newX509Data(Collections.singletonList("cn=foo"));
- assertNotNull(x509);
+ // test newX509Data(List)
+ X509Data x509 =
+ factory.newX509Data(Collections.singletonList("cn=foo"));
+ assertNotNull(x509);
}
+ @org.junit.Test
public void testnewX509IssuerSerial() {
- String name = "CN=valeriep";
- // test newX509IssuerSerial(String, BigInteger)
- X509IssuerSerial x509is = factory.newX509IssuerSerial(name,
- BigInteger.ONE);
- assertEquals(name, x509is.getIssuerName());
- assertEquals(BigInteger.ONE, x509is.getSerialNumber());
- try {
- x509is = factory.newX509IssuerSerial(null, BigInteger.ZERO);
- fail("Should raise an NPE for null issuer names");
- } catch (NullPointerException ex) {
- } catch (IllegalArgumentException ex2) {
- fail("Should throw NPE instead of IAE for null issuer names");
- }
- try {
- x509is = factory.newX509IssuerSerial(name, null);
- fail("Should raise an NPE for null serial numbers");
- } catch (NullPointerException ex) {
- } catch (IllegalArgumentException ex2) {
- fail("Should throw NPE instead of IAE for null serial numbers");
- }
- try {
- x509is = factory.newX509IssuerSerial(null, null);
- fail("Should raise an NPE for null issuer names/serial numbers");
- } catch (NullPointerException ex) {
- } catch (IllegalArgumentException ex2) {
- fail("Should throw NPE instead of IAE for null issuer " +
- "names/serial numbers");
- }
- try {
- x509is = factory.newX509IssuerSerial("valeriep", BigInteger.ZERO);
- fail("Should throw IAE for invalid issuer names");
- } catch (IllegalArgumentException ex) {}
- }
-
- // for debugging purposes
- public static void main(String[] args) throws Exception {
- KeyInfoFactoryTest kifTest =
- new KeyInfoFactoryTest("KeyInfoFactoryTest");
- kifTest.setUp();
+ String name = "CN=valeriep";
+ // test newX509IssuerSerial(String, BigInteger)
+ X509IssuerSerial x509is = factory.newX509IssuerSerial(name,
+ BigInteger.ONE);
+ assertEquals(name, x509is.getIssuerName());
+ assertEquals(BigInteger.ONE, x509is.getSerialNumber());
+ try {
+ x509is = factory.newX509IssuerSerial(null, BigInteger.ZERO);
+ fail("Should raise an NPE for null issuer names");
+ } catch (NullPointerException ex) {
+ } catch (IllegalArgumentException ex2) {
+ fail("Should throw NPE instead of IAE for null issuer names");
+ }
+ try {
+ x509is = factory.newX509IssuerSerial(name, null);
+ fail("Should raise an NPE for null serial numbers");
+ } catch (NullPointerException ex) {
+ } catch (IllegalArgumentException ex2) {
+ fail("Should throw NPE instead of IAE for null serial numbers");
+ }
+ try {
+ x509is = factory.newX509IssuerSerial(null, null);
+ fail("Should raise an NPE for null issuer names/serial numbers");
+ } catch (NullPointerException ex) {
+ } catch (IllegalArgumentException ex2) {
+ fail("Should throw NPE instead of IAE for null issuer " +
+ "names/serial numbers");
+ }
+ try {
+ x509is = factory.newX509IssuerSerial("valeriep", BigInteger.ZERO);
+ fail("Should throw IAE for invalid issuer names");
+ } catch (IllegalArgumentException ex) {}
}
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java Fri Jan 7 11:23:09 2011
@@ -28,92 +28,86 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.jcp.xml.dsig.internal.dom.DOMUtils;
-import junit.framework.*;
/**
* Unit test for javax.xml.crypto.dsig.keyinfo.KeyInfo
*
- * @version $Id$
* @author Valerie Peng
*/
-public class KeyInfoTest extends TestCase {
+public class KeyInfoTest extends org.junit.Assert {
private KeyInfoFactory fac;
- public KeyInfoTest() {
- super("KeyInfoTest");
+ public KeyInfoTest() throws Exception {
+ fac = KeyInfoFactory.getInstance
+ ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
}
- public KeyInfoTest(String name) {
- super(name);
- }
-
- public void setUp() throws Exception {
- fac = KeyInfoFactory.getInstance
- ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
- }
-
- public void tearDown() { }
-
+ @org.junit.Test
public void testgetId() {
- KeyInfo ki = fac.newKeyInfo
- (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
- assertNotNull(ki.getId());
+ KeyInfo ki = fac.newKeyInfo
+ (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
+ assertNotNull(ki.getId());
}
+ @org.junit.Test
+ @SuppressWarnings("unchecked")
public void testgetContent() {
- KeyInfo[] infos = new KeyInfo[2];
- infos[0] = fac.newKeyInfo
- (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
- infos[1] = fac.newKeyInfo
- (Collections.singletonList(fac.newKeyName("foo")));
- for (int j=0; j < infos.length; j++) {
- KeyInfo ki = infos[j];
- List li = ki.getContent();
- assertNotNull(ki.getContent());
- if (!li.isEmpty()) {
- Object[] content = li.toArray();
- for (int i=0; i<content.length; i++) {
- if (!(content[i] instanceof XMLStructure)) {
- fail("KeyInfo element has the wrong type");
- };
- }
- } else {
- try {
- li.add(new Object());
- fail("Added KeyInfo element of wrong type");
- } catch (ClassCastException ex) {
- // expected
- }
- }
- }
+ KeyInfo[] infos = new KeyInfo[2];
+ infos[0] = fac.newKeyInfo
+ (Collections.singletonList(fac.newKeyName("foo")), "skeleton");
+ infos[1] = fac.newKeyInfo
+ (Collections.singletonList(fac.newKeyName("foo")));
+ for (int j = 0; j < infos.length; j++) {
+ KeyInfo ki = infos[j];
+ List li = ki.getContent();
+ assertNotNull(ki.getContent());
+ if (!li.isEmpty()) {
+ Object[] content = li.toArray();
+ for (int i = 0; i < content.length; i++) {
+ if (!(content[i] instanceof XMLStructure)) {
+ fail("KeyInfo element has the wrong type");
+ };
+ }
+ } else {
+ try {
+ li.add(new Object());
+ fail("Added KeyInfo element of wrong type");
+ } catch (ClassCastException ex) {
+ // expected
+ }
+ }
+ }
}
+ @org.junit.Test
public void testConstructor() {
- final String id = "keyId";
- // test newKeyInfo(List, String id)
- KeyInfo ki = fac.newKeyInfo
- (Collections.singletonList(fac.newKeyName("foo")), id);
- assertEquals(id, ki.getId());
- try {
- ki = fac.newKeyInfo(null, id);
- fail("Should raise a NullPointerException");
- } catch (NullPointerException npe) {}
- // test newKeyInfo(List)
- ki = fac.newKeyInfo(Collections.singletonList(fac.newKeyName("foo")));
+ final String id = "keyId";
+ // test newKeyInfo(List, String id)
+ KeyInfo ki = fac.newKeyInfo
+ (Collections.singletonList(fac.newKeyName("foo")), id);
+ assertEquals(id, ki.getId());
+ try {
+ ki = fac.newKeyInfo(null, id);
+ fail("Should raise a NullPointerException");
+ } catch (NullPointerException npe) {}
+ // test newKeyInfo(List)
+ ki = fac.newKeyInfo(Collections.singletonList(fac.newKeyName("foo")));
}
+ @org.junit.Test
public void testisFeatureSupported() {
- KeyInfo ki = fac.newKeyInfo
- (Collections.singletonList(fac.newKeyName("foo")), "keyid");
- try {
- ki.isFeatureSupported(null);
- fail("Should raise a NPE for null feature");
- } catch (NullPointerException npe) {}
+ KeyInfo ki = fac.newKeyInfo
+ (Collections.singletonList(fac.newKeyName("foo")), "keyid");
+ try {
+ ki.isFeatureSupported(null);
+ fail("Should raise a NPE for null feature");
+ } catch (NullPointerException npe) {}
- assertTrue(!ki.isFeatureSupported("not supported"));
+ assertTrue(!ki.isFeatureSupported("not supported"));
}
+ @org.junit.Test
public void testMarshal() throws Exception {
KeyInfo ki = fac.newKeyInfo
(Collections.singletonList(fac.newKeyName("foo")), "keyid");
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java?rev=1056263&r1=1056262&r2=1056263&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyNameTest.java Fri Jan 7 11:23:09 2011
@@ -21,55 +21,45 @@ package javax.xml.crypto.test.dsig.keyin
import javax.xml.crypto.dsig.keyinfo.*;
-import junit.framework.*;
-
/**
* Unit test for javax.xml.crypto.dsig.keyinfo.KeyName
*
- * @version $Id$
* @author Sean Mullan
*/
-public class KeyNameTest extends TestCase {
+public class KeyNameTest extends org.junit.Assert {
private KeyInfoFactory fac;
- public KeyNameTest() {
- super("KeyNameTest");
- }
-
- public KeyNameTest(String name) {
- super(name);
+ public KeyNameTest() throws Exception {
+ fac = KeyInfoFactory.getInstance
+ ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
}
- public void setUp() throws Exception {
- fac = KeyInfoFactory.getInstance
- ("DOM", new org.jcp.xml.dsig.internal.dom.XMLDSigRI());
- }
-
- public void tearDown() { }
-
+ @org.junit.Test
public void testgetName() {
- KeyName kn = fac.newKeyName("skeleton");
- assertNotNull(kn.getName());
+ KeyName kn = fac.newKeyName("skeleton");
+ assertNotNull(kn.getName());
}
+ @org.junit.Test
public void testConstructor() {
- final String name = "keyName";
- KeyName kn = fac.newKeyName(name);
- assertEquals(name, kn.getName());
- try {
- kn = fac.newKeyName(null);
- fail("Should raise a NullPointerException");
- } catch (NullPointerException npe) {}
+ final String name = "keyName";
+ KeyName kn = fac.newKeyName(name);
+ assertEquals(name, kn.getName());
+ try {
+ kn = fac.newKeyName(null);
+ fail("Should raise a NullPointerException");
+ } catch (NullPointerException npe) {}
}
+ @org.junit.Test
public void testisFeatureSupported() {
- KeyName kn = fac.newKeyName("keyName");
- try {
- kn.isFeatureSupported(null);
- fail("Should raise a NPE for null feature");
- } catch (NullPointerException npe) {}
+ KeyName kn = fac.newKeyName("keyName");
+ try {
+ kn.isFeatureSupported(null);
+ fail("Should raise a NPE for null feature");
+ } catch (NullPointerException npe) {}
- assertTrue(!kn.isFeatureSupported("not supported"));
+ assertTrue(!kn.isFeatureSupported("not supported"));
}
}