FileDocCategorySizeDatePackage
PolicyMapTest.javaAPI DocExample10379Thu Jul 12 10:19:04 BST 2007com.sun.xml.ws.policy

PolicyMapTest

public class PolicyMapTest extends TestCase
author
Marek Potociar (marek.potociar at sun.com)

Fields Summary
Constructors Summary
public PolicyMapTest(String testName)

        super(testName);
    
Methods Summary
protected voidsetUp()

    
protected voidtearDown()

    
public voidtestCreatePolicyMapWithEmptyMutatorCollection()

        assertNotNull("Policy map instance should not be null", PolicyMap.createPolicyMap(new LinkedList<PolicyMapMutator>()));        
    
public voidtestCreatePolicyMapWithNonemptyMutatorCollection()

        assertNotNull("Policy map instance should not be null", PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {PolicyMapExtender.createPolicyMapExtender()})));                
    
public voidtestCreatePolicyMapWithNullMutatorCollection()

        assertNotNull("Policy map instance should not be null", PolicyMap.createPolicyMap(null));
    
public voidtestGetFaultMessageEffectivePolicy()

        PolicyMap policyMap = PolicyConfigParser.parse(getResourceUrl("effective/all.wsdl"), false);
        Policy expectedPolicy = loadPolicy("effective/resultFault.xml");
        PolicyMapKey policyMapKey = policyMap.createWsdlFaultMessageScopeKey(new QName("http://example.org/","Service"),new QName("http://example.org/","Port"),new QName("http://example.org/","Operation"),new QName("http://example.org/","Fault"));
        Policy policy = policyMap.getFaultMessageEffectivePolicy(policyMapKey);
        assertEquals(expectedPolicy, policy);
    
public voidtestGetFaultMessageWithTwoServicesEffectivePolicy()

        PolicyMap policyMap = PolicyConfigParser.parse(getResourceUrl("effective/twoservices.wsdl"), false);
        Policy expectedPolicy = loadPolicy("effective/resultFault.xml");
        PolicyMapKey policyMapKey = policyMap.createWsdlFaultMessageScopeKey(new QName("http://example.org/","Service"),new QName("http://example.org/","Port"),new QName("http://example.org/","Operation"),new QName("http://example.org/","Fault"));
        Policy policy = policyMap.getFaultMessageEffectivePolicy(policyMapKey);
        assertEquals(expectedPolicy, policy);
    
public voidtestGetInputMessageEffectivePolicy()

        PolicyMap policyMap = PolicyConfigParser.parse(getResourceUrl("effective/all.wsdl"), false);
        Policy expectedPolicy = loadPolicy("effective/resultInput.xml");
        PolicyMapKey policyMapKey = policyMap.createWsdlMessageScopeKey(new QName("http://example.org/","Service"),new QName("http://example.org/","Port"),new QName("http://example.org/","Operation"));
        Policy policy = policyMap.getInputMessageEffectivePolicy(policyMapKey);
        assertEquals(expectedPolicy, policy);
    
public voidtestGetOperationEffectivePolicy()

        PolicyMap policyMap = PolicyConfigParser.parse(getResourceUrl("effective/all.wsdl"), false);
        Policy expectedPolicy = loadPolicy("effective/resultOperation.xml");
        PolicyMapKey policyMapKey = policyMap.createWsdlOperationScopeKey(new QName("http://example.org/","Service"),new QName("http://example.org/","Port"),new QName("http://example.org/","Operation"));
        Policy policy = policyMap.getOperationEffectivePolicy(policyMapKey);
        assertEquals(expectedPolicy, policy);
    
public voidtestIsEmpty()

        PolicyMap map = PolicyMap.createPolicyMap(null);
        assertTrue(map.isEmpty());
        
        map = PolicyMap.createPolicyMap(new LinkedList<PolicyMapMutator>());
        assertTrue(map.isEmpty());
        
        map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {PolicyMapExtender.createPolicyMapExtender()}));
        assertTrue(map.isEmpty());
        
        PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
        PolicyMapMutator[] mutators = new PolicyMapMutator[] {extender};
        PolicyMapKey key = map.createWsdlServiceScopeKey(new QName("service"));
        map = PolicyMap.createPolicyMap(Arrays.asList(mutators));
        extender.putServiceSubject(key, null);
        assertFalse(map.isEmpty());

        mutators[0].disconnect();
        key = map.createWsdlEndpointScopeKey(new QName("service"), new QName("port"));
        map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {extender}));
        extender.putEndpointSubject(key, null);
        assertFalse(map.isEmpty());

        mutators[0].disconnect();
        key = map.createWsdlOperationScopeKey(new QName("service"), new QName("port"), new QName("operation"));
        map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {extender}));
        extender.putOperationSubject(key, null);
        assertFalse(map.isEmpty());

        mutators[0].disconnect();
        key = map.createWsdlMessageScopeKey(new QName("service"), new QName("port"), new QName("operation"));
        map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {extender}));
        extender.putInputMessageSubject(key, null);
        assertFalse(map.isEmpty());

        mutators[0].disconnect();
        key = map.createWsdlMessageScopeKey(new QName("service"), new QName("port"), new QName("operation"));
        map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {extender}));
        extender.putOutputMessageSubject(key, null);
        assertFalse(map.isEmpty());

        mutators[0].disconnect();
        key = map.createWsdlMessageScopeKey(new QName("service"), new QName("port"), new QName("operation"));
        map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {extender}));
        extender.putFaultMessageSubject(key, null);
        assertFalse(map.isEmpty());
    
public voidtestPolicyMapIterator()

        PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
        PolicyMap map = PolicyMap.createPolicyMap(Arrays.asList(new PolicyMapMutator[] {extender}));        

        PolicySubject subject = new PolicySubject("dummy", Policy.createEmptyPolicy());
        
        PolicyMapKey key = map.createWsdlServiceScopeKey(new QName("1"));
        extender.putServiceSubject(key, subject);
        key = map.createWsdlServiceScopeKey(new QName("2"));
        extender.putServiceSubject(key, subject);
        
        key = map.createWsdlEndpointScopeKey(new QName("3"), new QName("port"));
        extender.putEndpointSubject(key, subject);
        key = map.createWsdlEndpointScopeKey(new QName("4"), new QName("port"));
        extender.putEndpointSubject(key, subject);
        key = map.createWsdlEndpointScopeKey(new QName("5"), new QName("port"));
        extender.putEndpointSubject(key, subject);

        key = map.createWsdlMessageScopeKey(new QName("6"), new QName("port"), new QName("operation"));
        extender.putInputMessageSubject(key, subject);

        key = map.createWsdlMessageScopeKey(new QName("7"), new QName("port"), new QName("operation"));
        extender.putOutputMessageSubject(key, subject);
        
        key = map.createWsdlMessageScopeKey(new QName("8"), new QName("port"), new QName("operation"));
        extender.putFaultMessageSubject(key, subject);
        
        int counter = 0;
        for (Policy policy : map) {
            counter++;
        }
        
        assertEquals("Did not iterate over expected number of policies.", 8, counter);        
    
public voidtestToString()

        PolicyMap policyMap = getPolicyMap("bug_reproduction/simple.wsdl");
        String result = policyMap.toString();
        assertNotNull(result);