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

EndorsingSupportingTokensTest

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

Fields Summary
Constructors Summary
public EndorsingSupportingTokensTest(String testName)

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

        return new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName));
    
public booleanisHeaderPresent(javax.xml.namespace.QName expected, java.util.Iterator headers)

        while(headers.hasNext()){
            Header header = (Header) headers.next();
            if(expected.getLocalPart().equals(header.getLocalName())){
                if(expected.getNamespaceURI().equals(header.getURI())){
                    return true;
                }
            }
        }
        return false;
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

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

    
public voidtestEndorsingSupportingToken()

        String fileName="security/EndorsingSupportingToken.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "EndorsingSupportingTokens",assertion.getName().getLocalPart());
                EndorsingSupportingTokens est = (EndorsingSupportingTokens)assertion;
                
                AlgorithmSuite aSuite = (AlgorithmSuite) est.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.TripleDesRsa15.getEncAlgorithm());
                
                Iterator itrest = est.getTokens();
                if(itrest.hasNext()) {
                    assertTrue(X509Token.WSSX509V3TOKEN10.equals(((X509Token)itrest.next()).getTokenType()));
                }
                
                Iterator itrTkn = est.getSignedParts();
                if(itrTkn.hasNext()) {
                    SignedParts sp = ((SignedParts)itrTkn.next());
                    
                    assertEquals("Body should be present",true,sp.hasBody());
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","To"),sp.getHeaders()));
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","From"),sp.getHeaders()));
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","FaultTo"),sp.getHeaders()));
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","ReplyTo"),sp.getHeaders()));
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","MessageID"),sp.getHeaders()));
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","RelatesTo"),sp.getHeaders()));
                    assertTrue(isHeaderPresent(new QName("http://schemas.xmlsoap.org/ws/2004/08/addressing","Action"),sp.getHeaders()));
                    
                }
            }
        }
    
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;