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/14 12:52:57 UTC
svn commit: r1058967 - in
/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys:
content/x509/ keyresolver/ storage/
Author: coheigea
Date: Fri Jan 14 11:52:56 2011
New Revision: 1058967
URL: http://svn.apache.org/viewvc?rev=1058967&view=rev
Log:
[SANTUARIO-257] - More work on the tests.
Modified:
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509CertificateTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509IssuerSerialTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509SKITest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/keyresolver/KeyResolverTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/KeyStoreResolverTest.java
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/StorageResolverTest.java
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509CertificateTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509CertificateTest.java?rev=1058967&r1=1058966&r2=1058967&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509CertificateTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509CertificateTest.java Fri Jan 14 11:52:56 2011
@@ -24,37 +24,21 @@ import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.apache.xml.security.keys.content.x509.XMLX509Certificate;
import org.apache.xml.security.utils.Constants;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
/**
* Certificate parsing test.
*
* @author Sean Mullan
*/
-public class XMLX509CertificateTest extends TestCase {
+public class XMLX509CertificateTest extends org.junit.Assert {
private static final String BASEDIR =
System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
- public XMLX509CertificateTest() {
- super("XMLX509CertificateTest");
- }
-
- public XMLX509CertificateTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(XMLX509CertificateTest.class);
- }
-
+ @org.junit.Test
public void testGetX509Certificate() throws Exception {
-
- File f = null;
- f = new File(BASEDIR + SEP + "data" + SEP + "ie" + SEP + "baltimore" +
+ File f = new File(BASEDIR + SEP + "data" + SEP + "ie" + SEP + "baltimore" +
SEP + "merlin-examples" + SEP + "merlin-xmldsig-twenty-three" +
SEP + "signature-x509-crt.xml");
@@ -69,4 +53,5 @@ public class XMLX509CertificateTest exte
xmlCert.getX509Certificate();
// System.out.println(cert);
}
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509IssuerSerialTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509IssuerSerialTest.java?rev=1058967&r1=1058966&r2=1058967&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509IssuerSerialTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509IssuerSerialTest.java Fri Jan 14 11:52:56 2011
@@ -19,39 +19,24 @@ package org.apache.xml.security.test.key
import javax.xml.parsers.*;
import org.w3c.dom.Document;
import org.apache.xml.security.keys.content.x509.XMLX509IssuerSerial;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
/**
* XMLX509IssuerSerial tests.
*
* @author Sean Mullan
*/
-public class XMLX509IssuerSerialTest extends TestCase {
+public class XMLX509IssuerSerialTest extends org.junit.Assert {
private Document doc;
- public XMLX509IssuerSerialTest() {
- super("XMLX509IssuerSerialTest");
- }
-
- public XMLX509IssuerSerialTest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(XMLX509IssuerSerialTest.class);
- }
-
- public void setUp() throws Exception {
+ public XMLX509IssuerSerialTest() throws Exception {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
doc = dbf.newDocumentBuilder().newDocument();
}
+ @org.junit.Test
public void testGetIssuerName() throws Exception {
-
// Make sure hex encoded value is not escaped (see ...)
String issuer = "9.99.999=#abc123";
XMLX509IssuerSerial is =
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509SKITest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509SKITest.java?rev=1058967&r1=1058966&r2=1058967&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509SKITest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/content/x509/XMLX509SKITest.java Fri Jan 14 11:52:56 2011
@@ -22,37 +22,22 @@ import java.security.cert.*;
import java.util.Collection;
import java.util.Collections;
import org.apache.xml.security.keys.content.x509.XMLX509SKI;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
/**
* Test bugfix 41892: XML Security 1.4.0 does not build with IBM's JDK
*/
-public class XMLX509SKITest extends TestCase {
+public class XMLX509SKITest extends org.junit.Assert {
private static final String BASEDIR = System.getProperty("basedir");
private static final String SEP = System.getProperty("file.separator");
private CertificateFactory cf;
- public XMLX509SKITest() {
- super("XMLX509SKITest");
- }
-
- public XMLX509SKITest(String name) {
- super(name);
- }
-
- public static Test suite() {
- return new TestSuite(XMLX509SKITest.class);
- }
-
- public void setUp() throws Exception {
+ public XMLX509SKITest() throws Exception {
cf = CertificateFactory.getInstance("X.509");
}
+ @org.junit.Test
public void testGetSKIBytesFromCert() throws Exception {
-
File f = null;
if (BASEDIR != null && !"".equals(BASEDIR)) {
f = new File(BASEDIR + SEP +
@@ -82,7 +67,7 @@ public class XMLX509SKITest extends Test
"Collection",
new CollectionCertStoreParameters(Collections.singleton(cert)));
- Collection certs = cs.getCertificates(xcs);
+ Collection<?> certs = cs.getCertificates(xcs);
assertTrue(!certs.isEmpty());
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/keyresolver/KeyResolverTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/keyresolver/KeyResolverTest.java?rev=1058967&r1=1058966&r2=1058967&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/keyresolver/KeyResolverTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/keyresolver/KeyResolverTest.java Fri Jan 14 11:52:56 2011
@@ -31,10 +31,6 @@ import javax.crypto.spec.SecretKeySpec;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.xml.security.algorithms.JCEMapper;
import org.apache.xml.security.encryption.EncryptedData;
import org.apache.xml.security.encryption.EncryptedKey;
@@ -52,27 +48,19 @@ import org.w3c.dom.Text;
/**
* KeyResolver test.
*/
-public class KeyResolverTest extends TestCase {
+public class KeyResolverTest extends org.junit.Assert {
public KeyResolverTest() {
- super("KeyResolverTest");
- }
-
- public KeyResolverTest(String name) {
- super(name);
org.apache.xml.security.Init.init();
}
- public static Test suite() {
- return new TestSuite(KeyResolverTest.class);
- }
-
/**
* Encrypt some data, embedded the data encryption key
* in the message using the key transport algorithm rsa-1_5.
* Decrypt the data by resolving the Key Encryption Key.
* This test verifies if a KeyResolver can return a PrivateKey.
*/
+ @org.junit.Test
public void testResolvePrivateKey() throws Exception {
// See if AES-128 is available...
String algorithmId =
@@ -86,7 +74,9 @@ public class KeyResolverTest extends Tes
haveAES = true;
}
} catch (NoSuchAlgorithmException nsae) {
+ //
} catch (NoSuchPaddingException nspe) {
+ //
}
}
@@ -183,17 +173,15 @@ public class KeyResolverTest extends Tes
private static PrivateKey pk;
private static String pkName;
- public boolean engineCanResolve(Element element, String BaseURI,
- StorageResolver storage) {
+ public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
return false;
}
- public PrivateKey engineLookupAndResolvePrivateKey(Element element,
- String BaseURI, StorageResolver storage)
- throws KeyResolverException {
-
+ public PrivateKey engineLookupAndResolvePrivateKey(
+ Element element, String BaseURI, StorageResolver storage
+ ) throws KeyResolverException {
if (Constants.SignatureSpecNS.equals(element.getNamespaceURI()) &&
- Constants._TAG_KEYNAME.equals(element.getLocalName())) {
+ Constants._TAG_KEYNAME.equals(element.getLocalName())) {
String keyName = element.getFirstChild().getNodeValue();
if (pkName.equals(keyName)) {
return pk;
@@ -203,4 +191,5 @@ public class KeyResolverTest extends Tes
return null;
}
}
+
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/KeyStoreResolverTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/KeyStoreResolverTest.java?rev=1058967&r1=1058966&r2=1058967&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/KeyStoreResolverTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/KeyStoreResolverTest.java Fri Jan 14 11:52:56 2011
@@ -22,84 +22,70 @@ import java.security.cert.X509Certificat
import java.util.Iterator;
import java.util.NoSuchElementException;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.xml.security.keys.storage.implementations.KeyStoreResolver;
/**
* KeyStore StorageResolver test.
*/
-public class KeyStoreResolverTest extends TestCase {
-
- private static final String BASEDIR =
- System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
- private static final String SEP = System.getProperty("file.separator");
+public class KeyStoreResolverTest extends org.junit.Assert {
- public KeyStoreResolverTest() {
- super("KeyStoreResolverTest");
- }
-
- public KeyStoreResolverTest(String name) {
- super(name);
+ private static final String BASEDIR =
+ System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
+ private static final String SEP = System.getProperty("file.separator");
+
+ @org.junit.Test
+ public void testKeyStoreResolver() throws Exception {
+ FileInputStream f =
+ new FileInputStream(BASEDIR + SEP + "data" + SEP + "org" + SEP + "apache"
+ + SEP + "xml" + SEP + "security" + SEP + "samples"
+ + SEP + "input" + SEP + "keystore2.jks");
+
+ KeyStore ks = KeyStore.getInstance("JCEKS");
+ ks.load(f, "xmlsecurity".toCharArray());
+
+ KeyStoreResolver ksResolver = new KeyStoreResolver(ks);
+ Iterator<?> iter = ksResolver.getIterator();
+ checkIterator(iter);
+
+ // check new iterator starts from the beginning
+ Iterator<?> iter2 = ksResolver.getIterator();
+ checkIterator(iter2);
+
+ // check the iterators are independent
+ // check calling next() without calling hasNext()
+ iter = ksResolver.getIterator();
+ iter2 = ksResolver.getIterator();
+
+ while (iter.hasNext()) {
+ X509Certificate cert = (X509Certificate) iter.next();
+ X509Certificate cert2 = (X509Certificate) iter2.next();
+ if (!cert.equals(cert2)) {
+ fail("KeyStoreResolver iterators are not independent");
+ }
}
+ assertFalse(iter2.hasNext());
+ }
- public static Test suite() {
- return new TestSuite(KeyStoreResolverTest.class);
+ private void checkIterator(Iterator<?> iter) {
+ int count = 0;
+ iter.hasNext(); // hasNext() is idempotent
+
+ while (iter.hasNext()) {
+ X509Certificate cert = (X509Certificate) iter.next();
+ cert.getSubjectDN().getName();
+ count++;
}
- public void testKeyStoreResolver() throws Exception {
+ // The iterator skipped over symmetric keys
+ assertEquals(3, count);
- FileInputStream f = new FileInputStream(BASEDIR + SEP + "data" + SEP
- + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" + SEP
- + "samples" + SEP + "input" + SEP + "keystore2.jks");
-
- KeyStore ks = KeyStore.getInstance("JCEKS");
- ks.load(f, "xmlsecurity".toCharArray());
-
- KeyStoreResolver ksResolver = new KeyStoreResolver(ks);
- Iterator iter = ksResolver.getIterator();
- checkIterator(iter);
-
- // check new iterator starts from the beginning
- Iterator iter2 = ksResolver.getIterator();
- checkIterator(iter2);
-
- // check the iterators are independent
- // check calling next() without calling hasNext()
- iter = ksResolver.getIterator();
- iter2 = ksResolver.getIterator();
-
- while (iter.hasNext()) {
- X509Certificate cert = (X509Certificate) iter.next();
- X509Certificate cert2 = (X509Certificate) iter2.next();
- if (!cert.equals(cert2)) {
- fail("KeyStoreResolver iterators are not independent");
- }
- }
- assertFalse(iter2.hasNext());
+ // Cannot go beyond last element
+ try {
+ iter.next();
+ fail("Expecting NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ //
}
-
- private void checkIterator(Iterator iter) {
- int count = 0;
- iter.hasNext(); // hasNext() is idempotent
-
- while (iter.hasNext()) {
- X509Certificate cert = (X509Certificate) iter.next();
- cert.getSubjectDN().getName();
- count++;
- }
-
- // The iterator skipped over symmetric keys
- assertEquals(3, count);
+ }
- // Cannot go beyond last element
- try {
- iter.next();
- fail("Expecting NoSuchElementException");
- } catch (NoSuchElementException e) {
- }
- }
-
}
Modified: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/StorageResolverTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/StorageResolverTest.java?rev=1058967&r1=1058966&r2=1058967&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/StorageResolverTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/keys/storage/StorageResolverTest.java Fri Jan 14 11:52:56 2011
@@ -22,107 +22,94 @@ import java.security.cert.X509Certificat
import java.util.Iterator;
import java.util.NoSuchElementException;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.apache.xml.security.keys.storage.StorageResolver;
/**
* KeyStore StorageResolver test.
*/
-public class StorageResolverTest extends TestCase {
-
- private static final String BASEDIR =
- System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
- private static final String SEP = System.getProperty("file.separator");
+public class StorageResolverTest extends org.junit.Assert {
- public StorageResolverTest() {
- super("KeyStoreResolverTest");
+ private static final String BASEDIR =
+ System.getProperty("basedir") == null ? "./": System.getProperty("basedir");
+ private static final String SEP = System.getProperty("file.separator");
+
+ @org.junit.Test
+ @SuppressWarnings("deprecation")
+ public void testStorageResolver() throws Exception {
+
+ String inputDir = BASEDIR + SEP + "data" + SEP
+ + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" + SEP
+ + "samples" + SEP + "input";
+
+ FileInputStream inStream = new FileInputStream(inputDir + SEP + "keystore.jks");
+ KeyStore ks = KeyStore.getInstance("JKS");
+ ks.load(inStream, "xmlsecurity".toCharArray());
+
+ FileInputStream inStream2 = new FileInputStream(inputDir + SEP + "keystore2.jks");
+ KeyStore ks2 = KeyStore.getInstance("JCEKS");
+ ks2.load(inStream2, "xmlsecurity".toCharArray());
+
+ StorageResolver storage = new StorageResolver(ks);
+ storage.add(ks2);
+
+ // iterate directly on the storage
+ int count = 0;
+ while (storage.hasNext()) {
+ X509Certificate cert = storage.next();
+ assertNotNull(cert);
+ count++;
}
- public StorageResolverTest(String name) {
- super(name);
- }
+ assertEquals(4, count);
- public static Test suite() {
- return new TestSuite(StorageResolverTest.class);
+ try {
+ storage.next();
+ fail("Expecting NoSuchElementException");
+ } catch (NoSuchElementException e) {
}
- public void testStorageResolver() throws Exception {
+ Iterator<?> iter = storage.getIterator();
+ checkIterator(iter);
- String inputDir = BASEDIR + SEP + "data" + SEP
- + "org" + SEP + "apache" + SEP + "xml" + SEP + "security" + SEP
- + "samples" + SEP + "input";
-
- FileInputStream inStream = new FileInputStream(inputDir + SEP + "keystore.jks");
- KeyStore ks = KeyStore.getInstance("JKS");
- ks.load(inStream, "xmlsecurity".toCharArray());
-
- FileInputStream inStream2 = new FileInputStream(inputDir + SEP + "keystore2.jks");
- KeyStore ks2 = KeyStore.getInstance("JCEKS");
- ks2.load(inStream2, "xmlsecurity".toCharArray());
-
- StorageResolver storage = new StorageResolver(ks);
- storage.add(ks2);
-
- // iterate directly on the storage
- int count = 0;
- while (storage.hasNext()) {
- X509Certificate cert = storage.next();
- assertNotNull(cert);
- count++;
- }
-
- assertEquals(4, count);
-
- try {
- storage.next();
- fail("Expecting NoSuchElementException");
- } catch (NoSuchElementException e) {
- }
-
- Iterator iter = storage.getIterator();
- checkIterator(iter);
-
- // check new iterator starts from the beginning
- Iterator iter2 = storage.getIterator();
- checkIterator(iter2);
-
- // check the iterators are independent
- // check calling next() without calling hasNext()
- iter = storage.getIterator();
- iter2 = storage.getIterator();
-
- while (iter.hasNext()) {
- X509Certificate cert = (X509Certificate) iter.next();
- X509Certificate cert2 = (X509Certificate) iter2.next();
- if (!cert.equals(cert2)) {
- fail("StorageResolver iterators are not independent");
- }
- }
- assertFalse(iter2.hasNext());
+ // check new iterator starts from the beginning
+ Iterator<?> iter2 = storage.getIterator();
+ checkIterator(iter2);
+
+ // check the iterators are independent
+ // check calling next() without calling hasNext()
+ iter = storage.getIterator();
+ iter2 = storage.getIterator();
+
+ while (iter.hasNext()) {
+ X509Certificate cert = (X509Certificate) iter.next();
+ X509Certificate cert2 = (X509Certificate) iter2.next();
+ if (!cert.equals(cert2)) {
+ fail("StorageResolver iterators are not independent");
+ }
}
+ assertFalse(iter2.hasNext());
+ }
+
+ private void checkIterator(Iterator<?> iter) {
+ int count = 0;
+ iter.hasNext(); // hasNext() is idempotent
+
+ while (iter.hasNext()) {
+ X509Certificate cert = (X509Certificate) iter.next();
+ cert.getSubjectDN().getName();
+ count++;
+ }
+
+ // The iterator skipped over symmetric keys
+ assertEquals(4, count);
- private void checkIterator(Iterator iter) {
- int count = 0;
- iter.hasNext(); // hasNext() is idempotent
-
- while (iter.hasNext()) {
- X509Certificate cert = (X509Certificate) iter.next();
- cert.getSubjectDN().getName();
- count++;
- }
-
- // The iterator skipped over symmetric keys
- assertEquals(4, count);
-
- // Cannot go beyond last element
- try {
- iter.next();
- fail("Expecting NoSuchElementException");
- } catch (NoSuchElementException e) {
- }
+ // Cannot go beyond last element
+ try {
+ iter.next();
+ fail("Expecting NoSuchElementException");
+ } catch (NoSuchElementException e) {
+ //
}
+ }
}