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

SamlTokenTest

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

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

    
public voidtestSamlToken_Keys()

        String fileName = "security/SamlTokenAssertions1.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","SamlToken",assertion.getName().getLocalPart());
                SamlToken samlt = (SamlToken)assertion;
                assertTrue(samlt.isRequireDerivedKeys());
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestSamlToken_Reference()

        String fileName = "security/SamlTokenAssertions2.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","SamlToken",assertion.getName().getLocalPart());
                SamlToken samlt = (SamlToken)assertion;
                Iterator itrst = samlt.getTokenRefernceType();
                if(itrst.hasNext()) {
                    assertTrue(((String)itrst.next()).equals(com.sun.xml.ws.security.impl.policy.SamlToken.REQUIRE_KEY_IDENTIFIER_REFERENCE));
                }
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestSamlToken_Type(java.lang.String fileName, java.lang.String tokenType)

        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","SamlToken",assertion.getName().getLocalPart());
                SamlToken samlt = (SamlToken)assertion;
                assertTrue(samlt.getTokenType().equals(tokenType));
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestSamlToken_Types_5()

        testSamlToken_Type("security/SamlTokenAssertions1.xml", com.sun.xml.ws.security.impl.policy.SamlToken.WSS_SAML_V10_TOKEN10);
        testSamlToken_Type("security/SamlTokenAssertions2.xml", com.sun.xml.ws.security.impl.policy.SamlToken.WSS_SAML_V11_TOKEN10);
        testSamlToken_Type("security/SamlTokenAssertions3.xml", com.sun.xml.ws.security.impl.policy.SamlToken.WSS_SAML_V10_TOKEN11);
        testSamlToken_Type("security/SamlTokenAssertions4.xml", com.sun.xml.ws.security.impl.policy.SamlToken.WSS_SAML_V11_TOKEN11);
        testSamlToken_Type("security/SamlTokenAssertions5.xml", com.sun.xml.ws.security.impl.policy.SamlToken.WSS_SAML_V20_TOKEN11);
    
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;