You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2014/10/29 20:18:45 UTC
svn commit: r1635262 - in
/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test: ./
dsig/ dsig/keyinfo/
Author: mullan
Date: Wed Oct 29 19:18:44 2014
New Revision: 1635262
URL: http://svn.apache.org/r1635262
Log:
Modify tests to follow better practices with Generics. Take into consideration
both cases in which the API/implementation may be using Generics or raw types. Add SuppressWarnings annotations where appropriate.
Modified:
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/KeySelectors.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/CreateInteropXFilter2Test.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/DetachedTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ManifestTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ReferenceTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertiesTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertyTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignatureValidator.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignedInfoTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/X509KeySelector.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLObjectTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/XMLSignatureTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/KeySelectors.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/KeySelectors.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/KeySelectors.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/KeySelectors.java Wed Oct 29 19:18:44 2014
@@ -95,9 +95,10 @@ public class KeySelectors {
throw new KeySelectorException("Null KeyInfo object!");
}
// search for X509Data in keyinfo
- Iterator<?> iter = keyInfo.getContent().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<XMLStructure> iter = keyInfo.getContent().iterator();
while (iter.hasNext()) {
- XMLStructure kiType = (XMLStructure) iter.next();
+ XMLStructure kiType = iter.next();
if (kiType instanceof X509Data) {
X509Data xd = (X509Data) kiType;
Object[] entries = xd.getContent().toArray();
@@ -108,7 +109,8 @@ public class KeySelectors {
crl = (X509CRL) entries[i];
}
}
- Iterator<?> xi = xd.getContent().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<Object> xi = xd.getContent().iterator();
while (xi.hasNext()) {
Object o = xi.next();
// skip non-X509Certificate entries
@@ -144,10 +146,10 @@ public class KeySelectors {
if (keyInfo == null) {
throw new KeySelectorException("Null KeyInfo object!");
}
- List<?> list = keyInfo.getContent();
+ @SuppressWarnings("unchecked")
+ List<XMLStructure> list = keyInfo.getContent();
- for (int i = 0; i < list.size(); i++) {
- XMLStructure xmlStructure = (XMLStructure) list.get(i);
+ for (XMLStructure xmlStructure : list) {
if (xmlStructure instanceof KeyValue) {
PublicKey pk = null;
try {
@@ -253,9 +255,10 @@ public class KeySelectors {
if (keyInfo == null) {
throw new KeySelectorException("Null KeyInfo object!");
}
- Iterator<?> iter = keyInfo.getContent().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<XMLStructure> iter = keyInfo.getContent().iterator();
while (iter.hasNext()) {
- XMLStructure xmlStructure = (XMLStructure) iter.next();
+ XMLStructure xmlStructure = iter.next();
try {
if (xmlStructure instanceof KeyName) {
String name = ((KeyName)xmlStructure).getName();
@@ -298,7 +301,8 @@ public class KeySelectors {
("Unsupported RetrievalMethod type");
}
} else if (xmlStructure instanceof X509Data) {
- List<?> content = ((X509Data)xmlStructure).getContent();
+ @SuppressWarnings("unchecked")
+ List<Object> content = ((X509Data)xmlStructure).getContent();
int size = content.size();
List<X509Certificate> result = null;
// Lookup the public key using the information
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/CreateInteropXFilter2Test.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/CreateInteropXFilter2Test.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/CreateInteropXFilter2Test.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/CreateInteropXFilter2Test.java Wed Oct 29 19:18:44 2014
@@ -26,6 +26,7 @@ import java.security.*;
import java.security.cert.Certificate;
import java.util.*;
+import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.*;
import javax.xml.crypto.dsig.dom.*;
import javax.xml.crypto.dsig.keyinfo.*;
@@ -111,7 +112,7 @@ public class CreateInteropXFilter2Test e
fac.newSignatureMethod(SignatureMethod.DSA_SHA1, null), refs);
// create KeyInfo
- List<Object> kits = new ArrayList<Object>(2);
+ List<XMLStructure> kits = new ArrayList<XMLStructure>(2);
kits.add(kifac.newKeyValue(validatingKey));
List<Object> xds = new ArrayList<Object>(2);
xds.add("CN=Sean Mullan, DC=sun, DC=com");
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/DetachedTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/DetachedTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/DetachedTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/DetachedTest.java Wed Oct 29 19:18:44 2014
@@ -159,9 +159,10 @@ public class DetachedTest extends org.ju
// Check core validation status
if (coreValidity == false) {
// check the validation status of each Reference
- Iterator<?> i = signature.getSignedInfo().getReferences().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<Reference> i = signature.getSignedInfo().getReferences().iterator();
while (i.hasNext()) {
- Reference reference = (Reference) i.next();
+ Reference reference = i.next();
reference.validate(vc);
}
fail("Signature failed core validation");
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ManifestTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ManifestTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ManifestTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ManifestTest.java Wed Oct 29 19:18:44 2014
@@ -47,7 +47,7 @@ public class ManifestTest extends org.ju
public void testConstructor() throws Exception {
Manifest man = null;
String id = "manifest_id";
- List<Object> refs = new Vector<Object>();
+ List<Reference> refs = new Vector<Reference>();
// test XMLSignatureFactory.newManifest(List references)
// and XMLSignatureFactory.newManifest(List references,
// String id)
@@ -111,9 +111,12 @@ public class ManifestTest extends org.ju
" for empty references");
}
- refs.add("references");
+ // use raw List type to test for invalid Reference entries
+ List invalidRefs = new Vector();
+ addEntryToRawList(invalidRefs, "references");
try {
- man = fac.newManifest(refs);
+ @SuppressWarnings("unchecked")
+ Manifest man2 = fac.newManifest(invalidRefs);
fail("Should throw a CCE for references containing " +
"non-Reference objects");
} catch (ClassCastException cce) {
@@ -123,14 +126,15 @@ public class ManifestTest extends org.ju
}
try {
- man = fac.newManifest(refs, id);
+ @SuppressWarnings("unchecked")
+ Manifest man2 = fac.newManifest(invalidRefs, id);
fail("Should throw a CCE for references containing " +
"non-Reference objects");
} catch (ClassCastException cce) {
} catch (Exception ex) {
fail("Should throw a CCE instead of " + ex +
" for references containing non-Reference objects");
- }
+ }
}
@org.junit.Test
@@ -149,23 +153,27 @@ public class ManifestTest extends org.ju
}
@org.junit.Test
- @SuppressWarnings("unchecked")
public void testgetReferences() throws Exception {
List<Reference> refs = new Vector<Reference>();
refs.add(VALID_REF);
Manifest man = fac.newManifest(refs);
- List<Object> stored = man.getReferences();
+ @SuppressWarnings("unchecked")
+ List<Reference> stored = man.getReferences();
try {
stored.add(INVALID_REF);
fail("Should not be able to modify the references directly");
} catch (UnsupportedOperationException ex) {
}
try {
- ListIterator<Object> li = stored.listIterator();
+ ListIterator<Reference> li = stored.listIterator();
li.add(INVALID_REF);
fail("Should not be able to modify the references indirectly");
} catch (UnsupportedOperationException ex) {
}
}
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ReferenceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ReferenceTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ReferenceTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/ReferenceTest.java Wed Oct 29 19:18:44 2014
@@ -123,7 +123,7 @@ public class ReferenceTest extends org.j
fail("Unexpected Exception: " + ex);
}
- List<Object> transforms = new Vector<Object>();
+ List<Transform> transforms = new Vector<Transform>();
try {
// try empty transforms list
ref = fac.newReference(uri, dmSHA1, transforms,
@@ -133,10 +133,12 @@ public class ReferenceTest extends org.j
} catch(Exception ex) {
fail("Unexpected Exception: " + ex);
}
- transforms.add(new Object());
+ List invalidTransforms = new Vector();
+ addEntryToRawList(invalidTransforms, new Object());
try {
// try a transforms list with an invalid object
- ref = fac.newReference(uri, dmSHA1, transforms,
+ @SuppressWarnings("unchecked")
+ Reference ref2 = fac.newReference(uri, dmSHA1, invalidTransforms,
type, id);
} catch (ClassCastException cce) {
} catch (Exception ex) {
@@ -145,11 +147,12 @@ public class ReferenceTest extends org.j
// Test with various composition of Transform list
// 1. String only
- transforms.clear();
- transforms.add(Transform.BASE64);
+ invalidTransforms.clear();
+ addEntryToRawList(invalidTransforms, Transform.BASE64);
try {
// try a transforms list with a String object
- ref = fac.newReference(uri, dmSHA1, transforms,
+ @SuppressWarnings("unchecked")
+ Reference ref2 = fac.newReference(uri, dmSHA1, invalidTransforms,
type, id);
fail("Should throw a CCE for illegal transforms");
} catch (ClassCastException cce) {
@@ -248,9 +251,10 @@ public class ReferenceTest extends org.j
boolean result = sig.validate(validateContext);
assertTrue(result);
- Iterator<?> iter = sig.getSignedInfo().getReferences().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<Reference> iter = sig.getSignedInfo().getReferences().iterator();
while (iter.hasNext()) {
- Reference validated_ref = (Reference) iter.next();
+ Reference validated_ref = iter.next();
if (!cache) {
assertNull(validated_ref.getDereferencedData());
assertNull(validated_ref.getDigestInputStream());
@@ -281,4 +285,9 @@ public class ReferenceTest extends org.j
}
return Arrays.equals(md.digest(), ref.getDigestValue());
}
+
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertiesTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertiesTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertiesTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertiesTest.java Wed Oct 29 19:18:44 2014
@@ -44,7 +44,6 @@ public class SignaturePropertiesTest ext
}
@org.junit.Test
- @SuppressWarnings("unchecked")
public void testConstructor() {
// test XMLSignatureFactory.newSignatureProperties(List, String)
SignatureProperties props;
@@ -57,7 +56,7 @@ public class SignaturePropertiesTest ext
fail("Should raise a NPE for null content instead of " + ex);
}
- List<Object> list = new Vector<Object>();
+ List<SignatureProperty> list = new Vector<SignatureProperty>();
try {
props = factory.newSignatureProperties(list, id);
fail("Should raise an IAE for empty content");
@@ -67,9 +66,12 @@ public class SignaturePropertiesTest ext
}
String strEntry = "wrong type";
- list.add(strEntry);
+ // use raw List type to test for invalid SignatureProperty types
+ List invalidList = new Vector();
+ addEntryToRawList(invalidList, strEntry);
try {
- props = factory.newSignatureProperties(list, id);
+ @SuppressWarnings("unchecked")
+ SignatureProperties props2 = factory.newSignatureProperties(invalidList, id);
fail("Should raise a CCE for content containing " +
"invalid, i.e. non-SignatureProperty, entries");
} catch (ClassCastException cce) {
@@ -79,11 +81,11 @@ public class SignaturePropertiesTest ext
"instead of " + ex);
}
- list.remove(strEntry);
list.add(prop);
props = factory.newSignatureProperties(list, id);
assertNotNull(props);
- List<Object> unmodifiable = props.getProperties();
+ @SuppressWarnings("unchecked")
+ List<SignatureProperty> unmodifiable = props.getProperties();
assertNotNull(unmodifiable);
try {
unmodifiable.add(prop);
@@ -96,7 +98,7 @@ public class SignaturePropertiesTest ext
@org.junit.Test
public void testisFeatureSupported() {
- List<Object> list = new Vector<Object>();
+ List<SignatureProperty> list = new Vector<SignatureProperty>();
list.add(prop);
SignatureProperties props = factory.newSignatureProperties(list, id);
try {
@@ -107,4 +109,8 @@ public class SignaturePropertiesTest ext
assertTrue(!props.isFeatureSupported("not supported"));
}
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertyTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertyTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertyTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignaturePropertyTest.java Wed Oct 29 19:18:44 2014
@@ -42,7 +42,6 @@ public class SignaturePropertyTest exten
}
@org.junit.Test
- @SuppressWarnings("unchecked")
public void testConstructor() {
// test XMLSignatureFactory.newSignatureProperty(List, String, String)
SignatureProperty prop;
@@ -54,7 +53,7 @@ public class SignaturePropertyTest exten
} catch (Exception ex) {
fail("Should raise a NPE for null content instead of " + ex);
}
- List<Object> list = new Vector<Object>();
+ List<XMLStructure> list = new Vector<XMLStructure>();
try {
prop = factory.newSignatureProperty(list, target, id);
fail("Should raise an IAE for empty content");
@@ -63,9 +62,12 @@ public class SignaturePropertyTest exten
fail("Should raise an IAE for empty content instead of " + ex);
}
String strEntry = "wrong type";
- list.add(strEntry);
+ // use raw List type to test for invalid XMLStructure entries
+ List invalidList = new Vector();
+ addEntryToRawList(invalidList, strEntry);
try {
- prop = factory.newSignatureProperty(list, target, id);
+ @SuppressWarnings("unchecked")
+ SignatureProperty prop2 = factory.newSignatureProperty(invalidList, target, id);
fail("Should raise a CCE for content containing " +
"invalid, i.e. non-XMLStructure, entries");
} catch (ClassCastException cce) {
@@ -73,7 +75,6 @@ public class SignaturePropertyTest exten
fail("Should raise a CCE for content with invalid entries " +
"instead of " + ex);
}
- list.remove(strEntry);
list.add(new TestUtils.MyOwnXMLStructure());
try {
prop = factory.newSignatureProperty(list, null, id);
@@ -85,7 +86,8 @@ public class SignaturePropertyTest exten
prop = factory.newSignatureProperty(list, target, id);
assertNotNull(prop);
- List<Object> unmodifiable = prop.getContent();
+ @SuppressWarnings("unchecked")
+ List<XMLStructure> unmodifiable = prop.getContent();
assertNotNull(unmodifiable);
try {
unmodifiable.add(new TestUtils.MyOwnXMLStructure());
@@ -111,4 +113,8 @@ public class SignaturePropertyTest exten
assertTrue(!prop.isFeatureSupported("not supported"));
}
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignatureValidator.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignatureValidator.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignatureValidator.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignatureValidator.java Wed Oct 29 19:18:44 2014
@@ -85,9 +85,10 @@ public class SignatureValidator {
// Check core validation status
if (coreValidity == false) {
// check the validation status of each Reference
- Iterator<?> i = signature.getSignedInfo().getReferences().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<Reference> i = signature.getSignedInfo().getReferences().iterator();
while (i.hasNext()) {
- Reference reference = (Reference) i.next();
+ Reference reference = i.next();
reference.validate(vc);
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignedInfoTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignedInfoTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignedInfoTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/SignedInfoTest.java Wed Oct 29 19:18:44 2014
@@ -83,7 +83,7 @@ public class SignedInfoTest extends org.
}
}
- List<Object> empty = new Vector<Object>();
+ List<Reference> empty = new Vector<Reference>();
try {
si = fac.newSignedInfo(cm, sm, empty);
fail("Should throw an IAE for empty references");
@@ -93,9 +93,12 @@ public class SignedInfoTest extends org.
" for empty references");
}
- empty.add("String");
+ // use raw List type to test for invalid Reference entries
+ List invalidRefs = new Vector();
+ addEntryToRawList(invalidRefs, "String");
try {
- si = fac.newSignedInfo(cm, sm, empty);
+ @SuppressWarnings("unchecked")
+ SignedInfo si2 = fac.newSignedInfo(cm, sm, invalidRefs);
fail("Should throw an CCE for illegal references");
} catch(ClassCastException cce) {
} catch(Exception ex) {
@@ -127,5 +130,9 @@ public class SignedInfoTest extends org.
assertNotNull(si);
assertEquals(si.getId(), "id");
}
-
+
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/TestUtils.java Wed Oct 29 19:18:44 2014
@@ -54,6 +54,7 @@ import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dom.DOMStructure;
import javax.xml.crypto.dsig.DigestMethod;
import javax.xml.crypto.dsig.Reference;
+import javax.xml.crypto.dsig.Transform;
import javax.xml.crypto.dsig.XMLSignatureException;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.XMLValidateContext;
@@ -293,8 +294,8 @@ public class TestUtils {
return null;
}
- public List<?> getTransforms() {
- return Collections.EMPTY_LIST;
+ public List<Transform> getTransforms() {
+ return Collections.emptyList();
}
public boolean validate(XMLValidateContext vCtx)
@@ -362,7 +363,7 @@ public class TestUtils {
public Data dereference(URIReference ref, XMLCryptoContext ctxt) {
return new NodeSetData() {
- public Iterator<?> iterator() {
+ public Iterator<Node> iterator() {
return Collections.singletonList(data).iterator();
}
};
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=1635262&r1=1635261&r2=1635262&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 Wed Oct 29 19:18:44 2014
@@ -141,9 +141,10 @@ public class X509KeySelector extends Key
}
// Iterate through KeyInfo types
- Iterator<?> i = keyInfo.getContent().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<XMLStructure> i = keyInfo.getContent().iterator();
while (i.hasNext()) {
- XMLStructure kiType = (XMLStructure) i.next();
+ XMLStructure kiType = i.next();
// check X509Data
if (kiType instanceof X509Data) {
X509Data xd = (X509Data) kiType;
@@ -305,7 +306,8 @@ public class X509KeySelector extends Key
}
Collection<X509Certificate> certs = new ArrayList<X509Certificate>();
- Iterator<?> xi = xd.getContent().iterator();
+ @SuppressWarnings("unchecked")
+ Iterator<Object> xi = xd.getContent().iterator();
while (xi.hasNext()) {
Object o = xi.next();
// check X509IssuerSerial
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=1635262&r1=1635261&r2=1635262&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 Wed Oct 29 19:18:44 2014
@@ -22,6 +22,7 @@
package javax.xml.crypto.test.dsig;
import java.util.*;
+import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.*;
/**
@@ -42,7 +43,6 @@ public class XMLObjectTest extends org.j
("DOM", new org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI());
}
- @SuppressWarnings("unchecked")
@org.junit.Test
public void testConstructor() {
// test XMLSignatureFactory.newXMLObject(List, String, String, String)
@@ -51,14 +51,17 @@ public class XMLObjectTest extends org.j
obj = factory.newXMLObject(null, null, null, null);
assertNotNull(obj);
- List<Object> list = new Vector<Object>();
+ List<XMLStructure> list = new Vector<XMLStructure>();
obj = factory.newXMLObject(list, null, null, null);
assertNotNull(obj);
String strEntry = "wrong type";
- list.add(strEntry);
+ // use raw List type to test for invalid XMLStructure entries
+ List invalidList = new Vector();
+ addEntryToRawList(invalidList, strEntry);
try {
- obj = factory.newXMLObject(list, null, null, null);
+ @SuppressWarnings("unchecked")
+ XMLObject obj2 = factory.newXMLObject(invalidList, null, null, null);
fail("Should raise a CCE for content containing " +
"invalid, i.e. non-XMLStructure, entries");
} catch (ClassCastException cce) {
@@ -66,7 +69,6 @@ public class XMLObjectTest extends org.j
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);
@@ -76,7 +78,8 @@ public class XMLObjectTest extends org.j
assertEquals(obj.getMimeType(), mimeType);
assertEquals(obj.getEncoding(), encoding);
- List<Object> unmodifiable = obj.getContent();
+ @SuppressWarnings("unchecked")
+ List<XMLStructure> unmodifiable = obj.getContent();
try {
unmodifiable.add(new TestUtils.MyOwnXMLStructure());
fail("Should return an unmodifiable List object");
@@ -86,7 +89,7 @@ public class XMLObjectTest extends org.j
@org.junit.Test
public void testisFeatureSupported() {
- List<Object> list = new Vector<Object>();
+ List<XMLStructure> list = new Vector<XMLStructure>();
list.add(new TestUtils.MyOwnXMLStructure());
XMLObject obj = factory.newXMLObject(list, id, mimeType, encoding);
try {
@@ -96,4 +99,9 @@ public class XMLObjectTest extends org.j
assertTrue(!obj.isFeatureSupported("not supported"));
}
+
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}
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=1635262&r1=1635261&r2=1635262&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 Wed Oct 29 19:18:44 2014
@@ -117,8 +117,12 @@ public class XMLSignatureTest extends or
}
}
try {
- sig = fac.newXMLSignature(defSi, defKi,
- Collections.singletonList("wrongType"), id, sigValueId);
+ // use raw List type to test for invalid entries
+ List invalidObjects = new Vector();
+ addEntryToRawList(invalidObjects, "wrongType");
+ @SuppressWarnings("unchecked")
+ XMLSignature sig2 = fac.newXMLSignature(defSi, defKi,
+ invalidObjects, id, sigValueId);
fail("Should throw a CCE for invalid objects");
} catch (ClassCastException cce) {
} catch (Exception ex) {
@@ -406,6 +410,11 @@ public class XMLSignatureTest extends or
return fac.newSignedInfo(cm, sm, refs);
}
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
+
static class TestProvider extends Provider {
private static final long serialVersionUID = 1L;
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=1635262&r1=1635261&r2=1635262&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 Wed Oct 29 19:18:44 2014
@@ -63,21 +63,12 @@ public class KeyInfoTest extends org.jun
(Collections.singletonList(fac.newKeyName("foo")));
for (int j = 0; j < infos.length; j++) {
KeyInfo ki = infos[j];
- List<Object> li = ki.getContent();
+ List<XMLStructure> 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
+ Object[] content = li.toArray();
+ for (int i = 0; i < content.length; i++) {
+ if (!(content[i] instanceof XMLStructure)) {
+ fail("KeyInfo element has the wrong type");
}
}
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java?rev=1635262&r1=1635261&r2=1635262&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/PGPDataTest.java Wed Oct 29 19:18:44 2014
@@ -24,6 +24,7 @@ package javax.xml.crypto.test.dsig.keyin
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Vector;
import javax.xml.crypto.*;
import javax.xml.crypto.dsig.keyinfo.*;
@@ -58,11 +59,12 @@ public class PGPDataTest extends org.jun
fac.newPGPData(values[1], null)
};
for (int i=0; i<pds.length; i++) {
- List<?> li = pds[i].getExternalElements();
+ @SuppressWarnings("unchecked")
+ List<XMLStructure> li = pds[i].getExternalElements();
assertNotNull(li);
if (!li.isEmpty()) {
Object[] types = li.toArray();
- for (int j=0; j<types.length; j++) {
+ for (int j = 0; j < types.length; j++) {
if (!(types[j] instanceof XMLStructure)) {
fail("PGP element has the wrong type");
}
@@ -70,8 +72,11 @@ public class PGPDataTest extends org.jun
}
}
try {
- fac.newPGPData
- (values[0], Collections.singletonList(new Object()));
+ // use raw List type to test for invalid entries
+ List invalidData = new Vector();
+ addEntryToRawList(invalidData, new Object());
+ @SuppressWarnings("unchecked")
+ PGPData pd = fac.newPGPData(values[0], invalidData);
fail("Added PGP element of wrong type");
} catch (ClassCastException ex) {
// expected
@@ -134,4 +139,9 @@ public class PGPDataTest extends org.jun
assertTrue(!pd.isFeatureSupported("not supported"));
}
}
+
+ @SuppressWarnings("unchecked")
+ private static void addEntryToRawList(List list, Object entry) {
+ list.add(entry);
+ }
}