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

AsymmetricBindingTest

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

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

    
public voidtestAsymmerticBinding1()

        String fileName="security/AsymmetricBindingAssertion1.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "AsymmetricBinding",assertion.getName().getLocalPart());
                AsymmetricBinding asb = (AsymmetricBinding)assertion;
                
                X509Token tkn1 = (X509Token)asb.getInitiatorToken();
                assertTrue(tkn1.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V1TOKEN10));
                
                X509Token tkn2 = (X509Token)asb.getRecipientToken();
                assertTrue(tkn2.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V3TOKEN11));
                
                assertFalse("Tokens are Protected", asb.getTokenProtection());
                
                AlgorithmSuite aSuite = asb.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.TripleDesRsa15.getEncAlgorithm());
                
                assertTrue(asb.isIncludeTimeStamp());
                
                assertFalse("Signature is Encrypted", asb.getSignatureProtection());
                
                assertFalse(asb.isSignContent());
            }
        }
    
public voidtestAsymmerticBinding2()

        String fileName="security/AsymmetricBindingAssertion2.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "AsymmetricBinding",assertion.getName().getLocalPart());
                AsymmetricBinding asb = (AsymmetricBinding)assertion;
                
                X509Token tkn1 = (X509Token)asb.getInitiatorToken();
                assertTrue(tkn1.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V1TOKEN10));
                
                X509Token tkn2 = (X509Token)asb.getRecipientToken();
                assertTrue(tkn2.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V3TOKEN11));
                
                AlgorithmSuite aSuite = asb.getAlgorithmSuite();
                assertEquals("Unmatched Algorithm",aSuite.getEncryptionAlgorithm(), AlgorithmSuiteValue.TripleDesRsa15.getEncAlgorithm());
                
                assertTrue(asb.isIncludeTimeStamp());
                
                assertTrue("Signature is not Encrypted", asb.getSignatureProtection());
                
                assertTrue("Tokens are not protected", asb.getTokenProtection());
                
                assertEquals("SIGN_ENCRYPT is the protection order",com.sun.xml.ws.security.impl.policy.AsymmetricBinding.ENCRYPT_SIGN,asb.getProtectionOrder());
            }
        }
    
public voidtestAsymmerticCR6420594()

        String fileName="security/AsymmetricCR.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion", "AsymmetricBinding",assertion.getName().getLocalPart());
                AsymmetricBinding asb = (AsymmetricBinding)assertion;
                
                X509Token tkn1 = (X509Token)asb.getInitiatorToken();
                assertTrue(tkn1.getIncludeToken().equals(Token.INCLUDE_ALWAYS));
                assertTrue(tkn1.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V3TOKEN10));
                
                X509Token tkn2 = (X509Token)asb.getRecipientToken();
                assertTrue(tkn2.getIncludeToken().equals(Token.INCLUDE_ALWAYS));
                assertTrue(tkn2.getTokenType().equals(com.sun.xml.ws.security.impl.policy.X509Token.WSSX509V3TOKEN10));
            }
        }
    
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;