cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andreasm...@apache.org
Subject svn commit: r535175 - in /incubator/cxf/trunk: 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/ rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/s...
Date Fri, 04 May 2007 11:15:54 GMT
Author: andreasmyth
Date: Fri May  4 04:15:53 2007
New Revision: 535175

URL: http://svn.apache.org/viewvc?view=rev&rev=535175
Log:
Added AlternativeSelector API and implementations to select alternative with least/most assertions among all supported alternatives, or simply the first supported alternative. 
New default behaviour is to use the MinimalAlternativeSelector to make alternative selection predictable in the simple case of one optional assertion. 
Fixed addressing interceptor to let pass through messages without addressing properties.

Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java   (with props)
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingOptionalPolicyTest.java   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml   (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml   (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
    incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
    incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java
    incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/TestAssertion.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java (added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/AlternativeSelector.java Fri May  4 04:15:53 2007
@@ -0,0 +1,34 @@
+/**
+ * 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.Collection;
+
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+/**
+ * 
+ */
+public interface AlternativeSelector {
+ 
+    Collection<Assertion> selectAlternative(Policy policy, PolicyEngine engine, Assertor assertor);
+    
+}

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

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

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/policy/PolicyEngine.java Fri May  4 04:15:53 2007
@@ -19,11 +19,14 @@
 
 package org.apache.cxf.ws.policy;
 
+import java.util.Collection;
+
 import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
+import org.apache.neethi.Assertion;
 import org.apache.neethi.PolicyRegistry;
 
 /**
@@ -34,6 +37,12 @@
     boolean isEnabled();
     
     void setEnabled(boolean e);
+    
+    AlternativeSelector getAlternativeSelector();
+    
+    void setAlternativeSelector(AlternativeSelector selector);
+    
+    boolean supportsAlternative(Collection<Assertion> alterative, Assertor assertor);
     
     // available throughout the outbound path
     

Modified: incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java (original)
+++ incubator/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java Fri May  4 04:15:53 2007
@@ -247,6 +247,9 @@
         } else if (!ContextUtils.isRequestor(message)) {
             // responder validates incoming MAPs
             AddressingPropertiesImpl maps = getMAPs(message, false, false);
+            if (null == maps) {
+                return false;
+            }
             boolean isOneway = message.getExchange().isOneWay();
             continueProcessing = validateIncomingMAPs(maps, message);
             if (continueProcessing) {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EffectivePolicyImpl.java Fri May  4 04:15:53 2007
@@ -21,7 +21,6 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
 import java.util.logging.Level;
@@ -32,7 +31,6 @@
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
-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;
@@ -120,17 +118,14 @@
     }
 
     void chooseAlternative(PolicyEngineImpl engine, Assertor assertor) {
-        Iterator alternatives = policy.getAlternatives();
-        while (alternatives.hasNext()) {
-            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
-            if (engine.supportsAlternative(alternative, assertor)) {
-                setChosenAlternative(alternative);
-                return;
-            }
-        }
-        PolicyUtils.logPolicy(LOG, Level.FINE, "No alternative supported.", getPolicy());
-        throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE));
-
+        Collection<Assertion> alternative = engine.getAlternativeSelector()
+            .selectAlternative(policy, engine, assertor);
+        if (null == alternative) {
+            PolicyUtils.logPolicy(LOG, Level.FINE, "No alternative supported.", getPolicy());
+            throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE));
+        } else {
+            setChosenAlternative(alternative);
+        }   
     }
 
     void initialiseInterceptors(PolicyEngineImpl engine) {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java Fri May  4 04:15:53 2007
@@ -22,7 +22,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
 import java.util.Set;
@@ -31,7 +30,6 @@
 
 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.Interceptor;
 import org.apache.cxf.service.model.BindingFaultInfo;
 import org.apache.cxf.service.model.BindingOperationInfo;
@@ -92,15 +90,13 @@
     }
 
     void chooseAlternative(PolicyEngineImpl engine, Assertor assertor) {
-        Iterator alternatives = policy.getAlternatives();
-        while (alternatives.hasNext()) {
-            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
-            if (engine.supportsAlternative(alternative, assertor)) {
-                setChosenAlternative(alternative);
-                return;
-            }
+        Collection<Assertion> alternative = engine.getAlternativeSelector()
+            .selectAlternative(policy, engine, assertor);
+        if (null == alternative) {
+            throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE));
+        } else {
+            setChosenAlternative(alternative);
         }
-        throw new PolicyException(new Message("NO_ALTERNATIVE_EXC", BUNDLE));
     }
     
     void initialiseVocabulary(EndpointInfo ei, boolean requestor, PolicyEngineImpl engine) {

Modified: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyEngineImpl.java Fri May  4 04:15:53 2007
@@ -40,6 +40,7 @@
 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.selector.MinimalAlternativeSelector;
 import org.apache.neethi.Assertion;
 import org.apache.neethi.Constants;
 import org.apache.neethi.Policy;
@@ -58,6 +59,7 @@
     private Collection<PolicyProvider> policyProviders;
     private boolean enabled;
     private boolean addedBusInterceptors;
+    private AlternativeSelector alternativeSelector;
     
     private Map<BindingOperation, EffectivePolicy> clientRequestInfo;
     
@@ -115,6 +117,14 @@
         }
     }
     
+    public AlternativeSelector getAlternativeSelector() {        
+        return alternativeSelector;
+    }
+    
+    public void setAlternativeSelector(AlternativeSelector as) {
+        alternativeSelector = as;
+    }
+    
     // BusExtension interface
     
     public Class<?> getRegistrationType() {
@@ -291,13 +301,18 @@
             = new ConcurrentHashMap<BindingOperation, EffectivePolicy>();
     
         serverFaultInfo 
-            = new ConcurrentHashMap<BindingFault, EffectivePolicy>();
+            = new ConcurrentHashMap<BindingFault, EffectivePolicy>();        
     }
     
     
     
     @PostConstruct
     public void addBusInterceptors() {
+        
+        if (null == alternativeSelector) {
+            alternativeSelector = new MinimalAlternativeSelector();
+        }
+        
         if (null == bus || !enabled) {
             return;
         }
@@ -480,7 +495,7 @@
      * @param Assertor the assertor
      * @return true iff the alternative can be supported
      */
-    boolean supportsAlternative(List<Assertion> alternative, Assertor assertor) {
+    public boolean supportsAlternative(Collection<Assertion> alternative, Assertor assertor) {
         PolicyInterceptorProviderRegistry pipr = bus.getExtension(PolicyInterceptorProviderRegistry.class);
         for (Assertion a : alternative) {
             if (!(a.isOptional() 

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelector.java Fri May  4 04:15:53 2007
@@ -0,0 +1,48 @@
+/**
+ * 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.selector;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.ws.policy.AlternativeSelector;
+import org.apache.cxf.ws.policy.Assertor;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+/**
+ * 
+ */
+public class FirstAlternativeSelector implements AlternativeSelector {
+    
+    public Collection<Assertion> selectAlternative(Policy policy, PolicyEngine engine, Assertor assertor) {
+        Iterator alternatives = policy.getAlternatives();
+        while (alternatives.hasNext()) {
+            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
+            if (engine.supportsAlternative(alternative, assertor)) {
+                return alternative;
+            }
+        }        
+        return null;
+    }
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MaximalAlternativeSelector.java Fri May  4 04:15:53 2007
@@ -0,0 +1,50 @@
+/**
+ * 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.selector;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.ws.policy.AlternativeSelector;
+import org.apache.cxf.ws.policy.Assertor;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+/**
+ * 
+ */
+public class MaximalAlternativeSelector implements AlternativeSelector {
+
+    public Collection<Assertion> selectAlternative(Policy policy, PolicyEngine engine, Assertor assertor) {
+        Collection<Assertion> choice = null;
+        Iterator alternatives = policy.getAlternatives();
+        while (alternatives.hasNext()) {
+            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
+            if (engine.supportsAlternative(alternative, assertor) 
+                && (null == choice || alternative.size() > choice.size())) {
+                choice = alternative;
+            }
+        }
+        return choice;
+    }
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/selector/MinimalAlternativeSelector.java Fri May  4 04:15:53 2007
@@ -0,0 +1,50 @@
+/**
+ * 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.selector;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.ws.policy.AlternativeSelector;
+import org.apache.cxf.ws.policy.Assertor;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.neethi.Assertion;
+import org.apache.neethi.Policy;
+
+/**
+ * 
+ */
+public class MinimalAlternativeSelector implements AlternativeSelector {
+
+    public Collection<Assertion> selectAlternative(Policy policy, PolicyEngine engine, Assertor assertor) {
+        Collection<Assertion> choice = null;
+        Iterator alternatives = policy.getAlternatives();
+        while (alternatives.hasNext()) {
+            List<Assertion> alternative = CastUtils.cast((List)alternatives.next(), Assertion.class);
+            if (engine.supportsAlternative(alternative, assertor) 
+                && (null == choice || alternative.size() < choice.size())) {
+                choice = alternative;
+            }
+        }
+        return choice;
+    }
+}

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

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

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java Fri May  4 04:15:53 2007
@@ -28,7 +28,6 @@
 import javax.xml.namespace.QName;
 
 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;
@@ -36,9 +35,7 @@
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
-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;
@@ -230,26 +227,18 @@
     
     @Test
     public void testChooseAlternative() {
-        EffectivePolicyImpl cpi = new EffectivePolicyImpl();
-        cpi.setPolicy(new Policy());
-        
+        EffectivePolicyImpl epi = new EffectivePolicyImpl();        
+        Policy policy = new Policy();
+        epi.setPolicy(policy);        
         PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.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);
+        AlternativeSelector selector = control.createMock(AlternativeSelector.class);
+        EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
+        EasyMock.expect(selector.selectAlternative(policy, engine, assertor)).andReturn(null);
         
-        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(false);
         control.replay();
         try {
-            cpi.chooseAlternative(engine, assertor);  
+            epi.chooseAlternative(engine, assertor);  
             fail("Expected PolicyException not thrown.");
         } catch (PolicyException ex) {
             // expected
@@ -257,47 +246,29 @@
         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);
+        EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
+        Collection<Assertion> alternative = new ArrayList<Assertion>();
+        EasyMock.expect(selector.selectAlternative(policy, engine, assertor)).andReturn(alternative);
         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));
+        epi.chooseAlternative(engine, assertor);
+        Collection<Assertion> choice = epi.getChosenAlternative();
+        assertSame(choice, alternative);   
         control.verify();
     }
     
     @Test
     public void testInitialiseOutInterceptors() {
-        EffectivePolicyImpl cpi = new EffectivePolicyImpl();        
+        EffectivePolicyImpl epi = new EffectivePolicyImpl();        
         List<Assertion> alternative = new ArrayList<Assertion>();
-        cpi.setChosenAlternative(alternative);
+        epi.setChosenAlternative(alternative);
         
         PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class);
         PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class);
         setupPolicyInterceptorProviderRegistry(engine, reg);
         
         control.replay();
-        cpi.initialiseInterceptors(engine);
-        assertEquals(0, cpi.getInterceptors().size());
+        epi.initialiseInterceptors(engine);
+        assertEquals(0, epi.getInterceptors().size());
         control.verify();
         
         control.reset();
@@ -306,8 +277,8 @@
         alternative.add(a);
         EasyMock.expect(a.isOptional()).andReturn(true);
         control.replay();
-        cpi.initialiseInterceptors(engine);
-        assertEquals(0, cpi.getInterceptors().size());
+        epi.initialiseInterceptors(engine);
+        assertEquals(0, epi.getInterceptors().size());
         control.verify();
         
         control.reset();
@@ -317,8 +288,8 @@
         EasyMock.expect(a.getName()).andReturn(qn);
         EasyMock.expect(reg.get(qn)).andReturn(null);
         control.replay();
-        cpi.initialiseInterceptors(engine);
-        assertEquals(0, cpi.getInterceptors().size());
+        epi.initialiseInterceptors(engine);
+        assertEquals(0, epi.getInterceptors().size());
         control.verify();
         
         control.reset();
@@ -330,9 +301,9 @@
         Interceptor pi = control.createMock(Interceptor.class);
         EasyMock.expect(pp.getOutInterceptors()).andReturn(Collections.singletonList(pi));
         control.replay();
-        cpi.initialiseInterceptors(engine);
-        assertEquals(1, cpi.getInterceptors().size());
-        assertSame(pi, cpi.getInterceptors().get(0));
+        epi.initialiseInterceptors(engine);
+        assertEquals(1, epi.getInterceptors().size());
+        assertSame(pi, epi.getInterceptors().get(0));
         control.verify();     
     }
     

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java Fri May  4 04:15:53 2007
@@ -29,7 +29,6 @@
 import javax.xml.namespace.QName;
 
 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;
@@ -37,9 +36,7 @@
 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;
@@ -142,26 +139,18 @@
        
     @Test
     public void testChooseAlternative() {
-        EndpointPolicyImpl cpi = new EndpointPolicyImpl();
-        cpi.setPolicy(new Policy());
-        
+        EndpointPolicyImpl epi = new EndpointPolicyImpl();        
+        Policy policy = new Policy();
+        epi.setPolicy(policy);        
         PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.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);
+        AlternativeSelector selector = control.createMock(AlternativeSelector.class);
+        EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
+        EasyMock.expect(selector.selectAlternative(policy, engine, assertor)).andReturn(null);
         
-        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(false);
         control.replay();
         try {
-            cpi.chooseAlternative(engine, assertor);  
+            epi.chooseAlternative(engine, assertor);  
             fail("Expected PolicyException not thrown.");
         } catch (PolicyException ex) {
             // expected
@@ -169,31 +158,13 @@
         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);
+        EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector);
+        Collection<Assertion> alternative = new ArrayList<Assertion>();
+        EasyMock.expect(selector.selectAlternative(policy, engine, assertor)).andReturn(alternative);
         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));
+        epi.chooseAlternative(engine, assertor);
+        Collection<Assertion> choice = epi.getChosenAlternative();
+        assertSame(choice, alternative);   
         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=535175&r1=535174&r2=535175
==============================================================================
--- 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 Fri May  4 04:15:53 2007
@@ -73,6 +73,7 @@
         assertNotNull(engine.getRegistry());
         assertNull(engine.getBus());
         assertNull(engine.getPolicyProviders()); 
+        assertNull(engine.getAlternativeSelector());
         assertTrue(!engine.isEnabled());
         Bus bus = new CXFBusImpl();
         
@@ -82,10 +83,13 @@
         PolicyRegistry reg = control.createMock(PolicyRegistry.class);
         engine.setRegistry(reg);
         engine.setEnabled(true);
+        AlternativeSelector selector = control.createMock(AlternativeSelector.class);
+        engine.setAlternativeSelector(selector);
         assertSame(bus, engine.getBus());
         assertSame(providers, engine.getPolicyProviders());
         assertSame(reg, engine.getRegistry());
-        assertTrue(engine.isEnabled());        
+        assertTrue(engine.isEnabled()); 
+        assertSame(selector, engine.getAlternativeSelector());
         assertNotNull(engine.createOutPolicyInfo());
         assertNotNull(engine.createEndpointPolicyInfo());
         
@@ -384,6 +388,7 @@
         if (enabled) {
             control.verify();
         }
+        assertNotNull(engine.getAlternativeSelector());
     }
     
     @Test

Modified: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/TestAssertion.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/TestAssertion.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/TestAssertion.java (original)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/TestAssertion.java Fri May  4 04:15:53 2007
@@ -35,11 +35,11 @@
     private QName name;
     private boolean optional;
     
-    TestAssertion() {
+    public TestAssertion() {
         this(null);
     }
     
-    TestAssertion(QName n) {
+    public TestAssertion(QName n) {
         name = n;
     }
     

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java Fri May  4 04:15:53 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.selector;
+
+import java.util.Collection;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.ws.policy.AlternativeSelector;
+import org.apache.cxf.ws.policy.Assertor;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.cxf.ws.policy.TestAssertion;
+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;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * 
+ */
+public class FirstAlternativeSelectorTest extends Assert {
+
+    private IMocksControl control;
+    
+    @Before
+    public void setUp() {
+        control = EasyMock.createNiceControl(); 
+    } 
+    @Test
+    public void testChooseAlternative() {
+        AlternativeSelector selector = new FirstAlternativeSelector();
+        
+        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);
+        Collection<Assertion> firstAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
+        policy.addPolicyComponent(ea);
+        
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(false);
+        control.replay();
+        
+        assertNull(selector.selectAlternative(policy, engine, assertor));  
+        control.verify();
+        
+        control.reset();        
+        EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor)).andReturn(true);
+        control.replay();         
+        Collection<Assertion> chosen = selector.selectAlternative(policy, engine, assertor); 
+        assertSame(1, chosen.size());
+        assertSame(chosen.size(), firstAlternative.size());
+        assertSame(chosen.iterator().next(), firstAlternative.iterator().next());
+        control.verify();
+        
+        control.reset();
+        All other = new All();
+        other.addAssertion(a1);
+        ea.addPolicyComponent(other);
+        Collection<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();        
+      
+        chosen = selector.selectAlternative(policy, engine, assertor); 
+        assertSame(1, chosen.size());
+        assertSame(chosen.size(), secondAlternative.size());
+        assertSame(chosen.iterator().next(), secondAlternative.iterator().next());
+        control.verify();
+    }
+}

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

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

Added: incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java (added)
+++ incubator/cxf/trunk/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java Fri May  4 04:15:53 2007
@@ -0,0 +1,106 @@
+/**
+ * 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.selector;
+
+import java.util.Collection;
+
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.ws.policy.AlternativeSelector;
+import org.apache.cxf.ws.policy.Assertor;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.cxf.ws.policy.TestAssertion;
+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;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * 
+ */
+public class MinimalMaximalAlternativeSelectorTest extends Assert {
+
+    private IMocksControl control;
+    
+    @Before
+    public void setUp() {
+        control = EasyMock.createNiceControl(); 
+    } 
+    
+    @Test
+    public void testChooseMinAlternative() {
+        AlternativeSelector selector = new MinimalAlternativeSelector();
+        
+        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);
+        Collection<Assertion> maxAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
+        all = new All();
+        ea.addPolicyComponent(all);
+        Collection<Assertion> minAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
+        policy.addPolicyComponent(ea);  
+        EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor)).andReturn(true);
+        EasyMock.expect(engine.supportsAlternative(minAlternative, assertor)).andReturn(true);
+        
+        control.replay();        
+        Collection<Assertion> choice = selector.selectAlternative(policy, engine, assertor); 
+        assertEquals(0, choice.size());
+        control.verify();
+    }
+    
+    @Test
+    public void testChooseMaxAlternative() {
+        AlternativeSelector selector = new MaximalAlternativeSelector();
+        
+        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);
+        Collection<Assertion> maxAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
+        all = new All();
+        ea.addPolicyComponent(all);
+        Collection<Assertion> minAlternative = CastUtils.cast(all.getPolicyComponents(), Assertion.class);
+        policy.addPolicyComponent(ea);  
+        EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor)).andReturn(true);
+        EasyMock.expect(engine.supportsAlternative(minAlternative, assertor)).andReturn(true);
+        
+        control.replay();        
+        Collection<Assertion> choice = selector.selectAlternative(policy, engine, assertor); 
+        assertEquals(1, choice.size());
+        assertSame(a1, choice.iterator().next());
+        control.verify();
+    }
+}

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

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

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/mtom/MtomPolicyTest.java Fri May  4 04:15:53 2007
@@ -41,7 +41,9 @@
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.ConduitInitiator;
 import org.apache.cxf.transport.ConduitInitiatorManager;
+import org.apache.cxf.ws.policy.PolicyEngine;
 import org.apache.cxf.ws.policy.WSPolicyFeature;
+import org.apache.cxf.ws.policy.selector.FirstAlternativeSelector;
 import org.junit.Test;
 
 public class MtomPolicyTest extends AbstractCXFTest {
@@ -70,6 +72,8 @@
     }
     
     public void setupServer(boolean mtomRequired) throws Exception {
+        getBus().getExtension(PolicyEngine.class).setAlternativeSelector(
+            new FirstAlternativeSelector());
         JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
         sf.setServiceBean(new EchoService());
         sf.setBus(getBus());
@@ -84,7 +88,7 @@
             policy.getPolicyElements().add(DOMUtils.readXml(
                 getClass().getResourceAsStream("mtom-policy-optional.xsd"))
                            .getDocumentElement());
-        }
+        }        
         
         sf.getFeatures().add(policy);
         

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingOptionalPolicyTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingOptionalPolicyTest.java?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingOptionalPolicyTest.java (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/AddressingOptionalPolicyTest.java Fri May  4 04:15:53 2007
@@ -0,0 +1,184 @@
+/**
+ * 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.systest.ws.policy;
+
+import java.util.logging.Logger;
+
+import javax.xml.ws.Endpoint;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.greeter_control.BasicGreeterService;
+import org.apache.cxf.greeter_control.Greeter;
+import org.apache.cxf.greeter_control.PingMeFault;
+import org.apache.cxf.interceptor.LoggingInInterceptor;
+import org.apache.cxf.interceptor.LoggingOutInterceptor;
+import org.apache.cxf.systest.ws.util.InMessageRecorder;
+import org.apache.cxf.systest.ws.util.MessageFlow;
+import org.apache.cxf.systest.ws.util.OutMessageRecorder;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.cxf.ws.policy.PolicyEngine;
+import org.apache.cxf.ws.policy.selector.MinimalAlternativeSelector;
+import org.apache.cxf.ws.rm.RMUtils;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+
+/**
+ * Tests the use of the WS-Policy Framework to automatically engage WS-Addressing and
+ * WS-RM in response to Policies defined for the endpoint via an external policy attachment.
+ */
+public class AddressingOptionalPolicyTest extends AbstractBusClientServerTestBase {
+
+    private static final Logger LOG = Logger.getLogger(AddressingOptionalPolicyTest.class.getName());
+
+    public static class Server extends AbstractBusTestServerBase {
+    
+        protected void run()  {            
+            SpringBusFactory bf = new SpringBusFactory();
+            Bus bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-optional.xml");
+            BusFactory.setDefaultBus(bus);
+            LoggingInInterceptor in = new LoggingInInterceptor();
+            bus.getInInterceptors().add(in);
+            bus.getInFaultInterceptors().add(in);
+            LoggingOutInterceptor out = new LoggingOutInterceptor();
+            bus.getOutInterceptors().add(out);
+            bus.getOutFaultInterceptors().add(out);
+            
+            GreeterImpl implementor = new GreeterImpl();
+            String address = "http://localhost:9020/SoapContext/GreeterPort";
+            Endpoint.publish(address, implementor);
+            LOG.info("Published greeter endpoint.");            
+        }
+        
+
+        public static void main(String[] args) {
+            try { 
+                Server s = new Server(); 
+                s.start();
+            } catch (Exception ex) {
+                ex.printStackTrace();
+                System.exit(-1);
+            } finally { 
+                System.out.println("done!");
+            }
+        }
+    }    
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(Server.class));
+    }
+    
+    
+    @Test
+    public void testUsingAddressing() throws Exception {
+        SpringBusFactory bf = new SpringBusFactory();
+        bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-optional.xml");
+        BusFactory.setDefaultBus(bus);
+        InMessageRecorder in = new InMessageRecorder();
+        bus.getInInterceptors().add(in);
+        OutMessageRecorder out = new OutMessageRecorder();
+        bus.getOutInterceptors().add(out);
+        
+        BasicGreeterService gs = new BasicGreeterService();
+        final Greeter greeter = gs.getGreeterPort();
+        LOG.fine("Created greeter client.");
+
+        // oneway
+
+        greeter.greetMeOneWay("CXF");
+
+        // two-way
+
+        assertEquals("CXF", greeter.greetMe("cxf")); 
+     
+        // exception
+
+        try {
+            greeter.pingMe();
+        } catch (PingMeFault ex) {
+            fail("First invocation should have succeeded.");
+        } 
+       
+        try {
+            greeter.pingMe();
+            fail("Expected PingMeFault not thrown.");
+        } catch (PingMeFault ex) {
+            assertEquals(2, (int)ex.getFaultInfo().getMajor());
+            assertEquals(1, (int)ex.getFaultInfo().getMinor());
+        } 
+        
+        MessageFlow mf = new MessageFlow(out.getOutboundMessages(), in.getInboundMessages());
+        for (int i = 0; i < 3; i++) {
+            mf.verifyHeader(RMUtils.getAddressingConstants().getMessageIDQName(), true, i);
+            mf.verifyHeader(RMUtils.getAddressingConstants().getMessageIDQName(), false, i);
+        }
+    }
+    
+    @Test
+    public void testNotUsingAddressing() throws Exception {
+        SpringBusFactory bf = new SpringBusFactory();
+        bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-optional.xml");
+        BusFactory.setDefaultBus(bus);
+        InMessageRecorder in = new InMessageRecorder();
+        bus.getInInterceptors().add(in);
+        OutMessageRecorder out = new OutMessageRecorder();
+        bus.getOutInterceptors().add(out);
+        
+        bus.getExtension(PolicyEngine.class).setAlternativeSelector(new MinimalAlternativeSelector());
+                
+        BasicGreeterService gs = new BasicGreeterService();
+        final Greeter greeter = gs.getGreeterPort();
+        LOG.fine("Created greeter client.");
+
+        // oneway
+
+        greeter.greetMeOneWay("CXF");
+
+        // two-way
+
+        assertEquals("CXF", greeter.greetMe("cxf")); 
+     
+        // exception
+
+        try {
+            greeter.pingMe();
+        } catch (PingMeFault ex) {
+            fail("First invocation should have succeeded.");
+        } 
+       
+        try {
+            greeter.pingMe();
+            fail("Expected PingMeFault not thrown.");
+        } catch (PingMeFault ex) {
+            assertEquals(2, (int)ex.getFaultInfo().getMajor());
+            assertEquals(1, (int)ex.getFaultInfo().getMinor());
+        } 
+        
+        MessageFlow mf = new MessageFlow(out.getOutboundMessages(), in.getInboundMessages());
+        for (int i = 0; i < 3; i++) {
+            mf.verifyNoHeader(RMUtils.getAddressingConstants().getMessageIDQName(), true, i);
+            mf.verifyNoHeader(RMUtils.getAddressingConstants().getMessageIDQName(), false, i);
+        }
+    }
+}

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

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

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml Fri May  4 04:15:53 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  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.
+-->
+<attachments xmlns:wsp="http://www.w3.org/2006/07/ws-policy" xmlns:wsa="http://www.w3.org/2005/08/addressing">
+    <wsp:PolicyAttachment>
+        <wsp:AppliesTo>
+            <wsa:EndpointReference>
+                <wsa:Address>http://localhost:9020/SoapContext/GreeterPort</wsa:Address>
+            </wsa:EndpointReference>
+        </wsp:AppliesTo>
+        <wsp:Policy>
+            <wsam:Addressing xmlns:wsam="http://www.w3.org/2007/02/addressing/metadata" wsp:Optional="true">
+                <wsp:Policy/>
+            </wsam:Addressing>
+        </wsp:Policy>
+    </wsp:PolicyAttachment>    
+</attachments>
+

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional-external.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml?view=auto&rev=535175
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml (added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml Fri May  4 04:15:53 2007
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:http="http://cxf.apache.org/transports/http/configuration"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schema/transports/http.xsd
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+    <http:conduit id="{http://cxf.apache.org/greeter_control}GreeterPort.http-conduit">
+      <http:client DecoupledEndpoint="http://localhost:9999/decoupled_endpoint"/>
+    </http:conduit>
+
+    <bean id="org.apache.cxf.ws.policy.PolicyEngine" class="org.apache.cxf.ws.policy.spring.InitializingPolicyEngine">
+        <property name="bus" ref="cxf"/>
+        <property name="enabled" value="true"/>
+        <property name="alternativeSelector">
+            <bean class="org.apache.cxf.ws.policy.selector.MaximalAlternativeSelector"/>
+        </property>
+    </bean>
+
+    <bean class="org.apache.cxf.ws.policy.attachment.external.ExternalAttachmentProvider">
+        <constructor-arg ref="cxf"/>
+        <property name="location" value="org/apache/cxf/systest/ws/policy/addr-optional-external.xml"/>
+    </bean>
+
+</beans>
\ No newline at end of file

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/policy/addr-optional.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java?view=diff&rev=535175&r1=535174&r2=535175
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java Fri May  4 04:15:53 2007
@@ -315,6 +315,20 @@
         Document d = outbound ? outboundMessages.get(index) : inboundMessages.get(index);
         assert null != getRMHeaderElement(d, RMConstants.getSequenceFaultName());
     }
+    
+    public void verifyHeader(QName name, boolean outbound, int index) throws Exception {
+        Document d = outbound ? outboundMessages.get(index) : inboundMessages.get(index);
+        assertNotNull((outbound ? "Outbound" : "Inbound")
+            + " message " + index + " does not have " + name + "header.",
+            getHeaderElement(d, name.getNamespaceURI(), name.getLocalPart()));
+    }
+    
+    public void verifyNoHeader(QName name, boolean outbound, int index) throws Exception {
+        Document d = outbound ? outboundMessages.get(index) : inboundMessages.get(index);
+        assertNull((outbound ? "Outbound" : "Inbound")
+            + " message " + index + " has " + name + "header.",
+            getHeaderElement(d, name.getNamespaceURI(), name.getLocalPart()));
+    }
    
     protected String getAction(Document document) throws Exception {
         Element e = getHeaderElement(document, RMConstants.getAddressingNamespace(), "Action");



Mime
View raw message