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

SymmetricBindingTest

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

Fields Summary
Constructors Summary
public SymmetricBindingTest(String testName)

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

        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        if(cl==null) {
            return new InputStreamReader(ClassLoader.getSystemResourceAsStream(resourceName));
        } else {
            return new InputStreamReader(cl.getResourceAsStream(resourceName));
        }
        
        
    
protected voidsetUp()

    
public static junit.framework.Testsuite()

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

    
public voidtestSymmerticBinding1()

        String fileName="security/SymmetricBindingAssertion1.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "SymmetricBinding",assertion.getName().getLocalPart());
                SymmetricBinding sb = (SymmetricBinding)assertion;
                
                //  System.out.println((sb.getProtectionToken().getIncludeToken()));
                assertTrue(sb.getTokenProtection());
                
                AlgorithmSuite aSuite = sb.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.Basic128.getEncAlgorithm());
                
                assertTrue(sb.isIncludeTimeStamp());
                
                assertFalse("Signature is Encrypted", sb.getSignatureProtection());
                
                assertFalse(sb.isSignContent());
            }
        }
    
public voidtestSymmerticBinding2()

        String fileName="security/SymmetricBindingAssertion2.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "SymmetricBinding",assertion.getName().getLocalPart());
                SymmetricBinding sb = (SymmetricBinding)assertion;
                
                X509Token tkn1 = (X509Token)sb.getSignatureToken();
                assertTrue(tkn1.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V1TOKEN10));
                
                X509Token tkn2 = (X509Token)sb.getEncryptionToken();
                assertTrue(tkn2.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V3TOKEN10));
                
                AlgorithmSuite aSuite = sb.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.TripleDesRsa15.getEncAlgorithm());
                
                assertTrue(sb.isIncludeTimeStamp());
                
                assertTrue("Signature is not Encypted", sb.getSignatureProtection());
                
                assertFalse("Tokens are protected", sb.getTokenProtection());
            }
        }
    
public voidtestSymmetricIssuedTokenCR6419493()

        String fileName="security/IssuedTokenCR.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "SymmetricBinding",assertion.getName().getLocalPart());
                SymmetricBinding sb = (SymmetricBinding)assertion;
                
                IssuedToken tkn1 = (IssuedToken)sb.getProtectionToken();
                assertTrue(tkn1.getIncludeToken().equals(Token.INCLUDE_ALWAYS));
            }
        }
    
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;