cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r504621 [1/2] - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/phase/ api/src/main/java/org/apache/cxf/ws/policy/ api/src/test/java/org/apache/cxf/phase/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ rt/ws/policy/src/main/...
Date Wed, 07 Feb 2007 17:11:27 GMT
Author: andreasmyth
Date: Wed Feb  7 09:11:23 2007
New Revision: 504621

URL: http://svn.apache.org/viewvc?view=rev&rev=504621
Log:
[JIRA CXF-376] Support for (WSDL 1.1) attachment to fault message policy subjects.
{JIRA CXF-379] Client side interceptors to determine effective policy for outbound message, choose an alternative and add the interceptors required to assert the chosen alternative's assertions. 

Added:
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInfo.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertingConduit.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/ClientPolicyInfoTest.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyTest.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/TestAssertion.java   (with props)
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/policy/
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/policy/RMPolicyInterceptorProvider.java   (with props)
    incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/policy/
    incubator/cxf/trunk/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/policy/RMPolicyExtensionsTest.java   (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyProvider.java
    incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/builders/jaxb/JaxbAssertionBuilder.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builders/jaxb/JaxbAssertionBuilderTest.java
    incubator/cxf/trunk/rt/ws/rm/pom.xml
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMConstants.java
    incubator/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMOutInterceptor.java
    incubator/cxf/trunk/rt/ws/rm/src/main/resources/META-INF/cxf/cxf-extension-rm.xml
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/ControlImpl.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java?view=diff&rev=504621&r1=504620&r2=504621
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/phase/PhaseInterceptorChain.java Wed Feb  7 09:11:23 2007
@@ -81,19 +81,27 @@
         }
         iterator = new PhaseInterceptorIterator();
     }
-
+    
     public void add(List<Interceptor> newhandlers) {
+        add(newhandlers, false);
+    }
+
+    public void add(List<Interceptor> newhandlers, boolean force) {
         if (newhandlers == null) {
             return;
         }
 
         for (Interceptor handler : newhandlers) {
-            add(handler);
+            add(handler, force);
         }
     }
 
-    @SuppressWarnings("unchecked")
     public void add(Interceptor i) {
+        add(i, false);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public void add(Interceptor i, boolean force) {
         PhaseInterceptor pi = (PhaseInterceptor)i;
 
         if (LOG.isLoggable(Level.FINE)) {
@@ -106,7 +114,7 @@
         if (phase == null) {
             LOG.fine("Phase " + phaseName + " does not exist. Skipping handler "
                       + i.getClass().getName());
-        } else {
+        } else if (force | !phase.contains(pi)) {            
             insertInterceptor(phase, pi);
         }
     }
@@ -171,6 +179,7 @@
                     faultOccured = true;
                     if (LOG.isLoggable(Level.FINE)) {
                         LogUtils.log(LOG, Level.FINE, "Interceptor has thrown exception, unwinding now", ex);
+                        ex.printStackTrace();
                     }
                     message.setContent(Exception.class, ex);
                     if (message.getExchange() != null) {

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyProvider.java?view=diff&rev=504621&r1=504620&r2=504621
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyProvider.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyProvider.java Wed Feb  7 09:11:23 2007
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.ws.policy;
 
+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;
@@ -37,5 +38,7 @@
     Policy getEffectivePolicy(BindingOperationInfo bi);
     
     Policy getEffectivePolicy(BindingMessageInfo bmi);
+    
+    Policy getEffectivePolicy(BindingFaultInfo bfi);
     
 }

Modified: incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java?view=diff&rev=504621&r1=504620&r2=504621
==============================================================================
--- incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java (original)
+++ incubator/cxf/trunk/api/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java Wed Feb  7 09:11:23 2007
@@ -68,6 +68,20 @@
         assertSame(p, it.next());
         assertTrue(!it.hasNext());
     }
+    
+    public void testForceAddOneInterceptor() {
+        AbstractPhaseInterceptor p = setUpPhaseInterceptor("phase1", "p1");
+        control.replay();
+        chain.add(p, false);
+        Iterator<Interceptor<? extends Message>> it = chain.iterator();
+        assertSame(p, it.next());
+        assertTrue(!it.hasNext());
+        chain.add(p, true);
+        it = chain.iterator();
+        assertSame(p, it.next());
+        assertSame(p, it.next());
+        assertTrue(!it.hasNext());        
+    }
 
     @SuppressWarnings("unchecked")
     public void testAddTwoInterceptorsSamePhase() {

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInFaultInterceptor.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,88 @@
+/**
+ * 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.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+
+/**
+ * 
+ */
+public class ClientPolicyInFaultInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    private Bus bus;
+    
+    public ClientPolicyInFaultInterceptor() {
+        setPhase(Phase.PRE_LOGICAL);
+    }
+        
+    public void setBus(Bus b) {
+        bus = b;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    public void handleMessage(Message msg) {        
+        if (!PolicyUtils.isRequestor(msg)) {
+            return;
+        }
+        
+        BindingOperationInfo boi = msg.get(BindingOperationInfo.class);
+        if (null == boi) {
+            return;
+        }
+        
+        EndpointInfo ei = msg.get(EndpointInfo.class);
+        if (null == ei) {
+            return;
+        }
+        
+        PolicyEngine pe = bus.getExtension(PolicyEngine.class);
+        if (null == pe) {
+            return;
+        }
+        
+        Conduit conduit = msg.getConduit();
+        
+        // We do not know the underlying message type yet - so we pre-emptively add interceptors 
+        // that can deal with the response and all of the operation's possible fault messages.
+        
+        List<Interceptor> policyInFaultInterceptors = pe.getClientInFaultInterceptors(boi, ei, conduit);
+        for (Interceptor poi : policyInFaultInterceptors) {
+            msg.getInterceptorChain().add(poi);
+        }
+        
+        // TODO:
+        // In addition we add an interceptor that towards the end of the chain determines the
+        // effective policy of the underlying message and checks if any of its alternatives are
+        // supported.
+        
+    }
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInInterceptor.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,88 @@
+/**
+ * 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.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+
+/**
+ * 
+ */
+public class ClientPolicyInInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    private Bus bus;
+    
+    public ClientPolicyInInterceptor() {
+        setPhase(Phase.PRE_LOGICAL);
+    }
+        
+    public void setBus(Bus b) {
+        bus = b;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    public void handleMessage(Message msg) {        
+        if (!PolicyUtils.isRequestor(msg)) {
+            return;
+        }
+        
+        BindingOperationInfo boi = msg.get(BindingOperationInfo.class);
+        if (null == boi) {
+            return;
+        }
+        
+        EndpointInfo ei = msg.get(EndpointInfo.class);
+        if (null == ei) {
+            return;
+        }
+        
+        PolicyEngine pe = bus.getExtension(PolicyEngine.class);
+        if (null == pe) {
+            return;
+        }
+        
+        Conduit conduit = msg.getConduit();
+        
+        // We do not know the underlying message type yet - so we pre-emptively add interceptors 
+        // that can deal with the response and all of the operation's possible fault messages.
+        
+        List<Interceptor> policyInInterceptors = pe.getClientInInterceptors(boi, ei, conduit);
+        for (Interceptor poi : policyInInterceptors) {
+            msg.getInterceptorChain().add(poi);
+        }
+        
+        // TODO:
+        // In addition we add an interceptor that towards the end of the chain determines the
+        // effective policy of the underlying message and checks if any of its alternatives are
+        // supported..
+        
+    }
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInfo.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInfo.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyInfo.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,203 @@
+/**
+ * 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.Iterator;
+import java.util.List;
+import java.util.ResourceBundle;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.interceptor.AbstractAttributedInterceptorProvider;
+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.transport.Conduit;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+/**
+ * 
+ */
+public class ClientPolicyInfo extends AbstractAttributedInterceptorProvider  {
+    
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ClientPolicyInfo.class);
+    
+    private Policy requestPolicy;
+    private Policy responsePolicy;
+     
+    private List<Assertion> chosenAlternative;
+    private List<Assertion> responseVocabulary;
+    
+    void initialise(BindingOperationInfo boi, EndpointInfo ei, Conduit conduit, PolicyEngine engine) {
+        initialiseRequestPolicy(boi, ei, engine);
+        chooseAlternative(conduit, engine);
+        initialiseOutInterceptors(engine);  
+        initialiseResponsePolicy(boi, ei, engine);
+        initialiseInInterceptors(engine);
+    }
+    
+    public Policy getRequestPolicy() {
+        return requestPolicy;        
+    }
+    
+    void setRequestPolicy(Policy ep) {
+        requestPolicy = ep;
+    }
+    
+    public Policy getResponsePolicy() {
+        return responsePolicy;        
+    }
+    
+    void setResponsePolicy(Policy ep) {
+        responsePolicy = ep;
+    }
+    
+    public List<Assertion> getChosenAlternative() {
+        return chosenAlternative;
+    }
+    
+    void setChosenAlternative(List<Assertion> c) {
+        chosenAlternative = c;
+    }
+    
+    public List<Assertion> getResponseVolcabulary() {
+        return responseVocabulary;
+    }
+    
+    void setResponseVocabulary(List<Assertion> rv) {
+        responseVocabulary = rv;
+    }
+    
+    /**
+     * Get the effective policy for the outbound message specified by the binding operation 
+     * by merging the policies from the policy providers and normalising the result.
+     * 
+     * @param boi the binding operation info specifying the outbound message
+     * @param engine the policy engine
+     * 
+     * @return the normalised, effective policy for the outbound message
+     */
+    void initialiseRequestPolicy(BindingOperationInfo boi, EndpointInfo ei, PolicyEngine engine) {
+        BindingMessageInfo bmi = boi.getInput();
+
+        requestPolicy = engine.getAggregatedMessagePolicy(bmi);
+        requestPolicy = requestPolicy.merge(engine.getAggregatedOperationPolicy(boi));
+        requestPolicy = requestPolicy.merge(engine.getAggregatedEndpointPolicy(ei));
+        requestPolicy = requestPolicy.merge(engine.getAggregatedServicePolicy(ei.getService()));
+        requestPolicy = (Policy)requestPolicy.normalize(true);
+    }
+
+    /**
+     * Choose the first alternative for which the vocabulary is supported.
+     * 
+     * @param conduit the conduit
+     * @param engine the policy engine
+     * @throws PolicyException if no such alternative exists
+     */
+    void chooseAlternative(Conduit conduit, PolicyEngine engine) {
+        Iterator alternatives = requestPolicy.getAlternatives();
+        while (alternatives.hasNext()) {
+            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
+            if (engine.supportsAlternative(alternative, conduit)) {
+                setChosenAlternative(alternative);
+                return;
+            }
+        }
+        throw new PolicyException(new Message("CLIENT_OUT_NO_ALTERNATIVE_EXC", BUNDLE));
+
+    }
+    
+
+    /** 
+     * Based on the chosen alternative, determine the interceptors that need to be present on the
+     * outbound chain in order to support the assertions in this alternative.
+     * @param engine the policy engine
+     */
+    void initialiseOutInterceptors(PolicyEngine engine) {
+        PolicyInterceptorProviderRegistry reg 
+            = engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class);
+        List<Interceptor> out = new ArrayList<Interceptor>();
+        for (Assertion a : getChosenAlternative()) {
+            if (a.isOptional()) {
+                continue;
+            }
+            QName qn = a.getName();
+            PolicyInterceptorProvider pp = reg.get(qn);
+            if (null != pp) {
+                out.addAll(pp.getOutInterceptors());
+            }
+        }
+        setOutInterceptors(out);
+    }
+    
+    void initialiseResponsePolicy(BindingOperationInfo boi, EndpointInfo ei, PolicyEngine engine) {
+        BindingMessageInfo bmi = boi.getOutput();
+        if (null == bmi) {
+            return;
+        }
+        responsePolicy = engine.getAggregatedMessagePolicy(bmi);
+        for (BindingFaultInfo bfi : boi.getFaults()) {
+            responsePolicy = responsePolicy.merge(engine.getAggregatedFaultPolicy(bfi));
+        }
+        responsePolicy = responsePolicy.merge(engine.getAggregatedOperationPolicy(boi));
+        responsePolicy = responsePolicy.merge(engine.getAggregatedEndpointPolicy(ei));
+        responsePolicy = responsePolicy.merge(engine.getAggregatedServicePolicy(ei.getService()));
+        responsePolicy = (Policy)responsePolicy.normalize(true);         
+    }
+    
+    /** 
+     * Based on the calculated response policy, determine the interceptors that need to be present on the
+     * outbound chain in order to support the assertions in this alternative.
+     * @param engine the policy engine
+     */
+    void initialiseInInterceptors(PolicyEngine engine) {
+        if (null == responsePolicy) {
+            return;
+        }
+        PolicyInterceptorProviderRegistry reg 
+            = engine.getBus().getExtension(PolicyInterceptorProviderRegistry.class);
+        List<Interceptor> in = new ArrayList<Interceptor>();
+        List<Interceptor> inFault = new ArrayList<Interceptor>();
+        Iterator alternatives = responsePolicy.getAlternatives();
+        while (alternatives.hasNext()) {
+            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
+            for (Assertion a : alternative) {
+                if (a.isOptional()) {
+                    continue;
+                }
+                QName qn = a.getName();
+                PolicyInterceptorProvider pp = reg.get(qn);
+                if (null != pp) {
+                    in.addAll(pp.getInInterceptors());
+                    inFault.addAll(pp.getInFaultInterceptors());
+                }
+            }
+        }
+        setInInterceptors(in);
+        setInFaultInterceptors(inFault);
+    }
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/ClientPolicyOutInterceptor.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,81 @@
+/**
+ * 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.List;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+
+/**
+ * 
+ */
+public class ClientPolicyOutInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    private Bus bus;
+    
+    public ClientPolicyOutInterceptor() {
+        setPhase(Phase.PRE_LOGICAL);
+    }
+    
+    public void setBus(Bus b) {
+        bus = b;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    public void handleMessage(Message msg) {
+        if (!PolicyUtils.isRequestor(msg)) {
+            return;
+        }
+        
+        BindingOperationInfo boi = msg.get(BindingOperationInfo.class);
+        if (null == boi) {
+            return;
+        }
+        
+        EndpointInfo ei = msg.get(EndpointInfo.class);
+        if (null == ei) {
+            return;
+        }        
+        
+        PolicyEngine pe = bus.getExtension(PolicyEngine.class);
+        if (null == pe) {
+            return;
+        }
+        
+        Conduit conduit = msg.getConduit();
+        
+        // add the interceptors required to satisfy the policies
+        // for this operation
+        List<Interceptor> policyOutInterceptors = pe.getClientOutInterceptors(boi, ei, conduit);
+        for (Interceptor poi : policyOutInterceptors) {
+            msg.getInterceptorChain().add(poi);
+        }
+    }
+}

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

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

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties?view=diff&rev=504621&r1=504620&r2=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/Messages.properties Wed Feb  7 09:11:23 2007
@@ -21,4 +21,5 @@
 IMMUTABLE_POLICY_MODIFICATION_EXC = Attempt to modify immutable policy object.
 NO_ASSERTIONBUILDER_EXC = No assertion builder for type {0} registered.
 NOT_A_POLICY_ELEMENT_EXC = Specified element is not a Policy element.
-NOT_A_POLICYREF_ELEMENT_EXC = Specified element is not a PolicyReference element.
\ No newline at end of file
+NOT_A_POLICYREF_ELEMENT_EXC = Specified element is not a PolicyReference element.
+CLIENT_OUT_NO_ALTERNATIVE_EXC = None of the policy alternatives can be satisfied.
\ No newline at end of file

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,236 @@
+/**
+ * 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.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.extension.BusExtensionRegistrar;
+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.ws.policy.attachment.wsdl11.Wsdl11AttachmentPolicyProvider;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+/**
+ * 
+ */
+public class PolicyEngine {
+    
+    private Bus bus;
+    private PolicyBuilder builder;
+    private List<PolicyProvider> policyProviders;
+
+    private Map<BindingOperationInfo, ClientPolicyInfo> clientInfo 
+        = new ConcurrentHashMap<BindingOperationInfo, ClientPolicyInfo>();
+
+    public PolicyEngine() {
+        this(null);
+    }
+    public PolicyEngine(BusExtensionRegistrar registrar) {
+        if (null != registrar) {
+            registrar.registerExtension(this, PolicyEngine.class);
+            bus = registrar.getBus();
+        }
+    }
+    
+    public void setBus(Bus b) {
+        bus = b;
+    }
+    
+    public Bus getBus() {
+        return bus;
+    }
+    
+    public void setPolicyProviders(List<PolicyProvider> p) {
+        policyProviders = p;
+    }
+   
+    public List<PolicyProvider> getPolicyProviders() {
+        return policyProviders;
+    }
+    
+    public void setBuilder(PolicyBuilder b) {
+        builder = b;
+    }
+    
+    public PolicyBuilder getBuilder() {
+        return builder;
+    }
+        
+    @PostConstruct
+    void init() {
+        if (null == builder && null != bus) {
+            builder = new PolicyBuilder();
+            builder.setAssertionBuilderRegistry(bus.getExtension(AssertionBuilderRegistry.class));
+        }
+
+        if (null == policyProviders) {
+            // TODO:
+            // include attachment provider for wsdl 2.0 and
+            // for external attachments
+            Wsdl11AttachmentPolicyProvider wpp = new Wsdl11AttachmentPolicyProvider();
+            wpp.setBuilder(builder);
+            policyProviders = Collections.singletonList((PolicyProvider)wpp);
+        }    
+    }
+    
+    @PostConstruct
+    void addBusInterceptors() {
+        if (null == bus) {
+            return;
+        }
+
+        ClientPolicyOutInterceptor clientOut = new ClientPolicyOutInterceptor();
+        clientOut.setBus(bus);
+        bus.getOutInterceptors().add(clientOut);
+        ClientPolicyInInterceptor clientIn = new ClientPolicyInInterceptor();
+        clientIn.setBus(bus);
+        bus.getInInterceptors().add(clientIn);
+        ClientPolicyInFaultInterceptor clientInFault = new ClientPolicyInFaultInterceptor();
+        clientInFault.setBus(bus);
+        bus.getInFaultInterceptors().add(clientInFault);
+        
+        // TODO: server side
+    }
+
+    public List<Interceptor> getClientOutInterceptors(BindingOperationInfo boi, 
+                                                      EndpointInfo ei, Conduit conduit) {
+        return getClientPolicyInfo(boi, ei, conduit).getOutInterceptors();
+    }
+    
+    public List<Interceptor> getClientInInterceptors(BindingOperationInfo boi, 
+                                                     EndpointInfo ei, Conduit conduit) {
+        return getClientPolicyInfo(boi, ei, conduit).getInInterceptors();
+    }
+    
+    public List<Interceptor> getClientInFaultInterceptors(BindingOperationInfo boi, 
+                                                     EndpointInfo ei, Conduit conduit) {
+        return getClientPolicyInfo(boi, ei, conduit).getInFaultInterceptors();
+    }
+
+    public Policy getAggregatedServicePolicy(ServiceInfo si) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(si);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+
+    public Policy getAggregatedEndpointPolicy(EndpointInfo ei) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(ei);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    public Policy getAggregatedOperationPolicy(BindingOperationInfo boi) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(boi);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    public Policy getAggregatedMessagePolicy(BindingMessageInfo bmi) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(bmi);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+    
+    public Policy getAggregatedFaultPolicy(BindingFaultInfo bfi) {
+        Policy aggregated = null;
+        for (PolicyProvider pp : getPolicyProviders()) {
+            Policy p = pp.getEffectivePolicy(bfi);
+            if (null == aggregated) {
+                aggregated = p;
+            } else {
+                aggregated = aggregated.merge(p);
+            }
+        }
+        return aggregated == null ? new Policy() : aggregated;
+    }
+
+    /**
+     * Check if a given list of assertions can be supported by the conduit or
+     * interceptors (which, if necessary, can be added to the interceptor
+     * chain).
+     * 
+     * @param alternative the policy alternative
+     * @param conduit the conduit
+     * @return true iff the alternative can be supported
+     */
+    boolean supportsAlternative(List<Assertion> alternative, Conduit conduit) {
+        PolicyInterceptorProviderRegistry pipr = bus.getExtension(PolicyInterceptorProviderRegistry.class);
+        for (Assertion a : alternative) {
+            if (!(a.isOptional() 
+                || (null != pipr.get(a.getName())) 
+                || ((conduit instanceof Assertor) && ((Assertor)conduit).asserts(a)))) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    ClientPolicyInfo getClientPolicyInfo(BindingOperationInfo boi, EndpointInfo ei, Conduit conduit) {
+        ClientPolicyInfo cpi = clientInfo.get(boi);
+        if (null == cpi) {
+            cpi = new ClientPolicyInfo();
+            cpi.initialise(boi, ei, conduit, this);
+            clientInfo.put(boi, cpi);
+        }
+        return cpi;
+    }
+
+
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,42 @@
+/**
+ * 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 org.apache.cxf.message.Message;
+
+/**
+ * 
+ */
+public final class PolicyUtils {
+
+    private PolicyUtils() {
+    }
+
+    /**
+     * Determine if current messaging role is that of requestor.
+     * 
+     * @param message the current Message
+     * @return true iff the current messaging role is that of requestor
+     */
+    public static boolean isRequestor(Message message) {
+        Boolean requestor = (Boolean)message.get(Message.REQUESTOR_ROLE);
+        return requestor != null && requestor.booleanValue();
+    }
+}

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

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

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java?view=diff&rev=504621&r1=504620&r2=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProvider.java Wed Feb  7 09:11:23 2007
@@ -40,6 +40,7 @@
 import org.apache.cxf.service.model.DescriptionInfo;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.service.model.Extensible;
+import org.apache.cxf.service.model.FaultInfo;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.cxf.ws.policy.PolicyBuilder;
@@ -63,7 +64,7 @@
         new HashMap<DescriptionInfo, Map<String, Policy>>();
     
     
-    void setBuilder(PolicyBuilder b) {
+    public void setBuilder(PolicyBuilder b) {
         builder = b;
     }
     
@@ -94,7 +95,7 @@
      * element that defines the operation merged with that of the corresponding 
      * wsdl11:binding/wsdl11:operation element.
      * 
-     * @param bi the BindingOperationInfo identifying the oeration in relation to a port
+     * @param bi the BindingOperationInfo identifying the operation in relation to a port
      * @return the effective policy
      */
     public Policy getEffectivePolicy(BindingOperationInfo bi) {
@@ -106,10 +107,10 @@
     
     /**
      * The effective policy for a specific WSDL message (input or output) is calculated
-     * in relation to a specific port. and includes the element policy of the wsdl:message
-     * element that defines the message's type mered with the element policy of the 
+     * in relation to a specific port, and includes the element policy of the wsdl:message
+     * element that defines the message's type merged with the element policy of the 
      * wsdl11:binding and wsdl11:portType message definitions that describe the message.
-     * For example, the effective policy of a specific inout message for a specific port
+     * For example, the effective policy of a specific input message for a specific port
      * would be the (element policies of the) wsdl11:message element defining the message type,
      * the wsdl11:portType/wsdl11:operation/wsdl11:input element and the corresponding
      * wsdl11:binding/wsdl11:operation/wsdl11:input element for that message.
@@ -122,11 +123,9 @@
         DescriptionInfo di = si.getDescription();
 
         Policy p = getElementPolicy(bmi, di);
-        p = p.merge(getElementPolicy(bmi.getMessageInfo(), di));
-
         MessageInfo mi = bmi.getMessageInfo();
+        p = p.merge(getElementPolicy(mi, di));
         Extensible ex = getMessageTypeInfo(mi.getName(), di);
-  
         p = p.merge(getElementPolicy(ex, di));
 
         return p;
@@ -134,8 +133,17 @@
     
 
     
-    Policy getEffectivePolicy(BindingFaultInfo bfi) {
-        return null;
+    public Policy getEffectivePolicy(BindingFaultInfo bfi) {
+        ServiceInfo si = bfi.getBindingOperation().getBinding().getService();
+        DescriptionInfo di = si.getDescription();
+
+        Policy p = getElementPolicy(bfi, di);
+        FaultInfo fi = bfi.getFaultInfo();
+        p = p.merge(getElementPolicy(fi, di));
+        Extensible ex = getMessageTypeInfo(fi.getName(), di);
+        p = p.merge(getElementPolicy(ex, di));
+
+        return p;
     }
     
     Policy getElementPolicy(AbstractDescriptionElement adh) {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/builders/jaxb/JaxbAssertionBuilder.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/builders/jaxb/JaxbAssertionBuilder.java?view=diff&rev=504621&r1=504620&r2=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/builders/jaxb/JaxbAssertionBuilder.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/builders/jaxb/JaxbAssertionBuilder.java Wed Feb  7 09:11:23 2007
@@ -32,7 +32,9 @@
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.ws.policy.AssertionBuilder;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.Constants;
@@ -43,16 +45,43 @@
     private Unmarshaller unmarshaller;
     private Collection<QName> supportedTypes;
     
+    /**
+     * Constructs a JAXBAssertionBuilder from the QName of the schema type
+     * @param qn the schema type
+     * @throws JAXBException
+     * @throws ClassNotFoundException
+     */
+    public JaxbAssertionBuilder(QName qn) throws JAXBException, ClassNotFoundException {
+        this(JAXBUtils.namespaceURIToPackage(qn.getNamespaceURI())
+            + "." + JAXBUtils.nameToIdentifier(qn.getLocalPart(), JAXBUtils.IdentifierType.CLASS), qn);
+    }
+    
+    /**
+     * Constructs a JAXBAssertionBuilder from the specified class name and schema type. 
+     * @param className the name of the class to which the schema type is mapped
+     * @param qn the schema type
+     * @throws JAXBException
+     * @throws ClassNotFoundException
+     */
+    @SuppressWarnings("unchecked")
+    public JaxbAssertionBuilder(String className, QName qn) throws JAXBException, ClassNotFoundException {
+        this(ClassLoaderUtils.loadClass(className, JaxbAssertionBuilder.class), qn);
+    }
     
+    /**
+    * Constructs a JAXBAssertionBuilder from the specified class and schema type. 
+    * @param class the class to which the schema type is mapped
+    * @param qn the schema type
+    * @throws JAXBException
+    * @throws ClassNotFoundException
+    */
     public JaxbAssertionBuilder(Class<T> type, QName qn) throws JAXBException {
 
         JAXBContext context = JAXBContext.newInstance(type.getPackage().getName());
         unmarshaller = context.createUnmarshaller();
         supportedTypes = Collections.singletonList(qn);
-        
     }
-   
-    
+       
     @SuppressWarnings("unchecked")
     public Assertion build(Element element) {
         Object obj = null;

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertingConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertingConduit.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertingConduit.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertingConduit.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,29 @@
+/**
+ * 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 org.apache.cxf.transport.Conduit;
+
+/**
+ * 
+ */
+public interface AssertingConduit extends Assertor, Conduit {
+
+}

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

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

Added: 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/ClientPolicyInfoTest.java?view=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/ClientPolicyInfoTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/ClientPolicyInfoTest.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,313 @@
+/**
+ * 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.Collections;
+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.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.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 ClientPolicyInfoTest extends TestCase {
+
+    private IMocksControl control;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl();        
+    } 
+    
+    public void testAccessors() {
+        ClientPolicyInfo cpi = new ClientPolicyInfo();
+        Policy p = control.createMock(Policy.class);
+        Assertion a = control.createMock(Assertion.class);
+        List<Assertion> la = Collections.singletonList(a);
+        control.replay();
+        cpi.setRequestPolicy(p);
+        assertSame(p, cpi.getRequestPolicy());
+        cpi.setChosenAlternative(la);
+        assertSame(la, cpi.getChosenAlternative());
+        cpi.setResponsePolicy(p);
+        assertSame(p, cpi.getResponsePolicy());
+        control.verify();
+    }
+    
+    public void testInitialiseRequestPolicy() {
+        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);
+        Policy mp = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedMessagePolicy(bmi)).andReturn(mp);
+        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(merged.normalize(true)).andReturn(merged);
+        
+        control.replay();
+        ClientPolicyInfo cpi = new ClientPolicyInfo();
+        cpi.initialiseRequestPolicy(boi, ei, engine);
+        assertSame(merged, cpi.getRequestPolicy());
+        control.verify();
+    }
+    
+    public void testChooseAlternative() {
+        ClientPolicyInfo cpi = new ClientPolicyInfo();
+        cpi.setRequestPolicy(new Policy());
+        
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        Conduit conduit = control.createMock(Conduit.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.setRequestPolicy(policy);
+        
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, conduit)).andReturn(false);
+        control.replay();
+        try {
+            cpi.chooseAlternative(conduit, engine);  
+            fail("Expected PolicyException not thrown.");
+        } catch (PolicyException ex) {
+            // expected
+        }
+        control.verify();
+        
+        control.reset();        
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, conduit)).andReturn(true);
+        control.replay();        
+        cpi.chooseAlternative(conduit, engine); 
+        
+        List<Assertion> chosen = cpi.getChosenAlternative();
+        assertSame(1, chosen.size());
+        assertSame(chosen.size(), firstAlternative.size());
+        assertSame(chosen.get(0), 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, conduit)).andReturn(false);
+        EasyMock.expect(engine.supportsAlternative(secondAlternative, conduit)).andReturn(true);
+        control.replay();        
+        cpi.chooseAlternative(conduit, engine); 
+        chosen = cpi.getChosenAlternative();
+        assertSame(1, chosen.size());
+        assertSame(chosen.size(), secondAlternative.size());
+        assertSame(chosen.get(0), secondAlternative.get(0));
+        control.verify();
+    }
+    
+    public void testInitialiseOutInterceptors() {
+        ClientPolicyInfo cpi = new ClientPolicyInfo();        
+        List<Assertion> alternative = new ArrayList<Assertion>();
+        cpi.setChosenAlternative(alternative);
+        
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class);
+        setupPolicyInterceptorProviderRegistry(engine, reg);
+        
+        control.replay();
+        cpi.initialiseOutInterceptors(engine);
+        assertEquals(0, cpi.getOutInterceptors().size());
+        control.verify();
+        
+        control.reset();
+        setupPolicyInterceptorProviderRegistry(engine, reg);
+        Assertion a = control.createMock(Assertion.class);        
+        alternative.add(a);
+        EasyMock.expect(a.isOptional()).andReturn(true);
+        control.replay();
+        cpi.initialiseOutInterceptors(engine);
+        assertEquals(0, cpi.getOutInterceptors().size());
+        control.verify();
+        
+        control.reset();
+        setupPolicyInterceptorProviderRegistry(engine, reg);
+        EasyMock.expect(a.isOptional()).andReturn(false);
+        QName qn = new QName("http://x.y.z", "a");
+        EasyMock.expect(a.getName()).andReturn(qn);
+        EasyMock.expect(reg.get(qn)).andReturn(null);
+        control.replay();
+        cpi.initialiseOutInterceptors(engine);
+        assertEquals(0, cpi.getOutInterceptors().size());
+        control.verify();
+        
+        control.reset();
+        setupPolicyInterceptorProviderRegistry(engine, reg);
+        EasyMock.expect(a.isOptional()).andReturn(false);
+        EasyMock.expect(a.getName()).andReturn(qn);        
+        PolicyInterceptorProvider pp = control.createMock(PolicyInterceptorProvider.class);               
+        EasyMock.expect(reg.get(qn)).andReturn(pp);
+        Interceptor pi = control.createMock(Interceptor.class);
+        EasyMock.expect(pp.getOutInterceptors()).andReturn(Collections.singletonList(pi));
+        control.replay();
+        cpi.initialiseOutInterceptors(engine);
+        assertEquals(1, cpi.getOutInterceptors().size());
+        assertSame(pi, cpi.getOutInterceptors().get(0));
+        control.verify();     
+    }
+
+ 
+    public void testInitialiseResponsePolicyOn() {
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        
+        EasyMock.expect(boi.getOutput()).andReturn(null);
+        control.replay();
+        ClientPolicyInfo cpi = new ClientPolicyInfo();
+        cpi.initialiseResponsePolicy(boi, ei, engine);
+        assertNull(cpi.getResponsePolicy());
+        control.verify();
+        control.reset();
+        
+        
+        ServiceInfo si = control.createMock(ServiceInfo.class);
+        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);                     
+        EasyMock.expect(boi.getOutput()).andReturn(bmi);        
+        Policy mp = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedMessagePolicy(bmi)).andReturn(mp);
+        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);
+        Policy merged = control.createMock(Policy.class);
+        EasyMock.expect(mp.merge(fp)).andReturn(merged);        
+        Policy op = control.createMock(Policy.class);
+        EasyMock.expect(engine.getAggregatedOperationPolicy(boi)).andReturn(op);    
+        EasyMock.expect(merged.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(merged.normalize(true)).andReturn(merged);
+        
+        control.replay();
+        cpi = new ClientPolicyInfo();
+        cpi.initialiseResponsePolicy(boi, ei, engine);
+        assertSame(merged, cpi.getResponsePolicy());
+        control.verify();
+    }
+    
+    public void testInitialiseInInterceptors() {
+        ClientPolicyInfo cpi = new ClientPolicyInfo();    
+        Policy responsePolicy = new Policy();
+        ExactlyOne ea = new ExactlyOne();
+        All alt1 = new All();  
+        QName qn1 = new QName("http://x.y.z", "a1");
+        TestAssertion a1 = new TestAssertion(qn1);
+        alt1.addAssertion(a1);
+        All alt2 = new All();
+        QName qn2 = new QName("http://x.y.z", "a2");
+        TestAssertion a2 = new TestAssertion(qn2);
+        alt2.addAssertion(a2);
+        ea.addPolicyComponent(alt1);
+        ea.addPolicyComponent(alt2);
+        responsePolicy.addPolicyComponent(ea);        
+ 
+        PolicyEngine engine = control.createMock(PolicyEngine.class);
+        PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class);
+        
+        control.replay();
+        cpi.initialiseInInterceptors(engine);
+        assertTrue(cpi.getInInterceptors().isEmpty());
+        assertTrue(cpi.getInFaultInterceptors().isEmpty());
+        control.verify();
+        
+        control.reset();
+        cpi.setResponsePolicy(responsePolicy);
+        setupPolicyInterceptorProviderRegistry(engine, reg);
+        PolicyInterceptorProvider p1 = control.createMock(PolicyInterceptorProvider.class);
+        EasyMock.expect(reg.get(qn1)).andReturn(p1);
+        PolicyInterceptorProvider p2 = control.createMock(PolicyInterceptorProvider.class);
+        EasyMock.expect(reg.get(qn2)).andReturn(p2);
+        Interceptor i1 = control.createMock(Interceptor.class);
+        EasyMock.expect(p1.getInInterceptors()).andReturn(Collections.singletonList(i1));
+        EasyMock.expect(p1.getInFaultInterceptors())
+            .andReturn(CastUtils.cast(Collections.EMPTY_LIST, Interceptor.class));
+        Interceptor i2 = control.createMock(Interceptor.class);
+        EasyMock.expect(p2.getInInterceptors()).andReturn(Collections.singletonList(i2));
+        Interceptor fi2 = control.createMock(Interceptor.class);
+        EasyMock.expect(p2.getInFaultInterceptors())
+            .andReturn(Collections.singletonList(fi2));
+           
+        control.replay();
+        cpi.initialiseInInterceptors(engine);
+        assertEquals(2, cpi.getInInterceptors().size());
+        assertEquals(1, cpi.getInFaultInterceptors().size());
+        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);
+    }
+   
+    
+    
+    
+   
+}

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

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

Added: 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=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,354 @@
+/**
+ * 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.Collections;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.extension.BusExtensionRegistrar;
+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.neethi.Policy;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class PolicyEngineTest extends TestCase {
+
+    private IMocksControl control;
+    private PolicyEngine engine;
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl(); 
+    } 
+    
+    public void testAccessors() {
+        engine = new PolicyEngine();
+        assertNull(engine.getBuilder());
+        assertNull(engine.getPolicyProviders());
+        PolicyBuilder builder = control.createMock(PolicyBuilder.class);
+        engine.setBuilder(builder);
+        Bus bus = control.createMock(Bus.class);
+        engine.setBus(bus);
+        List<PolicyProvider> providers = CastUtils.cast(Collections.EMPTY_LIST, PolicyProvider.class);
+        engine.setPolicyProviders(providers);
+        assertSame(builder, engine.getBuilder());
+        assertSame(bus, engine.getBus());
+        assertSame(providers, engine.getPolicyProviders());
+    }
+    
+    public void testInit() {  
+        Bus bus = control.createMock(Bus.class);
+        BusExtensionRegistrar br = control.createMock(BusExtensionRegistrar.class);
+        br.registerExtension((PolicyEngine)EasyMock.isA(PolicyEngine.class), 
+                             EasyMock.eq(PolicyEngine.class));
+        EasyMock.expectLastCall();
+        EasyMock.expect(br.getBus()).andReturn(bus);
+        AssertionBuilderRegistry abr = control.createMock(AssertionBuilderRegistry.class);
+        EasyMock.expect(bus.getExtension(AssertionBuilderRegistry.class)).andReturn(abr);
+        
+        control.replay();
+        engine = new PolicyEngine(br);
+        engine.init();
+        assertSame(bus, engine.getBus());
+        assertEquals(1, engine.getPolicyProviders().size());
+        assertNotNull(engine.getBuilder());
+        control.verify();    
+    }
+    
+    public void testAddBusInterceptors() {        
+        engine = new PolicyEngine();
+        engine.addBusInterceptors();
+        
+        Bus bus = control.createMock(Bus.class);
+        engine.setBus(bus);
+        List<Interceptor> out = new ArrayList<Interceptor>();
+        List<Interceptor> in = new ArrayList<Interceptor>();
+        List<Interceptor> inFault = new ArrayList<Interceptor>();
+        EasyMock.expect(bus.getOutInterceptors()).andReturn(out);
+        EasyMock.expect(bus.getInInterceptors()).andReturn(in);
+        EasyMock.expect(bus.getInFaultInterceptors()).andReturn(inFault);
+        
+        control.replay();
+        engine.addBusInterceptors();
+        assertEquals(1, out.size());
+        assertTrue(out.get(0) instanceof ClientPolicyOutInterceptor);
+        assertEquals(1, in.size());
+        assertTrue(in.get(0) instanceof ClientPolicyInInterceptor);
+        assertEquals(1, inFault.size());
+        assertTrue(inFault.get(0) instanceof ClientPolicyInFaultInterceptor);
+        control.verify();
+    }
+    
+    public void testGetAggregatedServicePolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        ServiceInfo si = control.createMock(ServiceInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedServicePolicy(si);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(si)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedServicePolicy(si));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(si)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(si)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedServicePolicy(si));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedEndpointPolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedEndpointPolicy(ei);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(ei)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedEndpointPolicy(ei));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(ei)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(ei)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedEndpointPolicy(ei));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedOperationPolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedOperationPolicy(boi);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(boi)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedOperationPolicy(boi));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(boi)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(boi)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedOperationPolicy(boi));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedMessagePolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedMessagePolicy(bmi);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bmi)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedMessagePolicy(bmi));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bmi)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(bmi)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedMessagePolicy(bmi));
+        control.verify();      
+    }
+    
+    public void testGetAggregatedFaultPolicy() {
+        engine = new PolicyEngine();
+        List<PolicyProvider> providers = new ArrayList<PolicyProvider>();
+        engine.setPolicyProviders(providers);
+        BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class);
+        
+        control.replay();
+        Policy p = engine.getAggregatedFaultPolicy(bfi);
+        assertTrue(p.isEmpty());
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider1 = control.createMock(PolicyProvider.class);
+        providers.add(provider1);
+        Policy p1 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bfi)).andReturn(p1);
+        
+        control.replay();
+        assertSame(p1, engine.getAggregatedFaultPolicy(bfi));
+        control.verify();
+        control.reset();
+        
+        PolicyProvider provider2 = control.createMock(PolicyProvider.class);
+        providers.add(provider2);
+        Policy p2 = control.createMock(Policy.class);
+        Policy p3 = control.createMock(Policy.class);
+        EasyMock.expect(provider1.getEffectivePolicy(bfi)).andReturn(p1);
+        EasyMock.expect(provider2.getEffectivePolicy(bfi)).andReturn(p2);
+        EasyMock.expect(p1.merge(p2)).andReturn(p3);
+        
+        control.replay();
+        assertSame(p3, engine.getAggregatedFaultPolicy(bfi));
+        control.verify();      
+    }
+    
+    public void testGetClientOutInterceptors() throws NoSuchMethodException { 
+        doTestGetClientInterceptors(true, false);                
+    }
+    
+    public void testGetClientInInterceptors() throws NoSuchMethodException { 
+        doTestGetClientInterceptors(false, false);       
+    }
+    
+    public void testGetClientInFaultInterceptors() throws NoSuchMethodException { 
+        doTestGetClientInterceptors(false, true);       
+    }
+    
+    public void doTestGetClientInterceptors(boolean out, boolean fault) throws NoSuchMethodException { 
+        Method m = PolicyEngine.class.getDeclaredMethod("getClientPolicyInfo", 
+            new Class[] {BindingOperationInfo.class, EndpointInfo.class, Conduit.class});
+        engine = control.createMock(PolicyEngine.class, new Method[] {m});
+        BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
+        EndpointInfo ei = control.createMock(EndpointInfo.class);
+        Conduit conduit = control.createMock(Conduit.class);
+        
+        ClientPolicyInfo cpi = control.createMock(ClientPolicyInfo.class);
+        EasyMock.expect(engine.getClientPolicyInfo(boi, ei, conduit)).andReturn(cpi);
+        Interceptor i = control.createMock(Interceptor.class);
+        List<Interceptor> li = Collections.singletonList(i);
+        if (out) {
+            EasyMock.expect(cpi.getOutInterceptors()).andReturn(li);
+        } else {
+            if (fault) {
+                EasyMock.expect(cpi.getInFaultInterceptors()).andReturn(li);
+            } else {
+                EasyMock.expect(cpi.getInInterceptors()).andReturn(li);
+            }
+        }
+        
+        control.replay();
+        List<Interceptor> clientInterceptors = out ? engine.getClientOutInterceptors(boi, ei, conduit)
+            : (fault ? engine.getClientInFaultInterceptors(boi, ei, conduit) 
+                : engine.getClientInInterceptors(boi, ei, conduit));        
+        assertSame(li, clientInterceptors);        
+        control.verify();                
+    }
+    
+    public void xtestSupportsAlternative() {
+        doTestSupportsAlternative(true);
+    }    
+    
+    void doTestSupportsAlternative(boolean supported) {
+        /*
+        PolicyInterceptorProviderRegistry pipr = control.createMock(PolicyInterceptorProviderRegistry.class);
+        EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(pipr);
+        Assertion a = control.createMock(Assertion.class);
+        List<Assertion> alternative = Collections.singletonList(a);
+        EasyMock.expect(a.isOptional()).andReturn(false);
+        QName qn = new QName("http://x.y.z", "a");
+        EasyMock.expect(a.getName()).andReturn(qn);
+        EasyMock.expect(pipr.get(qn)).andReturn(null);
+        AssertingConduit ac = control.createMock(AssertingConduit.class);
+        EasyMock.expect(ac.asserts(a)).andReturn(supported);
+                
+        control.replay();
+        assertEquals(supported, engine.supportsAlternative(alternative, ac));
+        control.verify();
+        */
+    }
+    
+    
+}

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

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

Added: 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=auto&rev=504621
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java Wed Feb  7 09:11:23 2007
@@ -0,0 +1,181 @@
+/**
+ * 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.Collections;
+
+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.interceptor.InterceptorChain;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.Conduit;
+import org.easymock.classextension.EasyMock;
+import org.easymock.classextension.IMocksControl;
+
+/**
+ * 
+ */
+public class PolicyInterceptorsTest extends TestCase {
+    
+    private IMocksControl control;
+    private Message message;
+    private BindingOperationInfo boi;
+    private EndpointInfo ei;
+    private Bus bus;
+    private PolicyEngine pe;
+    private Conduit conduit;
+    
+    
+    public void setUp() {
+        control = EasyMock.createNiceControl();
+        bus = control.createMock(Bus.class);       
+    } 
+    
+    public void testClientPolicyOutInterceptor() {
+        ClientPolicyOutInterceptor interceptor = new ClientPolicyOutInterceptor();
+        interceptor.setBus(bus);
+       
+        doTestBasics(interceptor);
+        
+        control.reset();
+        setupMessage(true, true, true, true);
+        Interceptor i = control.createMock(Interceptor.class);
+        EasyMock.expect(pe.getClientOutInterceptors(boi, ei, conduit))
+            .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();
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();        
+    }
+    
+    public void testClientPolicyInInterceptor() {
+        ClientPolicyInInterceptor interceptor = new ClientPolicyInInterceptor();
+        interceptor.setBus(bus);
+        
+        doTestBasics(interceptor);
+        
+        control.reset();
+        setupMessage(true, true, true, true);
+        Interceptor i = control.createMock(Interceptor.class);
+        EasyMock.expect(pe.getClientInInterceptors(boi, ei, conduit))
+            .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();
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();        
+    }
+    
+    public void testClientPolicyInFaultInterceptor() {
+        ClientPolicyInFaultInterceptor interceptor = new ClientPolicyInFaultInterceptor();
+        interceptor.setBus(bus);
+        
+        doTestBasics(interceptor);
+        
+        control.reset();
+        setupMessage(true, true, true, true);
+        Interceptor i = control.createMock(Interceptor.class);
+        EasyMock.expect(pe.getClientInFaultInterceptors(boi, ei, conduit))
+            .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();
+        control.replay();
+        interceptor.handleMessage(message);
+        control.verify();        
+    }
+    
+    private void doTestBasics(Interceptor<Message> interceptor) {
+        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();
+    }
+    
+    void setupMessage(boolean setupRequestor, 
+                      boolean setupOperation, 
+                      boolean setupEndpoint, 
+                      boolean setupEngine) {
+        message = control.createMock(Message.class);
+        EasyMock.expect(message.get(Message.REQUESTOR_ROLE))
+            .andReturn(setupRequestor ? Boolean.TRUE : Boolean.FALSE);
+        if (!setupRequestor) {
+            return;
+        }        
+
+        if (null == boi) {
+            boi = control.createMock(BindingOperationInfo.class);
+        }
+        EasyMock.expect(message.get(BindingOperationInfo.class)).andReturn(setupOperation ? boi : null);
+        if (!setupOperation) {
+            return;
+        }
+               
+        if (null == ei) {
+            ei = control.createMock(EndpointInfo.class);
+        }
+        EasyMock.expect(message.get(EndpointInfo.class)).andReturn(setupEndpoint ? ei : null);
+        if (!setupEndpoint) {
+            return;
+        }
+        if (null == pe) {
+            pe = control.createMock(PolicyEngine.class);
+        }
+        EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(setupEngine ? pe : null);
+        if (!setupEngine) {
+            return;
+        }
+            
+        if (null == conduit) {
+            conduit = control.createMock(Conduit.class);
+        }
+        EasyMock.expect(message.getConduit()).andReturn(conduit);
+      
+    }
+}

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

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



Mime
View raw message