cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r512674 [2/2] - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/service/model/ api/src/main/java/org/apache/cxf/ws/policy/ rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/...
Date Wed, 28 Feb 2007 09:29:45 GMT
Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyInfoTest.java?view=auto&rev=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyInfoTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyInfoTest.java Wed Feb 28 01:29:43 2007
@@ -0,0 +1,345 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.policy;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.neethi.All;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.ExactlyOne;
+import org.apache.neethi.Policy;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class EndpointPolicyInfoTest extends TestCase {
+
+    private IMocksControl control;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl();        
+    } 
+    
+    public void testAccessors() {
+        EndpointPolicyInfo epi = new EndpointPolicyInfo();
+        assertNull(epi.getPolicy());
+        assertNull(epi.getChosenAlternative());
+        assertNull(epi.getInInterceptors());
+        assertNull(epi.getInFaultInterceptors());
+        assertNull(epi.getVocabulary());
+        assertNull(epi.getFaultVocabulary());
+        
+        Policy p = control.createMock(Policy.class);
+        Assertion a = control.createMock(Assertion.class);
+        List<Assertion> la = Collections.singletonList(a);
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);
+        control.replay();
+        epi.setPolicy(p);
+        assertSame(p, epi.getPolicy());
+        epi.setChosenAlternative(la);
+        assertSame(la, epi.getChosenAlternative());
+        epi.setInInterceptors(li);
+        assertSame(li, epi.getInInterceptors());
+        epi.setInFaultInterceptors(li);
+        assertSame(li, epi.getInFaultInterceptors());
+        epi.setVocabulary(la);
+        assertSame(la, epi.getVocabulary());
+        epi.setFaultVocabulary(la);
+        assertSame(la, epi.getFaultVocabulary());
+        control.verify();
+    }
+    
+    public void testInitialise() throws NoSuchMethodException {
+        Method m1 = EndpointPolicyInfo.class.getDeclaredMethod("initialisePolicy",
+            new Class[] {EndpointInfo.class, PolicyEngine.class});
+        Method m2 = EndpointPolicyInfo.class.getDeclaredMethod("chooseAlternative",
+            new Class[] {PolicyEngine.class, Assertor.class});
+        Method m3 = EndpointPolicyInfo.class.getDeclaredMethod("initialiseVocabulary",
+            new Class[] {EndpointInfo.class, boolean.class, PolicyEngine.class});
+        Method m4 = EndpointPolicyInfo.class.getDeclaredMethod("initialiseInterceptors",
+            new Class[] {EndpointInfo.class, boolean.class, PolicyEngine.class});
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class, 
+                                                    new Method[] {m1, m2, m3, m4});
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        boolean isServer = true;
+        PolicyEngine pe = control.createMock(PolicyEngine.class);
+        Assertor a = control.createMock(Assertor.class);
+         
+        epi.initialisePolicy(ei, pe);
+        EasyMock.expectLastCall();
+        epi.chooseAlternative(pe, a);
+        EasyMock.expectLastCall();
+        epi.initialiseInterceptors(ei, isServer, pe); 
+        EasyMock.expectLastCall();
+        
+        control.replay();
+        epi.initialise(ei, isServer, pe, a);
+        control.verify();        
+    }
+    
+    public void testInitialisePolicy() {        
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        ServiceInfo si = control.createMock(ServiceInfo.class);
+        EasyMock.expect(ei.getService()).andReturn(si);
+        Policy sp = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedServicePolicy(si)).andReturn(sp);
+        Policy ep = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedEndpointPolicy(ei)).andReturn(ep);
+        Policy merged = control.createMock(Policy.class);
+        EasyMock.expect(sp.merge(ep)).andReturn(merged);
+        EasyMock.expect(merged.normalize(true)).andReturn(merged);
+        
+        control.replay();
+        EndpointPolicyInfo epi = new EndpointPolicyInfo();
+        epi.initialisePolicy(ei, engine);
+        assertSame(merged, epi.getPolicy());
+        control.verify();
+    }
+       
+    public void testChooseAlternative() {
+        EndpointPolicyInfo cpi = new EndpointPolicyInfo();
+        cpi.setPolicy(new Policy());
+        
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        Assertor assertor = control.createMock(Assertor.class);
+               
+        Policy policy = new Policy();
+        ExactlyOne ea = new ExactlyOne();
+        All all = new All();
+        Assertion a1 = new TestAssertion(); 
+        all.addAssertion(a1);
+        ea.addPolicyComponent(all);
+        List<Assertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
+        policy.addPolicyComponent(ea);
+        cpi.setPolicy(policy);
+        
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(false);
+        control.replay();
+        try {
+            cpi.chooseAlternative(engine, assertor);  
+            fail("Expected PolicyException not thrown.");
+        } catch (PolicyException ex) {
+            // expected
+        }
+        control.verify();
+        
+        control.reset();        
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(true);
+        control.replay();        
+        cpi.chooseAlternative(engine, assertor); 
+        
+        Collection<Assertion> chosen = cpi.getChosenAlternative();
+        assertSame(1, chosen.size());
+        assertSame(chosen.size(), firstAlternative.size());
+        assertSame(chosen.iterator().next(), firstAlternative.get(0));
+        
+        // assertSame(cpi.getChosenAlternative(), firstAlternative);
+        control.verify();
+        
+        control.reset();
+        All other = new All();
+        other.addAssertion(a1);
+        ea.addPolicyComponent(other);
+        List<Assertion> secondAlternative = CastUtils.cast(other.getPolicyComponents(), Assertion.class);
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(false);
+        EasyMock.expect(engine.supportsAlternative(secondAlternative, assertor)).andReturn(true);
+        control.replay();        
+        cpi.chooseAlternative(engine, assertor); 
+        chosen = cpi.getChosenAlternative();
+        assertSame(1, chosen.size());
+        assertSame(chosen.size(), secondAlternative.size());
+        assertSame(chosen.iterator().next(), secondAlternative.get(0));
+        control.verify();
+    }
+    
+    public void testInitialiseVocabularyServer() {
+        dotestInitialiseVocabulary(false);
+    }
+    
+    public void testInitialiseVocabularyClient() {
+        dotestInitialiseVocabulary(true);
+    }
+    
+    private void dotestInitialiseVocabulary(boolean requestor) {
+        EndpointPolicyInfo epi = new EndpointPolicyInfo();   
+        List<Assertion> alternative = new ArrayList<Assertion>();
+        epi.setChosenAlternative(alternative);
+        Assertion ea = control.createMock(Assertion.class);        
+        alternative.add(ea);
+        EasyMock.expect(ea.isOptional()).andReturn(false);
+        Assertion eaOpt = control.createMock(Assertion.class);        
+        alternative.add(eaOpt);
+        EasyMock.expect(eaOpt.isOptional()).andReturn(true);
+        
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        BindingInfo bi = control.createMock(BindingInfo.class);
+        EasyMock.expect(ei.getBinding()).andReturn(bi);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        EasyMock.expect(bi.getOperations()).andReturn(Collections.singletonList(boi));
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        Policy op = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedOperationPolicy(boi)).andReturn(op);
+        Assertion oa = control.createMock(Assertion.class);
+        EasyMock.expect(engine.getAssertions(op, false)).andReturn(Collections.singletonList(oa));
+        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+        if (requestor) {
+            EasyMock.expect(boi.getOutput()).andReturn(bmi).times(2);
+        } else {
+            EasyMock.expect(boi.getInput()).andReturn(bmi);
+        }
+        Policy mp = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedMessagePolicy(bmi)).andReturn(mp);
+        Assertion ma = control.createMock(Assertion.class);
+        EasyMock.expect(engine.getAssertions(mp, false)).andReturn(Collections.singletonList(ma));
+        Assertion fa = null;
+        if (requestor) {
+            BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+            EasyMock.expect(boi.getFaults()).andReturn(Collections.singletonList(bfi));
+            Policy fp = control.createMock(Policy.class);
+            EasyMock.expect(engine.getAggregatedFaultPolicy(bfi)).andReturn(fp);
+            fa = control.createMock(Assertion.class);
+            EasyMock.expect(engine.getAssertions(fp, false)).andReturn(Collections.singletonList(fa));
+        }
+        
+        control.replay();
+        epi.initialiseVocabulary(ei, requestor, engine);
+        Collection<Assertion> expected = new ArrayList<Assertion>();
+        expected.add(ea);
+        expected.add(oa);
+        expected.add(ma);
+        verifyVocabulary(expected, epi.getVocabulary());
+        if (requestor) {
+            expected.remove(ma);
+            expected.add(fa);
+            verifyVocabulary(expected, epi.getFaultVocabulary());
+            // 
+        } else {
+            assertNull(epi.getFaultVocabulary());
+        }
+          
+        control.verify();          
+    }
+    
+    private void verifyVocabulary(Collection<Assertion> expected, Collection<Assertion> actual) {
+        
+        assertEquals(expected.size(), actual.size());
+        for (Iterator<Assertion> i = expected.iterator(); i.hasNext();) {
+            Assertion e = i.next();
+            Iterator<Assertion> j = actual.iterator();
+            boolean eFound = false;
+            while (j.hasNext()) {
+                if (e == j.next()) {
+                    eFound = true;
+                    break;
+                }              
+            }
+            assertTrue("Expected assertion not found.", eFound);
+        }
+    }
+    
+    public void testInitialiseInterceptorsServer() {
+        doTestInitialiseInterceptors(false);
+    }
+    
+    public void testInitialiseInterceptorsClient() {
+        doTestInitialiseInterceptors(true);
+    }
+    
+    private void doTestInitialiseInterceptors(boolean requestor) {
+        EndpointPolicyInfo epi = new EndpointPolicyInfo();        
+        Collection<Assertion> v = new ArrayList<Assertion>();
+        Collection<Assertion> fv = new ArrayList<Assertion>();
+        Assertion a = control.createMock(Assertion.class);        
+        v.add(a);
+        QName aqn = new QName("http://x.y.z", "a");
+        EasyMock.expect(a.getName()).andReturn(aqn).times(requestor ? 2 : 1);
+        Assertion aa = control.createMock(Assertion.class);        
+        v.add(aa);
+        EasyMock.expect(aa.getName()).andReturn(aqn).times(requestor ? 2 : 1);
+        fv.addAll(v);
+        epi.setVocabulary(v);
+        epi.setFaultVocabulary(fv);
+        
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class);
+        setupPolicyInterceptorProviderRegistry(engine, reg);
+        
+        PolicyInterceptorProvider app = control.createMock(PolicyInterceptorProvider.class);               
+        EasyMock.expect(reg.get(aqn)).andReturn(app).times(requestor ? 2 : 1);
+        Interceptor api = control.createMock(Interceptor.class);
+        EasyMock.expect(app.getInInterceptors())
+            .andReturn(Collections.singletonList(api));
+        if (requestor) {
+            EasyMock.expect(app.getInFaultInterceptors())
+                .andReturn(Collections.singletonList(api));
+        }
+        
+        control.replay();
+        epi.initialiseInterceptors(ei, requestor, engine);
+        assertEquals(1, epi.getInInterceptors().size());
+        assertSame(api, epi.getInInterceptors().get(0));
+        if (requestor) {
+            assertEquals(1, epi.getInFaultInterceptors().size());
+            assertSame(api, epi.getInFaultInterceptors().get(0));
+        } else {
+            assertNull(epi.getInFaultInterceptors());
+        }
+        control.verify();          
+    }
+    
+    private void setupPolicyInterceptorProviderRegistry(PolicyEngine engine, 
+                                                        PolicyInterceptorProviderRegistry reg) {
+        Bus bus = control.createMock(Bus.class);        
+        EasyMock.expect(engine.getBus()).andReturn(bus);
+        EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg);
+    }
+    
+    public void testCheckEffectivePolicy() {
+        
+    }
+    
+    public void testCheckeffectiveFaultPolicy() {
+        
+    }
+  
+}

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyInfoTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/OutPolicyInfoTest.java (from r510865, incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/ClientPolicyInfoTest.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/OutPolicyInfoTest.java?view=diff&rev=512674&p1=incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/ClientPolicyInfoTest.java&r1=510865&p2=incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/OutPolicyInfoTest.java&r2=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/ClientPolicyInfoTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/OutPolicyInfoTest.java Wed Feb 28 01:29:43 2007
@@ -19,7 +19,9 @@
 
 package org.apache.cxf.ws.policy;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -28,12 +30,15 @@
 import junit.framework.TestCase;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingMessageInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.Destination;
+import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
 import org.apache.neethi.All;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.ExactlyOne;
@@ -44,7 +49,7 @@
 /**
  * 
  */
-public class ClientPolicyInfoTest extends TestCase {
+public class OutPolicyInfoTest extends TestCase {
 
     private IMocksControl control;
     
@@ -53,55 +58,152 @@
     } 
     
     public void testAccessors() {
-        ClientRequestPolicyInfo crpi = new ClientRequestPolicyInfo();
+        OutPolicyInfo opi = new OutPolicyInfo();
+        assertNull(opi.getPolicy());
+        assertNull(opi.getChosenAlternative());
+        assertNull(opi.getInterceptors());
+        
         Policy p = control.createMock(Policy.class);
         Assertion a = control.createMock(Assertion.class);
         List<Assertion> la = Collections.singletonList(a);
         Interceptor i = control.createMock(Interceptor.class);
         List<Interceptor> li = Collections.singletonList(i);
         control.replay();
-        crpi.setRequestPolicy(p);
-        assertSame(p, crpi.getRequestPolicy());
-        crpi.setChosenAlternative(la);
-        assertSame(la, crpi.getChosenAlternative());
-        crpi.setOutInterceptors(li);
-        assertSame(li, crpi.getOutInterceptors());
+        opi.setPolicy(p);
+        assertSame(p, opi.getPolicy());
+        opi.setChosenAlternative(la);
+        assertSame(la, opi.getChosenAlternative());
+        opi.setInterceptors(li);
+        assertSame(li, opi.getInterceptors());
         control.verify();
     }
     
-    public void testInitialiseRequestPolicy() {
+    public void testInitialise() throws NoSuchMethodException {
+        Method m1 = OutPolicyInfo.class.getDeclaredMethod("initialisePolicy",
+            new Class[] {Endpoint.class, BindingOperationInfo.class, PolicyEngine.class, boolean.class});
+        Method m2 = OutPolicyInfo.class.getDeclaredMethod("chooseAlternative",
+            new Class[] {PolicyEngine.class, Assertor.class});
+        Method m3 = OutPolicyInfo.class.getDeclaredMethod("initialiseInterceptors",
+                                                          new Class[] {PolicyEngine.class});
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class, new Method[] {m1, m2, m3});
+        
+        Endpoint e = control.createMock(Endpoint.class);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        PolicyEngine pe = control.createMock(PolicyEngine.class);
+        Assertor a = control.createMock(Assertor.class);
+        boolean requestor = true;
+       
+        opi.initialisePolicy(e, boi, pe, requestor);
+        EasyMock.expectLastCall();
+        opi.chooseAlternative(pe, a);
+        EasyMock.expectLastCall();
+        opi.initialiseInterceptors(pe);
+        EasyMock.expectLastCall();
+        
+        control.replay();
+        opi.initialise(e, boi, pe, a, requestor);
+        control.verify();        
+    }
+    
+    public void testInitialiseFault() throws NoSuchMethodException {
+        Method m1 = OutPolicyInfo.class.getDeclaredMethod("initialisePolicy",
+            new Class[] {Endpoint.class, BindingFaultInfo.class, PolicyEngine.class});
+        Method m2 = OutPolicyInfo.class.getDeclaredMethod("chooseAlternative",
+            new Class[] {PolicyEngine.class, Assertor.class});
+        Method m3 = OutPolicyInfo.class.getDeclaredMethod("initialiseInterceptors",
+                                                          new Class[] {PolicyEngine.class});
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class, new Method[] {m1, m2, m3});
+        
+        Endpoint e = control.createMock(Endpoint.class);
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        PolicyEngine pe = control.createMock(PolicyEngine.class);
+        Assertor a = control.createMock(Assertor.class);
+       
+        opi.initialisePolicy(e, bfi, pe);
+        EasyMock.expectLastCall();
+        opi.chooseAlternative(pe, a);
+        EasyMock.expectLastCall();
+        opi.initialiseInterceptors(pe);
+        EasyMock.expectLastCall();
+        
+        control.replay();
+        opi.initialise(e, bfi, pe, a);
+        control.verify();        
+    }
+    
+    public void testInitialiseClientPolicy() {  
+        doTestInitialisePolicy(true);
+    }
+    
+    public void testInitialiseServerPolicy() {  
+        doTestInitialisePolicy(false);
+    }
+    
+    private void doTestInitialisePolicy(boolean requestor) {        
+        Endpoint e = control.createMock(Endpoint.class);
         BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
-        EndpointInfo ei = control.createMock(EndpointInfo.class);
-        ServiceInfo si = control.createMock(ServiceInfo.class);
-        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
         PolicyEngine engine = control.createMock(PolicyEngine.class);
-           
-        EasyMock.expect(boi.getInput()).andReturn(bmi);
+        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+        if (requestor) {
+            EasyMock.expect(boi.getInput()).andReturn(bmi);
+        } else {
+            EasyMock.expect(boi.getOutput()).andReturn(bmi);
+        }
+                
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class);
+        if (requestor) {
+            EasyMock.expect(engine.getEndpointPolicyInfo(e, (Conduit)null)).andReturn(epi);
+        } else {
+            EasyMock.expect(engine.getEndpointPolicyInfo(e, (Destination)null)).andReturn(epi);
+        }
+        Policy ep = control.createMock(Policy.class);
+        EasyMock.expect(epi.getPolicy()).andReturn(ep);        
+        Policy op = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedOperationPolicy(boi)).andReturn(op);
+        Policy merged = control.createMock(Policy.class);
+        EasyMock.expect(ep.merge(op)).andReturn(merged);
         Policy mp = control.createMock(Policy.class);
         EasyMock.expect(engine.getAggregatedMessagePolicy(bmi)).andReturn(mp);
+        EasyMock.expect(merged.merge(mp)).andReturn(merged);
+        EasyMock.expect(merged.normalize(true)).andReturn(merged);
+        
+        control.replay();
+        OutPolicyInfo opi = new OutPolicyInfo();
+        opi.initialisePolicy(e, boi, engine, requestor);
+        assertSame(merged, opi.getPolicy());
+        control.verify();
+    }
+    
+    public void testInitialiseServerFaultPolicy() {        
+        Endpoint e = control.createMock(Endpoint.class);
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        EasyMock.expect(bfi.getBindingOperation()).andReturn(boi);               
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class);        
+        EasyMock.expect(engine.getEndpointPolicyInfo(e, (Destination)null)).andReturn(epi);
+        Policy ep = control.createMock(Policy.class);
+        EasyMock.expect(epi.getPolicy()).andReturn(ep);        
         Policy op = control.createMock(Policy.class);
         EasyMock.expect(engine.getAggregatedOperationPolicy(boi)).andReturn(op);
         Policy merged = control.createMock(Policy.class);
-        EasyMock.expect(mp.merge(op)).andReturn(merged);
-        Policy ep = control.createMock(Policy.class);
-        EasyMock.expect(engine.getAggregatedEndpointPolicy(ei)).andReturn(ep);
-        EasyMock.expect(merged.merge(ep)).andReturn(merged);
-        EasyMock.expect(ei.getService()).andReturn(si);
-        Policy sp = control.createMock(Policy.class);
-        EasyMock.expect(engine.getAggregatedServicePolicy(si)).andReturn(sp);
-        EasyMock.expect(merged.merge(sp)).andReturn(merged);
+        EasyMock.expect(ep.merge(op)).andReturn(merged);
+        Policy fp = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedFaultPolicy(bfi)).andReturn(fp);
+        EasyMock.expect(merged.merge(fp)).andReturn(merged);
         EasyMock.expect(merged.normalize(true)).andReturn(merged);
         
         control.replay();
-        ClientRequestPolicyInfo cpi = new ClientRequestPolicyInfo();
-        cpi.initialiseRequestPolicy(boi, ei, engine);
-        assertSame(merged, cpi.getRequestPolicy());
+        OutPolicyInfo opi = new OutPolicyInfo();
+        opi.initialisePolicy(e, bfi, engine);
+        assertSame(merged, opi.getPolicy());
         control.verify();
     }
     
     public void testChooseAlternative() {
-        ClientRequestPolicyInfo cpi = new ClientRequestPolicyInfo();
-        cpi.setRequestPolicy(new Policy());
+        OutPolicyInfo cpi = new OutPolicyInfo();
+        cpi.setPolicy(new Policy());
         
         PolicyEngine engine = control.createMock(PolicyEngine.class);
         Assertor assertor = control.createMock(Assertor.class);
@@ -114,7 +216,7 @@
         ea.addPolicyComponent(all);
         List<Assertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
         policy.addPolicyComponent(ea);
-        cpi.setRequestPolicy(policy);
+        cpi.setPolicy(policy);
         
         EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(false);
         control.replay();
@@ -131,10 +233,10 @@
         control.replay();        
         cpi.chooseAlternative(engine, assertor); 
         
-        List<Assertion> chosen = cpi.getChosenAlternative();
+        Collection<Assertion> chosen = cpi.getChosenAlternative();
         assertSame(1, chosen.size());
         assertSame(chosen.size(), firstAlternative.size());
-        assertSame(chosen.get(0), firstAlternative.get(0));
+        assertSame(chosen.iterator().next(), firstAlternative.get(0));
         
         // assertSame(cpi.getChosenAlternative(), firstAlternative);
         control.verify();
@@ -151,12 +253,12 @@
         chosen = cpi.getChosenAlternative();
         assertSame(1, chosen.size());
         assertSame(chosen.size(), secondAlternative.size());
-        assertSame(chosen.get(0), secondAlternative.get(0));
+        assertSame(chosen.iterator().next(), secondAlternative.get(0));
         control.verify();
     }
     
     public void testInitialiseOutInterceptors() {
-        ClientRequestPolicyInfo cpi = new ClientRequestPolicyInfo();        
+        OutPolicyInfo cpi = new OutPolicyInfo();        
         List<Assertion> alternative = new ArrayList<Assertion>();
         cpi.setChosenAlternative(alternative);
         
@@ -166,7 +268,7 @@
         
         control.replay();
         cpi.initialiseInterceptors(engine);
-        assertEquals(0, cpi.getOutInterceptors().size());
+        assertEquals(0, cpi.getInterceptors().size());
         control.verify();
         
         control.reset();
@@ -176,7 +278,7 @@
         EasyMock.expect(a.isOptional()).andReturn(true);
         control.replay();
         cpi.initialiseInterceptors(engine);
-        assertEquals(0, cpi.getOutInterceptors().size());
+        assertEquals(0, cpi.getInterceptors().size());
         control.verify();
         
         control.reset();
@@ -187,7 +289,7 @@
         EasyMock.expect(reg.get(qn)).andReturn(null);
         control.replay();
         cpi.initialiseInterceptors(engine);
-        assertEquals(0, cpi.getOutInterceptors().size());
+        assertEquals(0, cpi.getInterceptors().size());
         control.verify();
         
         control.reset();
@@ -200,8 +302,8 @@
         EasyMock.expect(pp.getOutInterceptors()).andReturn(Collections.singletonList(pi));
         control.replay();
         cpi.initialiseInterceptors(engine);
-        assertEquals(1, cpi.getOutInterceptors().size());
-        assertSame(pi, cpi.getOutInterceptors().get(0));
+        assertEquals(1, cpi.getInterceptors().size());
+        assertSame(pi, cpi.getInterceptors().get(0));
         control.verify();     
     }
     
@@ -211,9 +313,91 @@
         EasyMock.expect(engine.getBus()).andReturn(bus);
         EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg);
     }
-   
-    
     
+    public void testCheckEffectivePolicy() {
+        OutPolicyInfo opi = new OutPolicyInfo();  
+        Policy p = new Policy();
+        QName aqn = new QName("http://x.y.z", "a");
+        Assertion a = new PrimitiveAssertion(aqn);
+        QName bqn = new QName("http://x.y.z", "b");
+        Assertion b = new PrimitiveAssertion(bqn);
+        QName cqn = new QName("http://x.y.z", "c");
+        Assertion c = new PrimitiveAssertion(cqn);
+        All alt1 = new All();
+        alt1.addAssertion(a);
+        alt1.addAssertion(b);
+        All alt2 = new All();
+        alt2.addAssertion(c);
+        ExactlyOne ea = new ExactlyOne();
+        ea.addPolicyComponent(alt1);
+        ea.addPolicyComponent(alt2);
+        p.addPolicyComponent(ea);   
+        AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, Assertion.class));
+        AssertionInfo ai = new AssertionInfo(a);
+        AssertionInfo bi = new AssertionInfo(b);
+        AssertionInfo ci = new AssertionInfo(c);
+        aim.put(aqn, Collections.singleton(ai));
+        aim.put(bqn, Collections.singleton(bi));
+        aim.put(cqn, Collections.singleton(ci));
+        opi.setPolicy(p);
+        
+        try {
+            opi.checkEffectivePolicy(aim);
+            fail("Expected PolicyException not thrown.");
+        } catch (PolicyException ex) {
+            // expected
+        }
+        
+        ai.setAsserted(true);
+        ci.setAsserted(true);
+        
+        opi.checkEffectivePolicy(aim);
+    }
     
-   
+    public void testAlternativeSupported() {
+        Assertion a1 = control.createMock(Assertion.class);
+        QName aqn = new QName("http://x.y.z", "a");
+        EasyMock.expect(a1.getName()).andReturn(aqn).anyTimes();
+        Assertion a2 = control.createMock(Assertion.class);
+        EasyMock.expect(a2.getName()).andReturn(aqn).anyTimes();
+        Assertion b = control.createMock(Assertion.class);
+        QName bqn = new QName("http://x.y.z", "b");
+        EasyMock.expect(b.getName()).andReturn(bqn).anyTimes();
+        Assertion c = control.createMock(Assertion.class);
+        QName cqn = new QName("http://x.y.z", "c");
+        EasyMock.expect(c.getName()).andReturn(cqn).anyTimes();
+        AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, Assertion.class));
+        AssertionInfo ai1 = new AssertionInfo(a1);
+        AssertionInfo ai2 = new AssertionInfo(a2);
+        Collection<AssertionInfo> ais = new ArrayList<AssertionInfo>();
+        AssertionInfo bi = new AssertionInfo(b);
+        AssertionInfo ci = new AssertionInfo(c);
+        ais.add(ai1);
+        ais.add(ai2);
+        aim.put(aqn, ais);
+        aim.put(bqn, Collections.singleton(bi));
+        aim.put(cqn, Collections.singleton(ci));
+        ai2.setAsserted(true);
+        bi.setAsserted(true);
+        ci.setAsserted(true);
+        EasyMock.expect(a1.equal(a1)).andReturn(true).anyTimes();
+        EasyMock.expect(a2.equal(a2)).andReturn(true).anyTimes();
+        EasyMock.expect(b.equal(b)).andReturn(true).anyTimes();
+        EasyMock.expect(c.equal(c)).andReturn(true).anyTimes();
+        
+        
+        List<Assertion> alt1 = new ArrayList<Assertion>();
+        alt1.add(a1);
+        alt1.add(b);
+        
+        List<Assertion> alt2 = new ArrayList<Assertion>();
+        alt2.add(a2);
+        alt2.add(c);
+                
+        OutPolicyInfo opi = new OutPolicyInfo();
+        control.replay();
+        assertTrue(!opi.alternativeSupported(alt1, aim));
+        assertTrue(opi.alternativeSupported(alt2, aim));
+        control.verify();     
+    }  
 }

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java?view=diff&rev=512674&r1=512673&r2=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java Wed Feb 28 01:29:43 2007
@@ -21,11 +21,14 @@
 
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import javax.xml.namespace.QName;
+
 import junit.framework.TestCase;
 
 import org.apache.cxf.Bus;
@@ -38,9 +41,12 @@
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.transport.Conduit;
-import org.apache.cxf.transport.Destination;
+import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Constants;
 import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyComponent;
+import org.apache.neethi.PolicyReference;
 import org.apache.neethi.PolicyRegistry;
 import org.easymock.classextension.EasyMock;
 import org.easymock.classextension.IMocksControl;
@@ -95,9 +101,9 @@
         List<Interceptor> inFault = new ArrayList<Interceptor>();
         List<Interceptor> outFault = new ArrayList<Interceptor>();
         if (add) {
-            EasyMock.expect(bus.getOutInterceptors()).andReturn(out).times(2);
-            EasyMock.expect(bus.getInInterceptors()).andReturn(in).times(2);
-            EasyMock.expect(bus.getInFaultInterceptors()).andReturn(inFault);
+            EasyMock.expect(bus.getOutInterceptors()).andReturn(out).times(3);
+            EasyMock.expect(bus.getInInterceptors()).andReturn(in).times(3);
+            EasyMock.expect(bus.getInFaultInterceptors()).andReturn(inFault).times(2);
             EasyMock.expect(bus.getOutFaultInterceptors()).andReturn(outFault);
             control.replay();
         }
@@ -109,14 +115,17 @@
             Set<String> idsIn = getInterceptorIds(in);
             Set<String> idsInFault = getInterceptorIds(inFault);
             Set<String> idsOutFault = getInterceptorIds(outFault);
-            assertEquals(2, out.size());
+            assertEquals(3, out.size());
             assertTrue(idsOut.contains(PolicyConstants.CLIENT_POLICY_OUT_INTERCEPTOR_ID));
             assertTrue(idsOut.contains(PolicyConstants.SERVER_POLICY_OUT_INTERCEPTOR_ID));
-            assertEquals(2, in.size());
+            assertTrue(idsOut.contains(PolicyVerificationOutInterceptor.class.getName()));
+            assertEquals(3, in.size());
             assertTrue(idsIn.contains(PolicyConstants.CLIENT_POLICY_IN_INTERCEPTOR_ID));
             assertTrue(idsIn.contains(PolicyConstants.SERVER_POLICY_IN_INTERCEPTOR_ID));
-            assertEquals(1, inFault.size());
+            assertTrue(idsIn.contains(PolicyVerificationInInterceptor.class.getName()));
+            assertEquals(2, inFault.size());
             assertTrue(idsInFault.contains(PolicyConstants.CLIENT_POLICY_IN_FAULT_INTERCEPTOR_ID));
+            assertTrue(idsInFault.contains(PolicyVerificationInFaultInterceptor.class.getName()));
             assertEquals(1, outFault.size());
             assertTrue(idsOutFault.contains(PolicyConstants.SERVER_POLICY_OUT_FAULT_INTERCEPTOR_ID));
         } else {
@@ -305,6 +314,7 @@
         control.verify();      
     }
     
+    /*
     public void testGetClientOutInterceptors() throws NoSuchMethodException {
         Method m = PolicyEngine.class.getDeclaredMethod("getClientRequestPolicyInfo",
                                                         new Class[] {Endpoint.class,
@@ -314,11 +324,11 @@
         BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
         Endpoint e = control.createMock(Endpoint.class);
         Conduit conduit = control.createMock(Conduit.class);
-        ClientRequestPolicyInfo cpi = control.createMock(ClientRequestPolicyInfo.class);
+        OutPolicyInfo cpi = control.createMock(OutPolicyInfo.class);
         EasyMock.expect(engine.getClientRequestPolicyInfo(e, boi, conduit)).andReturn(cpi);
         Interceptor i = control.createMock(Interceptor.class);
         List<Interceptor> li = Collections.singletonList(i);
-        EasyMock.expect(cpi.getOutInterceptors()).andReturn(li);        
+        EasyMock.expect(cpi.getInterceptors()).andReturn(li);        
 
         control.replay();
         List<Interceptor> clientInterceptors = engine.getClientOutInterceptors(e, boi, conduit); 
@@ -326,6 +336,29 @@
         control.verify();
     }
     
+    public void testGetClientOutAssertions() throws NoSuchMethodException {
+        Method m = PolicyEngine.class.getDeclaredMethod("getClientRequestPolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingOperationInfo.class,
+                                                                     Conduit.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Conduit conduit = control.createMock(Conduit.class);
+        OutPolicyInfo cpi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(engine.getClientRequestPolicyInfo(e, boi, conduit)).andReturn(cpi);
+        Assertion a = control.createMock(Assertion.class);
+        List<Assertion> la = Collections.singletonList(a);
+        EasyMock.expect(cpi.getChosenAlternative()).andReturn(la);        
+
+        control.replay();
+        Collection<Assertion> assertions = engine.getClientOutAssertions(e, boi, conduit); 
+        assertSame(la, assertions);
+        control.verify();
+    }
+    */
+    
+    /*
     public void testGetClientInInterceptors() throws NoSuchMethodException { 
         doTestGetInterceptors(false, false);
     }
@@ -339,13 +372,171 @@
     }
     
     public void testServerOutInterceptors() throws NoSuchMethodException {
-        doTestGetServerOutInterceptors(false);
+        Method m = PolicyEngine.class.getDeclaredMethod("getServerResponsePolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingOperationInfo.class,
+                                                                     Destination.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Destination destination = control.createMock(Destination.class);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(engine.getServerResponsePolicyInfo(e, boi, destination)).andReturn(opi);
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);        
+        EasyMock.expect(opi.getInterceptors()).andReturn(li);
+
+        control.replay();
+        List<Interceptor> interceptors = engine.getServerOutInterceptors(e, boi, destination);
+        assertSame(li, interceptors);
+        control.verify();
+    }
+    
+    public void testServerOutAssertions() throws NoSuchMethodException {
+        Method m = PolicyEngine.class.getDeclaredMethod("getServerResponsePolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingOperationInfo.class,
+                                                                     Destination.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Destination destination = control.createMock(Destination.class);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(engine.getServerResponsePolicyInfo(e, boi, destination)).andReturn(opi);
+        Assertion a = control.createMock(Assertion.class);
+        List<Assertion> la = Collections.singletonList(a);        
+        EasyMock.expect(opi.getChosenAlternative()).andReturn(la);
+
+        control.replay();
+        Collection<Assertion> assertions = engine.getServerOutAssertions(e, boi, destination);
+        assertSame(la, assertions);
+        control.verify();
     }
     
     public void testServerOutFaultInterceptors() throws NoSuchMethodException {
-        doTestGetServerOutInterceptors(true);
+        Method m = PolicyEngine.class.getDeclaredMethod("getServerFaultPolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingFaultInfo.class,
+                                                                     Destination.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Destination destination = control.createMock(Destination.class);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(engine.getServerFaultPolicyInfo(e, bfi, destination)).andReturn(opi);
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);  
+        EasyMock.expect(opi.getInterceptors()).andReturn(li);
+
+        control.replay();
+        List<Interceptor> interceptors = engine.getServerOutFaultInterceptors(e, bfi, destination);
+        assertSame(li, interceptors);
+        control.verify();
+    }
+    
+    public void testServerOutFaultAssertions() throws NoSuchMethodException {
+        Method m = PolicyEngine.class.getDeclaredMethod("getServerFaultPolicyInfo",
+                                                        new Class[] {Endpoint.class,
+                                                                     BindingFaultInfo.class,
+                                                                     Destination.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        Endpoint e = control.createMock(Endpoint.class);
+        Destination destination = control.createMock(Destination.class);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(engine.getServerFaultPolicyInfo(e, bfi, destination)).andReturn(opi);
+        Assertion a = control.createMock(Assertion.class);
+        List<Assertion> la = Collections.singletonList(a);  
+        EasyMock.expect(opi.getChosenAlternative()).andReturn(la);
+
+        control.replay();
+        Collection<Assertion> assertions = engine.getServerOutFaultAssertions(e, bfi, destination);
+        assertSame(la, assertions);
+        control.verify();
+    }
+    */
+    
+    public void testGetAssertions() throws NoSuchMethodException {
+        Method m = PolicyEngine.class.getDeclaredMethod("addAssertions",
+            new Class[] {PolicyComponent.class, boolean.class, Collection.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        Assertion a = control.createMock(Assertion.class);
+        EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
+        EasyMock.expect(a.isOptional()).andReturn(true);
+        
+        control.replay();
+        assertTrue(engine.getAssertions(a, false).isEmpty());
+        control.verify();
+        
+        control.reset();
+        EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
+        // EasyMock.expect(a.isOptional()).andReturn(false);
+        
+        control.replay();
+        Collection<Assertion> ca = engine.getAssertions(a, true);
+        assertEquals(1, ca.size());
+        assertSame(a, ca.iterator().next());
+        control.verify();
+        
+        control.reset();
+        Policy p = control.createMock(Policy.class);
+        EasyMock.expect(p.getType()).andReturn(Constants.TYPE_POLICY);
+        engine.addAssertions(EasyMock.eq(p), EasyMock.eq(false), 
+                             CastUtils.cast(EasyMock.isA(Collection.class), Assertion.class));
+        EasyMock.expectLastCall();
+        
+        control.replay();
+        assertTrue(engine.getAssertions(p, false).isEmpty());
+        control.verify();
+    }
+    
+    public void testAddAssertions() {
+        engine = new PolicyEngine();
+        Collection<Assertion> assertions = new ArrayList<Assertion>();
+        
+        Assertion a = control.createMock(Assertion.class);
+        EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
+        EasyMock.expect(a.isOptional()).andReturn(true);
+        
+        control.replay();
+        engine.addAssertions(a, false, assertions);
+        assertTrue(assertions.isEmpty());
+        control.verify();
+        
+        control.reset();
+        EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION);
+        control.replay();
+        engine.addAssertions(a, true, assertions);
+        assertEquals(1, assertions.size());
+        assertSame(a, assertions.iterator().next());        
+        control.verify();
+        
+        assertions.clear();
+        Policy p = new Policy();
+        a = new PrimitiveAssertion(new QName("http://x.y.z", "a"));
+        p.addAssertion(a);
+        PolicyReference pr = new PolicyReference();
+        pr.setURI("a#b");
+        engine.getRegistry().register("a#b", p);
+        
+        engine.addAssertions(pr, false, assertions);
+        assertEquals(1, assertions.size());
+        assertSame(a, assertions.iterator().next());       
+    }
+    
+    public void testKeys() {
+        engine = new PolicyEngine();
+        Endpoint endpoint = control.createMock(Endpoint.class);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        PolicyEngine.BindingOperation bo = engine.new BindingOperation(endpoint, boi);
+        assertNotNull(bo);
+        
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        PolicyEngine.BindingFault bf = engine.new BindingFault(endpoint, bfi);
+        assertNotNull(bf);      
     }
      
+    /*
     private void doTestGetInterceptors(boolean isServer, boolean fault) throws NoSuchMethodException {
         Method m = PolicyEngine.class.getDeclaredMethod("getEndpointPolicyInfo",
             new Class[] {Endpoint.class, isServer ? Destination.class : Conduit.class});
@@ -380,33 +571,7 @@
         assertSame(li, interceptors);
         control.verify(); 
     }
-    
-    private void doTestGetServerOutInterceptors(boolean fault) throws NoSuchMethodException {
-
-        Method m = PolicyEngine.class.getDeclaredMethod("getServerResponsePolicyInfo",
-                                                        new Class[] {Endpoint.class,
-                                                                     BindingOperationInfo.class,
-                                                                     Destination.class});
-        engine = control.createMock(PolicyEngine.class, new Method[] {m});
-        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
-        Endpoint e = control.createMock(Endpoint.class);
-        Destination destination = control.createMock(Destination.class);
-        ServerResponsePolicyInfo srpi = control.createMock(ServerResponsePolicyInfo.class);
-        EasyMock.expect(engine.getServerResponsePolicyInfo(e, boi, destination)).andReturn(srpi);
-        Interceptor i = control.createMock(Interceptor.class);
-        List<Interceptor> li = Collections.singletonList(i);
-        if (fault) {
-            EasyMock.expect(srpi.getOutFaultInterceptors()).andReturn(li);
-        } else {
-            EasyMock.expect(srpi.getOutInterceptors()).andReturn(li);
-        }
-
-        control.replay();
-        List<Interceptor> interceptors = fault ? engine.getServerOutFaultInterceptors(e, boi, destination)
-            : engine.getServerOutInterceptors(e, boi, destination);
-        assertSame(li, interceptors);
-        control.verify();
-    }
+    */
     
     private Set<String> getInterceptorIds(List<Interceptor> interceptors) {
         Set<String> ids = new HashSet<String>();

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java?view=diff&rev=512674&r1=512673&r2=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java Wed Feb 28 01:29:43 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.ws.policy;
 
+import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Collections;
 
@@ -31,7 +32,9 @@
 import org.apache.cxf.interceptor.InterceptorChain;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.FaultInfo;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
 import org.apache.neethi.Assertion;
@@ -59,6 +62,13 @@
         bus = control.createMock(Bus.class);       
     } 
     
+    public void testAbstractPolicyInterceptor() {
+        ClientPolicyOutInterceptor interceptor = new ClientPolicyOutInterceptor();
+        assertNull(interceptor.getBus());
+        interceptor.setBus(bus);
+        assertSame(bus, interceptor.getBus());
+    }
+    
     public void testClientPolicyOutInterceptor() {
         ClientPolicyOutInterceptor interceptor = new ClientPolicyOutInterceptor();
         interceptor.setBus(bus);
@@ -66,17 +76,20 @@
         doTestBasics(interceptor, true, true);
         
         control.reset();
-        setupMessage(true, true, true, true, true, true);
+        setupMessage(true, true, true, true, true, true);        
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(pe.getClientRequestPolicyInfo(endpoint, boi, conduit)).andReturn(opi);
         Interceptor i = control.createMock(Interceptor.class);
-        EasyMock.expect(pe.getClientOutInterceptors(endpoint, boi, conduit))
+        EasyMock.expect(opi.getInterceptors())
             .andReturn(CastUtils.cast(Collections.singletonList(i), Interceptor.class));
         InterceptorChain ic = control.createMock(InterceptorChain.class);
         EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
         ic.add(i);
         EasyMock.expectLastCall();
         Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
-        EasyMock.expect(pe.getClientOutAssertions(endpoint, boi, conduit)).andReturn(assertions);
-        EasyMock.expect(message.put(PolicyConstants.CLIENT_OUT_ASSERTIONS, assertions)).andReturn(null);
+        EasyMock.expect(opi.getChosenAlternative()).andReturn(assertions);
+        message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
+        EasyMock.expectLastCall();
         control.replay();
         interceptor.handleMessage(message);
         control.verify();        
@@ -89,14 +102,20 @@
         doTestBasics(interceptor, true, false);
         
         control.reset();
-        setupMessage(true, true, false, false, true, true);
+        setupMessage(true, true, false, false, true, true);        
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class);
+        EasyMock.expect(pe.getEndpointPolicyInfo(endpoint, conduit)).andReturn(epi);
         Interceptor i = control.createMock(Interceptor.class);
-        EasyMock.expect(pe.getClientInInterceptors(endpoint, conduit))
+        EasyMock.expect(epi.getInInterceptors())
             .andReturn(CastUtils.cast(Collections.singletonList(i), Interceptor.class));
         InterceptorChain ic = control.createMock(InterceptorChain.class);
         EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
         ic.add(i);
         EasyMock.expectLastCall();
+        Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
+        EasyMock.expect(epi.getVocabulary()).andReturn(assertions);
+        message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
+        EasyMock.expectLastCall();
         control.replay();
         interceptor.handleMessage(message);
         control.verify();        
@@ -110,13 +129,19 @@
         
         control.reset();
         setupMessage(true, true, false, false, true, true);
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class);
+        EasyMock.expect(pe.getEndpointPolicyInfo(endpoint, conduit)).andReturn(epi);
         Interceptor i = control.createMock(Interceptor.class);
-        EasyMock.expect(pe.getClientInFaultInterceptors(endpoint, conduit))
+        EasyMock.expect(epi.getInFaultInterceptors())
             .andReturn(CastUtils.cast(Collections.singletonList(i), Interceptor.class));
         InterceptorChain ic = control.createMock(InterceptorChain.class);
         EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
         ic.add(i);
         EasyMock.expectLastCall();
+        Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
+        EasyMock.expect(epi.getFaultVocabulary()).andReturn(assertions);
+        message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
+        EasyMock.expectLastCall();
         control.replay();
         interceptor.handleMessage(message);
         control.verify();        
@@ -127,19 +152,25 @@
         interceptor.setBus(bus);
         
         doTestBasics(interceptor, false, false);
-        
+
         control.reset();
         setupMessage(false, false, false, false, true, true);
+        EndpointPolicyInfo epi = control.createMock(EndpointPolicyInfo.class);
+        EasyMock.expect(pe.getEndpointPolicyInfo(endpoint, destination)).andReturn(epi);
         Interceptor i = control.createMock(Interceptor.class);
-        EasyMock.expect(pe.getServerInInterceptors(endpoint, destination))
+        EasyMock.expect(epi.getInInterceptors())
             .andReturn(CastUtils.cast(Collections.singletonList(i), Interceptor.class));
         InterceptorChain ic = control.createMock(InterceptorChain.class);
         EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
         ic.add(i);
         EasyMock.expectLastCall();
+        Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
+        EasyMock.expect(epi.getVocabulary()).andReturn(assertions);
+        message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
+        EasyMock.expectLastCall();
         control.replay();
         interceptor.handleMessage(message);
-        control.verify();        
+        control.verify();       
     }
     
     public void testServerPolicyOutInterceptor() {
@@ -150,43 +181,90 @@
         
         control.reset();
         setupMessage(false, false, true, true, true, true);
-        Interceptor i = control.createMock(Interceptor.class);
-        EasyMock.expect(pe.getServerOutInterceptors(endpoint, boi, destination))
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(pe.getServerResponsePolicyInfo(endpoint, boi, destination)).andReturn(opi);
+        Interceptor i = control.createMock(Interceptor.class);        
+        EasyMock.expect(opi.getInterceptors())
             .andReturn(CastUtils.cast(Collections.singletonList(i), Interceptor.class));
         InterceptorChain ic = control.createMock(InterceptorChain.class);
         EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
         ic.add(i);
         EasyMock.expectLastCall();
         Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
-        EasyMock.expect(pe.getServerOutAssertions(endpoint, boi, destination)).andReturn(assertions);
-        EasyMock.expect(message.put(PolicyConstants.SERVER_OUT_ASSERTIONS, assertions)).andReturn(null);
+        EasyMock.expect(opi.getChosenAlternative()).andReturn(assertions);
+        message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
+        EasyMock.expectLastCall();
         control.replay();
         interceptor.handleMessage(message);
         control.verify();        
     }
     
-    public void testServerPolicyOutFaultInterceptor() {
-        ServerPolicyOutFaultInterceptor interceptor = new ServerPolicyOutFaultInterceptor();
+    public void testServerPolicyOutFaultInterceptor() throws NoSuchMethodException {
+        Method m = ServerPolicyOutFaultInterceptor.class.getDeclaredMethod("getBindingFaultInfo",
+            new Class[] {Message.class, Exception.class, BindingOperationInfo.class});
+        
+        ServerPolicyOutFaultInterceptor interceptor = 
+            control.createMock(ServerPolicyOutFaultInterceptor.class, new Method[] {m});
         interceptor.setBus(bus);
         
         doTestBasics(interceptor, false, true);
         
         control.reset();
         setupMessage(false, false, true, true, true, true);
+        Exception ex = control.createMock(Exception.class);
+        EasyMock.expect(exchange.get(Exception.class)).andReturn(ex);
+        EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(null);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();  
+         
+        control.reset();
+        setupMessage(false, false, true, true, true, true);
+        // Exception ex = control.createMock(Exception.class);
+        EasyMock.expect(exchange.get(Exception.class)).andReturn(ex);
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(bfi);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);
+        EasyMock.expect(pe.getServerFaultPolicyInfo(endpoint, bfi, destination)).andReturn(opi);
         Interceptor i = control.createMock(Interceptor.class);
-        EasyMock.expect(pe.getServerOutFaultInterceptors(endpoint, boi, destination))
+        EasyMock.expect(opi.getInterceptors())
             .andReturn(CastUtils.cast(Collections.singletonList(i), Interceptor.class));
         InterceptorChain ic = control.createMock(InterceptorChain.class);
         EasyMock.expect(message.getInterceptorChain()).andReturn(ic);
         ic.add(i);
         EasyMock.expectLastCall();
+        Collection<Assertion> assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class);
+        EasyMock.expect(opi.getChosenAlternative()).andReturn(assertions);
+        message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class));
+        EasyMock.expectLastCall();
         control.replay();
         interceptor.handleMessage(message);
         control.verify();        
     }
     
+    public void testServerPolicyOutFaultInterceptorGetBindingFaultInfo() {
+        ServerPolicyOutFaultInterceptor interceptor = new ServerPolicyOutFaultInterceptor();
+        message = control.createMock(Message.class);
+        Exception ex = new UnsupportedOperationException();
+        boi = control.createMock(BindingOperationInfo.class);
+        EasyMock.expect(message.get(BindingFaultInfo.class)).andReturn(null);
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        Collection<BindingFaultInfo> bfis = CastUtils.cast(Collections.singletonList(bfi));
+        EasyMock.expect(boi.getFaults()).andReturn(bfis);
+        FaultInfo fi = control.createMock(FaultInfo.class);
+        EasyMock.expect(bfi.getFaultInfo()).andReturn(fi);
+        EasyMock.expect(fi.getProperty(Class.class.getName(), Class.class))
+            .andReturn(RuntimeException.class);
+        message.put(BindingFaultInfo.class, bfi);
+        EasyMock.expectLastCall();
+        
+        control.replay();
+        assertSame(bfi, interceptor.getBindingFaultInfo(message, ex, boi));
+        control.verify();        
+    }
+   
     private void doTestBasics(Interceptor<Message> interceptor, boolean isClient, boolean usesOperationInfo) {
-        setupMessage(!isClient, isClient, usesOperationInfo, false, false, false);
+        setupMessage(!isClient, isClient, usesOperationInfo, !usesOperationInfo, false, false);
         control.replay();
         interceptor.handleMessage(message);
         control.verify();
@@ -198,13 +276,13 @@
         control.verify();
         
         control.reset();
-        setupMessage(true, isClient, usesOperationInfo, usesOperationInfo, false, false);
+        setupMessage(isClient, isClient, usesOperationInfo, usesOperationInfo, false, false);
         control.replay();
         interceptor.handleMessage(message);
         control.verify();
             
         control.reset();
-        setupMessage(true, isClient, usesOperationInfo, usesOperationInfo, true, false);
+        setupMessage(isClient, isClient, usesOperationInfo, usesOperationInfo, true, false);
         control.replay();
         interceptor.handleMessage(message);
         control.verify();
@@ -217,6 +295,14 @@
                       Boolean setupEndpoint, 
                       Boolean setupEngine) {
 
+        /*
+        System.out.println("setupMessage, setupRequestor: " + setupRequestor
+                           + ", isClient: " + isClient
+                           + ", usesOperationInfo: " + usesOperationInfo
+                           + ", setupOperation: " + setupOperation
+                           + ", setupEndpoint: " + setupEndpoint
+                           + ", setupEngine: " + setupEngine);
+        */                  
         message = control.createMock(Message.class);
         EasyMock.expect(message.get(Message.REQUESTOR_ROLE))
             .andReturn(setupRequestor ? Boolean.TRUE : Boolean.FALSE);
@@ -244,13 +330,6 @@
         if (!setupEndpoint) {
             return;
         }
-        
-        /*
-        if (null == ei) {
-            ei = control.createMock(EndpointInfo.class);            
-        }
-        EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei);
-        */
         
         if (null == pe && setupEngine) {
             pe = control.createMock(PolicyEngine.class);

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java?view=auto&rev=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java Wed Feb 28 01:29:43 2007
@@ -0,0 +1,142 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.policy;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingFaultInfo;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class PolicyVerificationInFaultInterceptorTest extends TestCase {
+ 
+    private IMocksControl control;
+    private Bus bus;
+    private Message message;
+    private Exchange exchange;
+    private BindingFaultInfo bfi;
+    private Endpoint endpoint;
+    private PolicyEngine engine;
+    private AssertionInfoMap aim;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl(); 
+        bus = control.createMock(Bus.class);  
+    } 
+    
+    public void testHandleMessage() {
+        PolicyVerificationInFaultInterceptor interceptor = 
+            new PolicyVerificationInFaultInterceptor();
+        interceptor.setBus(bus);
+        
+        setupMessage(false, false, false, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, false, false, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, false, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, true, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, true, true);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);        
+        EasyMock.expect(engine.getClientFaultPolicyInfo(endpoint, bfi)).andReturn(opi);
+        opi.checkEffectivePolicy(aim);
+        EasyMock.expectLastCall();
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+    }
+    
+    void setupMessage(boolean requestor,
+                      boolean setupBindingFaultInfo,
+                      boolean setupEndpoint,
+                      boolean setupPolicyEngine,
+                      boolean setupAssertionInfoMap) {
+        if (null == message) {
+            message = control.createMock(Message.class); 
+        }
+        if (null == exchange) {
+            exchange = control.createMock(Exchange.class);            
+        }
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(
+            requestor ? Boolean.TRUE : Boolean.FALSE);
+        if (!requestor) {
+            return;
+        }
+        
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        if (setupBindingFaultInfo && null == bfi) {
+            bfi = control.createMock(BindingFaultInfo.class);
+        }
+        EasyMock.expect(message.get(BindingFaultInfo.class)).andReturn(bfi);
+        if (!setupBindingFaultInfo) {
+            return;
+        }
+        if (setupEndpoint && null == endpoint) {
+            endpoint = control.createMock(Endpoint.class);
+        }
+        EasyMock.expect(exchange.get(Endpoint.class)).andReturn(endpoint);
+        if (!setupEndpoint) {
+            return;
+        }
+        
+        if (setupPolicyEngine && null == engine) {
+            engine = control.createMock(PolicyEngine.class);
+        }
+        EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(engine);
+        if (!setupPolicyEngine) {
+            return;           
+        }
+        if (setupAssertionInfoMap && null == aim) {
+            aim = control.createMock(AssertionInfoMap.class);
+        }
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java?view=auto&rev=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java Wed Feb 28 01:29:43 2007
@@ -0,0 +1,147 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.policy;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class PolicyVerificationInInterceptorTest extends TestCase {
+ 
+    private IMocksControl control;
+    private Bus bus;
+    private Message message;
+    private Exchange exchange;
+    private BindingOperationInfo boi;
+    private Endpoint endpoint;
+    private PolicyEngine engine;
+    private AssertionInfoMap aim;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl(); 
+        bus = control.createMock(Bus.class);  
+    } 
+    
+    public void testHandleMessage() {
+        PolicyVerificationInInterceptor interceptor = new PolicyVerificationInInterceptor();
+        interceptor.setBus(bus);
+        
+        setupMessage(false, false, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, false, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        control.reset();
+        setupMessage(true, true, false, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, false);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, true);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
+        OutPolicyInfo opi = control.createMock(OutPolicyInfo.class);        
+        EasyMock.expect(engine.getServerRequestPolicyInfo(endpoint, boi)).andReturn(opi);
+        opi.checkEffectivePolicy(aim);
+        EasyMock.expectLastCall();
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, true);
+        EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.TRUE);  
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        setupMessage(true, true, true, true);
+        EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(null);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);  
+        EasyMock.expect(engine.getClientResponsePolicyInfo(endpoint, boi)).andReturn(opi);
+        opi.checkEffectivePolicy(aim);
+        EasyMock.expectLastCall();
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+    }
+    
+    void setupMessage(boolean setupBindingOperationInfo,
+                      boolean setupEndpoint,
+                      boolean setupPolicyEngine,
+                      boolean setupAssertionInfoMap) {
+        if (null == message) {
+            message = control.createMock(Message.class); 
+        }
+        if (null == exchange) {
+            exchange = control.createMock(Exchange.class);            
+        }
+        EasyMock.expect(message.getExchange()).andReturn(exchange);
+        if (setupBindingOperationInfo && null == boi) {
+            boi = control.createMock(BindingOperationInfo.class);
+        }
+        EasyMock.expect(exchange.get(BindingOperationInfo.class)).andReturn(boi);
+        if (!setupBindingOperationInfo) {
+            return;
+        }
+        if (setupEndpoint && null == endpoint) {
+            endpoint = control.createMock(Endpoint.class);
+        }
+        EasyMock.expect(exchange.get(Endpoint.class)).andReturn(endpoint);
+        if (!setupEndpoint) {
+            return;
+        }
+        
+        if (setupPolicyEngine && null == engine) {
+            engine = control.createMock(PolicyEngine.class);
+        }
+        EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(engine);
+        if (!setupPolicyEngine) {
+            return;           
+        }
+        if (setupAssertionInfoMap && null == aim) {
+            aim = control.createMock(AssertionInfoMap.class);
+        }
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java?view=auto&rev=512674
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java Wed Feb 28 01:29:43 2007
@@ -0,0 +1,98 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.ws.policy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.message.Message;
+import org.apache.neethi.Assertion;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class PolicyVerificationOutInterceptorTest extends TestCase {
+ 
+    private IMocksControl control;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl();   
+    } 
+    
+    public void testHandleMessage() {
+        PolicyVerificationOutInterceptor interceptor = new PolicyVerificationOutInterceptor();
+        
+        Message message = control.createMock(Message.class);
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();
+        
+        control.reset();
+        Collection<Assertion> assertions = new ArrayList<Assertion>();
+        AssertionInfoMap aim = new AssertionInfoMap(assertions);
+        
+        Assertion a1 = control.createMock(Assertion.class);   
+        AssertionInfo ai1 = new AssertionInfo(a1);
+        Assertion a2 = control.createMock(Assertion.class);
+        AssertionInfo ai2 = new AssertionInfo(a2);
+        Assertion a3 = control.createMock(Assertion.class);
+        AssertionInfo ai3 = new AssertionInfo(a3);
+        
+        QName n1 = new QName("http://x.b.c/x", "a1"); 
+        QName n2 = new QName("http://x.b.c/x", "a2");
+        
+        Collection<AssertionInfo> c = new ArrayList<AssertionInfo>();
+        c.add(ai1);
+        c.add(ai2);
+        aim.put(n1, c);
+        c = new ArrayList<AssertionInfo>();
+        c.add(ai3);
+        aim.put(n2, c);
+        
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
+        
+        control.replay();
+        try {
+            interceptor.handleMessage(message);
+            fail("Expected PolicyException not thrown.");
+        } catch (PolicyException ex) {
+            // expected
+        }
+        control.verify();
+        
+        control.reset();
+        ai1.setAsserted(true);
+        ai2.setAsserted(true);
+        ai3.setAsserted(true);
+
+        EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
+        
+        control.replay();        
+        interceptor.handleMessage(message);       
+        control.verify();
+    }
+}

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message