FileDocCategorySizeDatePackage
EffectiveAlternativeSelectorTest.javaAPI DocExample8034Tue May 29 16:57:36 BST 2007com.sun.xml.ws.policy

EffectiveAlternativeSelectorTest

public class EffectiveAlternativeSelectorTest extends TestCase
author
japod

Fields Summary
private static final com.sun.xml.ws.policy.sourcemodel.PolicyModelUnmarshaller
xmlUnmarshaller
Constructors Summary
public EffectiveAlternativeSelectorTest(String testName)

    
       
        super(testName);
    
Methods Summary
public static junit.framework.Testsuite()

        TestSuite suite = new TestSuite(EffectiveAlternativeSelectorTest.class);
        
        return suite;
    
public voidtestDoEmptySelection()

        HashSet<PolicyMapMutator> mutators = new HashSet<PolicyMapMutator>();
        EffectivePolicyModifier modifier = EffectivePolicyModifier.createEffectivePolicyModifier();
        mutators.add(modifier);
        PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
        mutators.add(extender);
        PolicyMap policyMap = PolicyMap.createPolicyMap(mutators);
        
        Policy emptyPolicy = Policy.createEmptyPolicy();
        PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(new QName("service"), new QName("port"));
        extender.putEndpointSubject(key, new PolicySubject("two", emptyPolicy));
        
        EffectiveAlternativeSelector.doSelection(modifier);
        
        assertTrue(extender.getMap().getEndpointEffectivePolicy(key).isEmpty());
    
public voidtestDoNegativeSelection()

        HashSet<PolicyMapMutator> mutators = new HashSet<PolicyMapMutator>();
        EffectivePolicyModifier myModifier = EffectivePolicyModifier.createEffectivePolicyModifier();
        mutators.add(myModifier);
        PolicyMapExtender myExtender = PolicyMapExtender.createPolicyMapExtender();
        mutators.add(myExtender);
        PolicyMap policyMap = PolicyMap.createPolicyMap(mutators);
        
        //Policy pol1 = PolicyModelTranslator.getTranslator()
        //                .translate(unmarshalModel("single_alternative_policy/policy3.xml"));
        Policy pol2 = loadPolicy("complex_policy/nested_assertions_with_alternatives.xml");
        
        PolicyMapKey aKey = PolicyMap.createWsdlEndpointScopeKey(new QName("service"),new QName("port"));
        
        //myExtender.putEndpointSubject(aKey,new PolicySubject("one",pol1));
        myExtender.putEndpointSubject(aKey,new PolicySubject("two",pol2));
        
        //System.out.println(myExtender.getMap());
        
        if(2>myExtender.getMap().getEndpointEffectivePolicy(aKey).getNumberOfAssertionSets()) {
            fail("Insufficient number of alternatives found. At least 2 of them needed.");
        };
        
        EffectiveAlternativeSelector.doSelection(myModifier);
        
        if(1!=myExtender.getMap().getEndpointEffectivePolicy(aKey).getNumberOfAssertionSets()) {
            fail("Too many alternatives has left.");
        }
        
        EffectiveAlternativeSelector.doSelection(myModifier);
        
        if(1!=myExtender.getMap().getEndpointEffectivePolicy(aKey).getNumberOfAssertionSets()) {
            fail("Too many alternatives has left.");
        }
    
public voidtestDoNullSelection()

        HashSet<PolicyMapMutator> mutators = new HashSet<PolicyMapMutator>();
        EffectivePolicyModifier modifier = EffectivePolicyModifier.createEffectivePolicyModifier();
        mutators.add(modifier);
        PolicyMapExtender extender = PolicyMapExtender.createPolicyMapExtender();
        mutators.add(extender);
        PolicyMap policyMap = PolicyMap.createPolicyMap(mutators);
        
        Policy nullPolicy = Policy.createNullPolicy();
        PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(new QName("service"), new QName("port"));
        extender.putEndpointSubject(key, new PolicySubject("two", nullPolicy));
        
        EffectiveAlternativeSelector.doSelection(modifier);
        
        assertTrue(extender.getMap().getEndpointEffectivePolicy(key).isNull());
    
public voidtestDoPositiveSelection()
Test of doSelection method, of class com.sun.xml.ws.policy.EffectiveAlternativeSelector.

        HashSet<PolicyMapMutator> mutators = new HashSet<PolicyMapMutator>();
        EffectivePolicyModifier myModifier = EffectivePolicyModifier.createEffectivePolicyModifier();
        mutators.add(myModifier);
        PolicyMapExtender myExtender = PolicyMapExtender.createPolicyMapExtender();
        mutators.add(myExtender);
        PolicyMap policyMap = PolicyMap.createPolicyMap(mutators);
        
        //Policy pol1 = PolicyModelTranslator.getTranslator()
        //                .translate(unmarshalModel("single_alternative_policy/policy3.xml"));
        Policy pol2 = loadPolicy("complex_policy/nested_assertions_with_alternatives.xml");
        
        PolicyMapKey aKey = PolicyMap.createWsdlEndpointScopeKey(new QName("service"),new QName("port"));
        
        //myExtender.putEndpointSubject(aKey,new PolicySubject("one",pol1));
        myExtender.putEndpointSubject(aKey,new PolicySubject("two",pol2));
        
        //System.out.println(myExtender.getMap());
        
        if(2>myExtender.getMap().getEndpointEffectivePolicy(aKey).getNumberOfAssertionSets()) {
            fail("Insufficient number of alternatives found. At least 2 of them needed.");
        };
        
        EffectiveAlternativeSelector.doSelection(myModifier);
        
        if(1!=myExtender.getMap().getEndpointEffectivePolicy(aKey).getNumberOfAssertionSets()) {
            fail("Too many alternatives has left.");
        }