Author: sergeyb
Date: Tue Jul 27 16:29:03 2010
New Revision: 979765
URL: http://svn.apache.org/viewvc?rev=979765&view=rev
Log:
Merged revisions 979764 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r979764 | sergeyb | 2010-07-27 17:19:20 +0100 (Tue, 27 Jul 2010) | 1 line
CXF-2912 : Updating EndpointPolicyImpl to ignore empty policies during the
update
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
cxf/branches/2.2.x-fixes/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jul 27 16:29:03 2010
@@ -1 +1 @@
-/cxf/trunk:979457,979459
+/cxf/trunk:979457,979459,979764
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java?rev=979765&r1=979764&r2=979765&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/EndpointPolicyImpl.java
Tue Jul 27 16:29:03 2010
@@ -88,8 +88,16 @@ public class EndpointPolicyImpl implemen
public EndpointPolicy updatePolicy(Policy p) {
EndpointPolicyImpl epi = createEndpointPolicy();
- Policy np = (Policy)p.normalize(true);
- epi.setPolicy(getPolicy().merge(np));
+
+ if (!PolicyUtils.isEmptyPolicy(p)) {
+ Policy normalizedPolicy = (Policy)p.normalize(true);
+ epi.setPolicy(getPolicy().merge(normalizedPolicy));
+ } else {
+ Policy clonedPolicy = new Policy();
+
clonedPolicy.addPolicyComponents(getPolicy().getPolicyComponents());
+ epi.setPolicy(clonedPolicy);
+ }
+
epi.checkExactlyOnes();
epi.finalizeConfig();
return epi;
Modified:
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java?rev=979765&r1=979764&r2=979765&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/PolicyUtils.java
Tue Jul 27 16:29:03 2010
@@ -28,6 +28,7 @@ import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.ws.policy.builder.primitive.NestedPrimitiveAssertion;
import org.apache.neethi.Assertion;
import org.apache.neethi.Constants;
+import org.apache.neethi.Policy;
import org.apache.neethi.PolicyComponent;
import org.apache.neethi.PolicyOperator;
@@ -42,6 +43,45 @@ public final class PolicyUtils {
}
/**
+ * Checks if a given policy contains no policy components
+ * or if it has only empty ExactlyOne or All components
+ * containing no assertions
+ *
+ * @param p the policy
+ * @return true if the policy is empty
+ */
+ public static boolean isEmptyPolicy(Policy p) {
+
+ return isEmptyPolicyOperator(p);
+ }
+
+ /**
+ * Checks if a given policy operator has no policy components
+ * or if it has only empty ExactlyOne or All components
+ * containing no assertions
+ *
+ * @param p the policy operator
+ * @return true if this policy operator is empty
+ */
+ public static boolean isEmptyPolicyOperator(PolicyOperator p) {
+
+ if (p.isEmpty()) {
+ return true;
+ }
+
+ List components = p.getPolicyComponents();
+
+ for (Object component : components) {
+ if (!(component instanceof PolicyOperator)
+ || !isEmptyPolicyOperator((PolicyOperator)component)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
* Determine if a collection of assertions contains a given assertion,
using
* the equal method from the Assertion interface.
*
Modified:
cxf/branches/2.2.x-fixes/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java?rev=979765&r1=979764&r2=979765&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java
Tue Jul 27 16:29:03 2010
@@ -36,8 +36,10 @@ import org.apache.neethi.All;
import org.apache.neethi.Constants;
import org.apache.neethi.ExactlyOne;
import org.apache.neethi.Policy;
+import org.apache.neethi.PolicyOperator;
import org.easymock.classextension.EasyMock;
import org.easymock.classextension.IMocksControl;
+
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -213,6 +215,61 @@ public class EndpointPolicyImplTest exte
assertTrue("Policy was not merged",
n1.equals(aqn1) && n2.equals(aqn2) || n1.equals(aqn2) &&
n2.equals(aqn1));
}
+
+ @Test
+ public void testUpdatePolicyWithEmptyPolicy() {
+
+ doTestUpdateWithEmptyPolicy(new Policy());
+ }
+
+ @Test
+ public void testUpdatePolicyWithEmptyAll() {
+
+ Policy emptyPolicy = new Policy();
+ emptyPolicy.addPolicyComponent(new All());
+ emptyPolicy.addPolicyComponent(new All());
+ doTestUpdateWithEmptyPolicy(emptyPolicy);
+ }
+
+ @Test
+ public void testUpdatePolicyWithEmptyExactlyOneAndAll() {
+
+ Policy emptyPolicy = new Policy();
+ PolicyOperator exactlyOne = new ExactlyOne();
+ exactlyOne.addPolicyComponent(new All());
+ exactlyOne.addPolicyComponent(new All());
+ emptyPolicy.addPolicyComponent(exactlyOne);
+ emptyPolicy.addPolicyComponent(new All());
+ emptyPolicy.addPolicyComponent(new All());
+ doTestUpdateWithEmptyPolicy(emptyPolicy);
+ }
+
+ private void doTestUpdateWithEmptyPolicy(Policy emptyPolicy) {
+ Policy p1 = new Policy();
+ QName aqn1 = new QName("http://x.y.z", "a");
+ p1.addAssertion(mockAssertion(aqn1, 5, true));
+
+ EndpointPolicyImpl epi = new TestEndpointPolicy();
+ control.replay();
+
+ epi.setPolicy((Policy)p1.normalize(true));
+
+ Policy ep = epi.updatePolicy(emptyPolicy).getPolicy();
+
+ List<ExactlyOne> pops =
+ CastUtils.cast(ep.getPolicyComponents(), ExactlyOne.class);
+ assertEquals("New policy must have 1 top level policy operator", 1,
pops.size());
+ List<All> alts =
+ CastUtils.cast(pops.get(0).getPolicyComponents(), All.class);
+ assertEquals("1 alternatives should be available", 1, alts.size());
+
+ List<PolicyAssertion> assertions1 =
+ CastUtils.cast(alts.get(0).getAssertions(), PolicyAssertion.class);
+ assertEquals("1 assertion should be available", 1, assertions1.size());
+
+ QName n1 = assertions1.get(0).getName();
+ assertTrue("Policy was not merged", n1.equals(aqn1));
+ }
private PolicyAssertion mockAssertion(QName name, int howMany, boolean
normalize) {
PolicyAssertion a = control.createMock(PolicyAssertion.class);