Author: sanka
Date: Mon Feb 5 01:11:00 2007
New Revision: 503598
URL: http://svn.apache.org/viewvc?view=rev&rev=503598
Log:
Removed the new policy code from the brach.
Applied the set of testcases in WSCOMMONS-29.
Added:
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/util/PolicyComparator.java
webservices/commons/branches/modules/neethi/1_1/src/test/test-resources/base/Policy_Vocabulary.xml
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy2.java
Removed:
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/neethi/
webservices/commons/branches/modules/neethi/1_1/src/test/java/org/apache/ws/policy/util/PolicyComparator.java
webservices/commons/branches/modules/neethi/1_1/src/test/test3/
Modified:
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/Policy.java
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Driver.java
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_EffectivePolicy.java
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy.java
Modified:
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/Policy.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/Policy.java?view=diff&rev=503598&r1=503597&r2=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/Policy.java
(original)
+++
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/Policy.java
Mon Feb 5 01:11:00 2007
@@ -25,6 +25,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.ws.policy.util.PolicyComparator;
import org.apache.ws.policy.util.PolicyRegistry;
/**
@@ -457,7 +458,7 @@
return result;
}
-
+
private class PolicyIterator implements java.util.Iterator {
private ExactlyOne exactlyOne = null;
Added:
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/util/PolicyComparator.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/util/PolicyComparator.java?view=auto&rev=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/util/PolicyComparator.java
(added)
+++
webservices/commons/branches/modules/neethi/1_1/src/main/java/org/apache/ws/policy/util/PolicyComparator.java
Mon Feb 5 01:11:00 2007
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.policy.util;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.ws.policy.All;
+import org.apache.ws.policy.Assertion;
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PolicyReference;
+import org.apache.ws.policy.PrimitiveAssertion;
+import org.apache.ws.policy.ExactlyOne;
+
+public class PolicyComparator {
+ public static boolean compare(Policy arg1, Policy arg2) {
+ if (arg1.getId() == null && arg2.getId() != null
+ || arg1.getId() != null && arg1.getId() ==
null) {
+ return false;
+ }
+
+ if (arg1.getId() != null) {
+ if (!arg1.getId().equals(arg2.getId())) {
+ return false;
+ }
+ }
+
+ return compare(arg1.getTerms(), arg2.getTerms());
+ }
+
+ public static boolean compare(Assertion arg1, Assertion arg2) {
+ if (! arg1.getClass().equals(arg2.getClass())) {
+ return false;
+ }
+
+ if (arg1 instanceof Policy) {
+ return compare((Policy) arg1, (Policy) arg2);
+
+ } else if (arg1 instanceof PolicyReference) {
+
+ return compare((PolicyReference) arg1,
(PolicyReference) arg2);
+
+ } else if (arg1 instanceof All) {
+
+ return compare((All) arg1,
+ (All) arg2);
+
+ } else if (arg1 instanceof ExactlyOne) {
+ return compare((ExactlyOne) arg1,
+ (ExactlyOne) arg2);
+
+ } else if (arg1 instanceof PrimitiveAssertion) {
+ return compare((PrimitiveAssertion) arg1,
(PrimitiveAssertion) arg2);
+
+ } else {
+ // TODO should I throw an exception ..
+ }
+
+ return false;
+ }
+
+
+
+ public static boolean compare(PolicyReference arg1, PolicyReference
arg2) {
+ return
arg1.getPolicyURIString().equals(arg2.getPolicyURIString());
+ }
+
+ public static boolean compare(All arg1,
+ All arg2) {
+ return compare(arg1.getTerms(), arg2.getTerms());
+ }
+
+ public static boolean compare(ExactlyOne arg1,
+ ExactlyOne arg2) {
+ return compare(arg1.getTerms(), arg2.getTerms());
+ }
+
+ public static boolean compare(PrimitiveAssertion arg1,
+ PrimitiveAssertion arg2) {
+ if (!(arg1.getName().equals(arg2.getName()))) {
+ return false;
+ }
+ if (arg1.getStrValue() != null) {
+ String arg1Str = arg1.getStrValue().trim();
+ if (arg2.getStrValue() == null) {
+ return false;
+ } else {
+ String arg2Str = arg2.getStrValue().trim();
+ if (! arg1Str.equals(arg2Str)) {
+ return false;}
+ }
+ }
+// if ((arg1.getStrValue() == null || arg1.getStrValue().trim() ==
"") && (arg2.getStrValue() != null && arg2.getStrValue().trim() != "")
+// || (arg1.getStrValue() != null &&
arg1.getStrValue().trim() == "") && (arg1.getStrValue() == null ||
arg1.getStrValue().trim() == "")) {
+// return false;
+// }
+ return compare(arg1.getTerms(), arg2.getTerms());
+ }
+
+ private static boolean compare(List arg1, List arg2) {
+ if (arg1.size() != arg2.size()) {
+ return false;
+ }
+
+ Iterator iterator = arg1.iterator();
+ Assertion assertion1;
+
+ while (iterator.hasNext()) {
+ assertion1 = (Assertion) iterator.next();
+
+ Iterator iterator2 = arg2.iterator();
+ boolean match = false;
+ Assertion assertion2;
+
+ while (iterator2.hasNext()) {
+ assertion2 = (Assertion) iterator2.next();
+ if (compare(assertion1, assertion2)) {
+ match = true;
+ break;
+ }
+ }
+
+ if (!match) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private static boolean compare(Hashtable arg1, Hashtable arg2) {
+ if (arg1.size() != arg2.size()) {
+ return false;
+ }
+ Iterator iterator1 = arg1.keySet().iterator();
+ while (iterator1.hasNext()) {
+ QName qname = (QName) iterator1.next();
+ if (arg2.get(qname) == null
+ ||
!arg1.get(qname).equals(arg2.get(qname))) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
\ No newline at end of file
Added:
webservices/commons/branches/modules/neethi/1_1/src/test/test-resources/base/Policy_Vocabulary.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/test/test-resources/base/Policy_Vocabulary.xml?view=auto&rev=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/test/test-resources/base/Policy_Vocabulary.xml
(added)
+++
webservices/commons/branches/modules/neethi/1_1/src/test/test-resources/base/Policy_Vocabulary.xml
Mon Feb 5 01:11:00 2007
@@ -0,0 +1,24 @@
+<wsp:Policy wsu:Id="Policy_Optional_MixedNested"
+
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
+ Name="http://www.ibm.com/policies/TestID"
+ xmlns:cal="http://policy.test.webservices.com/calendar"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+ cal:attributeA="A" cal:attributeB="B" cal:attributeC="C">
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <cal:Hour wsp:Optional="true">24</cal:Hour>
+ <cal:Unknown>XXX</cal:Unknown>
+ <cal:YearDay>Numeric</cal:YearDay>
+ </wsp:All>
+ <cal:Month wsp:Optional="true">UNSUPPORTED_XXX</cal:Month>
+ </wsp:ExactlyOne>
+ <wsp:Policy>
+ <wsp:ExactlyOne>
+ <cal:Unknown wsp:Optional="true">YYY</cal:Unknown>
+ <cal:YearDay>Numeric</cal:YearDay>
+ </wsp:ExactlyOne>
+ <cal:MonthDay wsp:Optional="true">UNSUPPORTED_YYY</cal:MonthDay>
+ </wsp:Policy>
+ <cal:Hour wsp:Optional="true">24</cal:Hour>
+</wsp:Policy>
+
Modified:
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Driver.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Driver.java?view=diff&rev=503598&r1=503597&r2=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Driver.java
(original)
+++
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Driver.java
Mon Feb 5 01:11:00 2007
@@ -32,6 +32,7 @@
suite.addTestSuite(Test_JIRA14.class);
suite.addTestSuite(Test_Policy.class);
suite.addTestSuite(Test_EffectivePolicy.class);
+ suite.addTestSuite(Test_Policy2.class);
suite.run();
}
Modified:
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_EffectivePolicy.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_EffectivePolicy.java?view=diff&rev=503598&r1=503597&r2=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_EffectivePolicy.java
(original)
+++
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_EffectivePolicy.java
Mon Feb 5 01:11:00 2007
@@ -8,11 +8,9 @@
import javax.xml.namespace.QName;
import org.apache.ws.policy.attachment.WSDLPolicyProcessor;
-import org.apache.ws.policy.util.ExtraUtil;
import org.apache.ws.policy.util.PolicyFactory;
import org.apache.ws.policy.util.PolicyReader;
import org.apache.ws.policy.util.PolicyRegistry;
-import org.apache.ws.policy.util.PolicyUtil;
public class Test_EffectivePolicy extends PolicyTestCase {
Modified:
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy.java?view=diff&rev=503598&r1=503597&r2=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy.java
(original)
+++
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy.java
Mon Feb 5 01:11:00 2007
@@ -1227,7 +1227,7 @@
in = getResource("base/Policy_Equality2.xml");
Policy pol2 = pReader.readPolicy(in);
-
+
assertTrue("Comparator: Policy1 should be EQUAL to Policy2",
PolicyComparator.compare(pol1, pol2) == true);
assertTrue("Comparator: Policy2 should be EQUAL to Policy1",
Added:
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy2.java
URL:
http://svn.apache.org/viewvc/webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy2.java?view=auto&rev=503598
==============================================================================
---
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy2.java
(added)
+++
webservices/commons/branches/modules/neethi/1_1/src/test/test2/org/apache/ws/policy/Test_Policy2.java
Mon Feb 5 01:11:00 2007
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2004,2006 The Apache Software Foundation.
+ *
+ * Licensed 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.ws.policy;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.ws.policy.Policy;
+import org.apache.ws.policy.PrimitiveAssertion;
+import org.apache.ws.policy.util.PolicyComparator;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyReader;
+import org.apache.ws.policy.util.PolicyUtil;
+
+public class Test_Policy2 extends PolicyTestCase {
+ PolicyReader reader = PolicyFactory
+ .getPolicyReader(PolicyFactory.OM_POLICY_READER);
+
+ public Test_Policy2(String name) {
+ super(name);
+ }
+
+ public void testNormalizeNested() throws Exception {
+ String fileName;
+ Policy policy;
+
+ fileName = "base" + File.separator + "Policy_Vocabulary.xml";
+ policy = reader.readPolicy(getResource(fileName));
+
+ List vocab = policy.getVocabulary();
+
+ assertTrue("Normalize test", vocab.size() == 5 );
+
+ }
+
+ public static void main(String[] args) {
+ WSPTestSuite suite = new WSPTestSuite(Test_Policy2.class);
+ suite.run();
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]