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

SupportingTokensTest

public class SupportingTokensTest extends TestCase
author
mayank

Fields Summary
Constructors Summary
public SupportingTokensTest(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(SupportingTokensTest.class);
        
        return suite;
    
protected voidtearDown()

    
public voidtestSupportingToken()

        String fileName="security/SupportingTokenAssertion.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        while(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "SupportingTokens",assertion.getName().getLocalPart());
                SupportingTokens stk = (SupportingTokens)assertion;
                
                AlgorithmSuite aSuite = stk.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.TripleDesRsa15.getEncAlgorithm());
                
                Iterator itrTkn = stk.getTokens();
                if(itrTkn.hasNext()) {
                    assertTrue(((com.sun.xml.ws.security.policy.UserNameToken)itrTkn.next()).getType().equals(com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_10));
                }
                
                Iterator itrSparts = stk.getSignedParts();
                if(itrSparts.hasNext()) {
                    assertEquals("Body not found ",true,((SignedParts)itrSparts.next()).hasBody());
                }
            }
        }
    
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;