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

RelTokenTest

public class RelTokenTest extends TestCase
author
Mayank.Mishra@sun.com

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

    
public voidtestRelToken1()

        testRelToken_Keys_Reference("security/RelToken1.xml", "");
        testRelToken_Keys_Reference("security/RelToken2.xml", "RequireKeyIdentifierReference");
    
public voidtestRelToken2()

        testRelTokenType("security/RelToken1.xml", com.sun.xml.ws.security.policy.RelToken.WSS_REL_V10_TOKEN10);
        testRelTokenType("security/RelToken2.xml", com.sun.xml.ws.security.policy.RelToken.WSS_REL_V20_TOKEN10);
        testRelTokenType("security/RelToken3.xml", com.sun.xml.ws.security.policy.RelToken.WSS_REL_V10_TOKEN11);
        testRelTokenType("security/RelToken4.xml", com.sun.xml.ws.security.policy.RelToken.WSS_REL_V20_TOKEN11);
    
public voidtestRelTokenType(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","RelToken",assertion.getName().getLocalPart());
                assertion = (PolicyAssertion)assertion;
                com.sun.xml.ws.security.impl.policy.RelToken rt = (com.sun.xml.ws.security.impl.policy.RelToken)assertion;
                assertTrue(rt.getTokenType().equals(tokenType));
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestRelToken_Keys_Reference(java.lang.String fileName, java.lang.String param)

        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","RelToken",assertion.getName().getLocalPart());
                com.sun.xml.ws.security.impl.policy.RelToken rt=(com.sun.xml.ws.security.impl.policy.RelToken)assertion;
                if(param.equals(""))
                    assertTrue(rt.isRequireDerivedKeys());
                else {
                    Iterator itrRt = rt.getTokenRefernceType();
                    if(itrRt.hasNext()) {
                        assertTrue(((String)itrRt.next()).equals(com.sun.xml.ws.security.policy.RelToken.REQUIRE_KEY_IDENTIFIER_REFERENCE));
                    }
                }
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
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;