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

UsernameTokenTest

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

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

    
public voidtestTokenAssertionsType(java.lang.String fileName, java.lang.String tokenType)

        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","UsernameToken",assertion.getName().getLocalPart());
                com.sun.xml.ws.security.policy.UserNameToken ut = (com.sun.xml.ws.security.policy.UserNameToken)assertion;
                assertTrue(tokenType.equals(ut.getType()));
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestUserNameTokenAssertions_8()

        testTokenAssertionsType("security/UserNameTokenAssertions1.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_10);
        testTokenAssertionsType("security/UserNameTokenAssertions2.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_10);
        testTokenAssertionsType("security/UserNameTokenAssertions3.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_10);
        testTokenAssertionsType("security/UserNameTokenAssertions4.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_10);
        testTokenAssertionsType("security/UserNameTokenAssertions5.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_11);
        testTokenAssertionsType("security/UserNameTokenAssertions6.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_11);
        testTokenAssertionsType("security/UserNameTokenAssertions7.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_11);
        testTokenAssertionsType("security/UserNameTokenAssertions8.xml", com.sun.xml.ws.security.policy.UserNameToken.WSS_USERNAME_TOKEN_11);
    
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;