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

PolicyIntersectorTest

public class PolicyIntersectorTest extends TestCase
author
Marek Potociar (marek.potociar@sun.com)

Fields Summary
PolicyIntersector
intersector
Constructors Summary
public PolicyIntersectorTest(String testName)

    
       
        super(testName);
    
Methods Summary
protected voidsetUp()

    
protected voidtearDown()

    
public voidtestIntersectAllPolicyInCollectionEmptyReturnsEmptyPolicy()

        Collection<Policy> policies = new LinkedList<Policy>();
        for (int i = 0; i < 10; i++) {
            policies.add(Policy.createEmptyPolicy("fake" + i, null));
        }
        
        Policy result = intersector.intersect(policies);
        
        assertTrue("Intersecting collection with all policy instances empty should return empty policy as a result", result.isEmpty());
    
public voidtestIntersectEmptyPolicyCollectionThrowsIAE()

        Collection<Policy> policies = new LinkedList<Policy>();
        try {            
            Policy result = intersector.intersect(policies);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException e) {
            // ok
        }                
    
public voidtestIntersectEmptyPolicyInCollectionReturnsNullPolicy()

        Collection<AssertionSet> alternatives = Arrays.asList(new AssertionSet[] {AssertionSet.createAssertionSet(Arrays.asList(new PolicyAssertion[] {new PolicyAssertion(AssertionData.createAssertionData(new QName("A")), null, null){}}))});
        Collection<Policy> policies = new LinkedList<Policy>();
        for (int i = 0; i < 10; i++) {
            policies.add(Policy.createPolicy("fake", null, alternatives));
        }
        policies.add(Policy.createEmptyPolicy());
        
        Policy result = intersector.intersect(policies);
        
        assertTrue("Intersecting collection with empty policy instance should return null policy as a result", result.isNull());
    
public voidtestIntersectNullPolicyCollectionThrowsIAE()

        Collection<Policy> policies = null;
        try {            
            Policy result = intersector.intersect(policies);
            fail("IllegalArgumentException should have been thrown");
        } catch (IllegalArgumentException e) {
            // ok
        }                
    
public voidtestIntersectNullPolicyInCollectionReturnsNullPolicy()

        Collection<AssertionSet> alternatives = Arrays.asList(new AssertionSet[] {AssertionSet.createAssertionSet(Arrays.asList(new PolicyAssertion[] {new PolicyAssertion(AssertionData.createAssertionData(new QName("A")), null, null){}}))});
        Collection<Policy> policies = new LinkedList<Policy>();
        for (int i = 0; i < 10; i++) {
            policies.add(Policy.createPolicy("fake", null, alternatives));
        }
        policies.add(Policy.createNullPolicy());
        
        Policy result = intersector.intersect(policies);
        
        assertTrue("Intersecting collection with null policy instance should return null policy as a result", result.isNull());
    
public voidtestIntersectSimplePolicies()

        Collection<Policy> policies = new LinkedList<Policy>();
        
        policies.add(PolicyResourceLoader.loadPolicy("intersection/policy1.xml"));
        policies.add(PolicyResourceLoader.loadPolicy("intersection/policy2.xml"));
        policies.add(PolicyResourceLoader.loadPolicy("intersection/policy3.xml"));
        
        Policy expectedResult = PolicyResourceLoader.loadPolicy("intersection/intersection_1-2-3.xml");
        Policy result = intersector.intersect(policies);
        assertEquals("Intersection did not provide expected result.", expectedResult, result);
    
public voidtestIntersectSinglePolicyInCollectionReturnsTheSameSinglePolicyInstance()

        Collection<Policy> policies = new LinkedList<Policy>();
        Policy expected = Policy.createEmptyPolicy("fake", null);
        policies.add(expected);
        Policy result = intersector.intersect(policies);
        
        assertTrue("Intersecting collection with single policy instance should return the very same policy instance", expected == result);
    
public voidtestPolicyIntersectorFactoryMethodDoesNotReturnNull()

        assertNotNull(PolicyIntersector.createPolicyIntersector());