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

EncryptedPartsTest

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

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

    
public voidtestEncryptParts2()

        String fileName = "security/EncryptParts2.xml";
        Policy policy = unmarshalPolicy(fileName);
        assertNotNull(policy);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()){
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as){
                assertEquals("Invalid assertion", "EncryptedParts", assertion.getName().getLocalPart());
                EncryptedParts ep = (EncryptedParts)assertion;
                assertTrue(ep.hasBody());
            }
        }
    
public voidtestEncryptPartsCR6421129()

        String fileName = "security/EncryptParts5.xml";
        Policy policy = unmarshalPolicy(fileName);
        assertNotNull(policy);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as){
                assertEquals("Invalid asserton","EncryptedParts", assertion.getName().getLocalPart());
                EncryptedParts ep = (EncryptedParts)assertion;
                Iterator itrTargets = ep.getTargets();
                boolean hasBody = false;
                while(itrTargets.hasNext()){
                    PolicyAssertion assertTargets = (PolicyAssertion)itrTargets.next();
                    if ( PolicyUtil.isBody(assertTargets)) {
                        if(hasBody==true){
                            assertFalse(true);
                        }else{
                            hasBody = true;
                        }
                    }
                }
            }
        }
    
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;