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

SignedEndorsingSupportingTokensTest

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

Fields Summary
Constructors Summary
public SignedEndorsingSupportingTokensTest(String testName)

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

        return new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName));
    
public booleanhasXPathTarget(java.lang.String xpathExpr, java.util.Iterator itr)

        while(itr.hasNext()){
            if(xpathExpr.equals(itr.next())){
                return true;
            }
        }
        return false;
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

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

    
public voidtestSignedEndorsingSupportingToken()

        String fileName="security/SignedEndorsingSupportingToken.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "SignedEndorsingSupportingTokens",assertion.getName().getLocalPart());
                SignedEndorsingSupportingTokens sst = (SignedEndorsingSupportingTokens)assertion;
                
                AlgorithmSuite aSuite = (AlgorithmSuite) sst.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.TripleDesRsa15.getEncAlgorithm());
                
                Iterator itrest = sst.getTokens();
                if(itrest.hasNext()) {
                    assertTrue(X509Token.WSSX509V3TOKEN10.equals(((X509Token)itrest.next()).getTokenType()));
                }
                
                
                
                Iterator itrSparts = sst.getSignedElements();
                if(itrSparts.hasNext()) {
                    SignedElements se = (SignedElements)itrSparts.next();
                    assertTrue(hasXPathTarget("//soapEnv:Body",se.getTargets()));
                    assertTrue(hasXPathTarget("//addr:To",se.getTargets()));
                    assertTrue(hasXPathTarget("//addr:From",se.getTargets()));
                    assertTrue(hasXPathTarget("//addr:RealtesTo",se.getTargets()));
                }
            }
        }
    
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;