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

IssuedTokenTest

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

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

    
public voidtestIssuedTokenAssertions1()

        String fileName = "security/IssuedTokenAssertions1.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","IssuedToken",assertion.getName().getLocalPart());
                IssuedToken it = (IssuedToken)assertion;
                assertEquals("Invalid Dervied Keys", "RequireDerivedKeys", it.REQUIRE_DERIVED_KEYS);
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestIssuedTokenAssertions2()

        String fileName = "security/IssuedTokenAssertions2.xml";
        Policy policy = unmarshalPolicy(fileName);
        String rType = com.sun.xml.ws.security.policy.IssuedToken.REQUIRE_EXTERNAL_REFERENCE;
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","IssuedToken",assertion.getName().getLocalPart());
                IssuedToken it = (IssuedToken)assertion;
                System.out.println(it.getIncludeToken());
                Iterator itrIt = it.getTokenRefernceType();
                if(itrIt.hasNext()) {
                    assertTrue(((String)itrIt.next()).equals(rType));
                }
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestIssuedTokenAssertions3()

        String fileName = "security/IssuedTokenAssertions3.xml";
        String rType = com.sun.xml.ws.security.policy.IssuedToken.REQUIRE_INTERNAL_REFERENCE;
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","IssuedToken",assertion.getName().getLocalPart());
                IssuedToken it = (IssuedToken)assertion;
                System.out.println(it.getIncludeToken());
                Iterator itrIt = it.getTokenRefernceType();
                if(itrIt.hasNext()) {
                    assertTrue(((String)itrIt.next()).equals(rType));
                }
            }
        } else {
            throw new Exception("No Assertions found!. Unmarshalling of "+fileName+" failed!");
        }
    
public voidtestIssuedTokenAssertions4()

         // test for bug
         //https://wsit.dev.java.net/issues/show_bug.cgi?id=314
        String fileName = "security/IssuedTokenAssertions_issuer.xml";
        Policy policy = unmarshalPolicy(fileName);
        Iterator <AssertionSet> itr = policy.iterator();
        if(itr.hasNext()) {
            AssertionSet as = itr.next();
            for(PolicyAssertion assertion : as) {
                assertEquals("Invalid assertion","IssuedToken",assertion.getName().getLocalPart());
                IssuedToken it = (IssuedToken)assertion;
               assertNotNull(it.getIssuer().getAddress().getURI());
            }
        } 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;