FileDocCategorySizeDatePackage
X509TokenTest.javaAPI DocExample7450Tue May 29 16:57:42 BST 2007com.sun.xml.ws.security.impl.policy

X509TokenTest

public class X509TokenTest extends TestCase
author
Mayank.Mishra@SUN.com

Fields Summary
Constructors Summary
public X509TokenTest(String testName)

        super(testName);
    
Methods Summary
private java.io.ReadergetResourceReader(java.lang.String resourceName)

        return new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName));
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(X509TokenTest.class);
        
        return suite;
    
protected voidtearDown()

    
public voidtestX509TokenAssertionsReference(java.lang.String fileName, java.lang.String referenceType)

        
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","X509Token",assertion.getName().getLocalPart());
                X509Token xt = (X509Token)assertion;
                Iterator itrref = xt.getTokenRefernceType().iterator();
                assertTrue(xt.getTokenRefernceType().contains(referenceType));
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestX509TokenAssertionsType(java.lang.String fileName, java.lang.String tokenType)

        
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","X509Token",assertion.getName().getLocalPart());
                X509Token xt = (X509Token)assertion;
                assertTrue(tokenType.equals(xt.getTokenType()));
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestX509TokensAssertions_Reference_4()

        testX509TokenAssertionsReference("security/X509TokenAssertions9.xml", X509Token.REQUIRE_KEY_IDENTIFIER_REFERENCE);
        testX509TokenAssertionsReference("security/X509TokenAssertions10.xml", X509Token.REQUIRE_ISSUER_SERIAL_REFERENCE);
        testX509TokenAssertionsReference("security/X509TokenAssertions11.xml", X509Token.REQUIRE_EMBEDDED_TOKEN_REFERENCE);
        testX509TokenAssertionsReference("security/X509TokenAssertions12.xml", X509Token.REQUIRE_THUMBPRINT_REFERENCE);
    
public voidtestX509TokensAssertions_Types_8()

        testX509TokenAssertionsType("security/X509TokenAssertions1.xml", X509Token.WSSX509V1TOKEN10);
        testX509TokenAssertionsType("security/X509TokenAssertions2.xml", X509Token.WSSX509V3TOKEN10);
        testX509TokenAssertionsType("security/X509TokenAssertions3.xml", X509Token.WSSX509PKCS7TOKEN10);
        testX509TokenAssertionsType("security/X509TokenAssertions4.xml", X509Token.WSSX509PKIPATHV1TOKEN10);
        testX509TokenAssertionsType("security/X509TokenAssertions5.xml", X509Token.WSSX509V1TOKEN11);
        testX509TokenAssertionsType("security/X509TokenAssertions6.xml", X509Token.WSSX509V3TOKEN11);
        testX509TokenAssertionsType("security/X509TokenAssertions7.xml", X509Token.WSSX509PKCS7TOKEN11);
        testX509TokenAssertionsType("security/X509TokenAssertions8.xml", X509Token.WSSX509PKIPATHV1TOKEN11);
    
public com.sun.xml.ws.policy.PolicyunmarshalPolicy(java.lang.String xmlFile)

        PolicySourceModel model =  unmarshalPolicyResource(
                xmlFile);
        Policy mbp = PolicyModelTranslator.getTranslator().translate(model);
        return mbp;
      
private com.sun.xml.ws.policy.sourcemodel.PolicySourceModelunmarshalPolicyResource(java.lang.String resource)

        Reader reader = getResourceReader(resource);
        PolicySourceModel model = PolicyModelUnmarshaller.getXmlUnmarshaller().unmarshalModel(reader);
        reader.close();
        return model;