You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by sa...@apache.org on 2005/12/11 20:14:07 UTC

svn commit: r355996 - in /webservices/commons/trunk/policy/test/org/apache/ws/policy: NormalizeTest.java PolicyTestCase.java util/PolicyComparator.java

Author: sanka
Date: Sun Dec 11 11:13:54 2005
New Revision: 355996

URL: http://svn.apache.org/viewcvs?rev=355996&view=rev
Log:
Added: testcases for test normalize(..) is working properly

Added:
    webservices/commons/trunk/policy/test/org/apache/ws/policy/NormalizeTest.java
    webservices/commons/trunk/policy/test/org/apache/ws/policy/PolicyTestCase.java
Modified:
    webservices/commons/trunk/policy/test/org/apache/ws/policy/util/PolicyComparator.java

Added: webservices/commons/trunk/policy/test/org/apache/ws/policy/NormalizeTest.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/test/org/apache/ws/policy/NormalizeTest.java?rev=355996&view=auto
==============================================================================
--- webservices/commons/trunk/policy/test/org/apache/ws/policy/NormalizeTest.java (added)
+++ webservices/commons/trunk/policy/test/org/apache/ws/policy/NormalizeTest.java Sun Dec 11 11:13:54 2005
@@ -0,0 +1,54 @@
+/*
+ * 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;
+
+import java.io.File;
+
+import org.apache.ws.policy.util.PolicyComparator;
+import org.apache.ws.policy.util.PolicyFactory;
+import org.apache.ws.policy.util.PolicyReader;
+
+/**
+ * @author Sanka Samaranayake (sanka@apache.org)
+ */
+public class NormalizeTest extends PolicyTestCase {
+	PolicyReader reader = PolicyFactory
+			.getPolicyReader(PolicyFactory.OM_POLICY_READER);
+
+	public NormalizeTest() {
+		super("NormalizeTest");
+	}
+
+	public void test() throws Exception {
+		String r1, r2;
+		Policy p1, p2;
+
+		for (int i = 1; i < 25; i++) {
+
+			r1 = "samples" + File.separator + "test" + i + ".xml";
+			r2 = "normalize" + File.separator + "test" + i + ".xml";
+
+			p1 = reader.readPolicy(getResource(r1));
+			p1 = (Policy) p1.normalize();
+
+			p2 = reader.readPolicy(getResource(r2));
+
+			if (!PolicyComparator.compare(p1, p2)) {
+				fail("test" + i + " normalize() FAILED");
+			} 
+		}
+	}
+}
\ No newline at end of file

Added: webservices/commons/trunk/policy/test/org/apache/ws/policy/PolicyTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/test/org/apache/ws/policy/PolicyTestCase.java?rev=355996&view=auto
==============================================================================
--- webservices/commons/trunk/policy/test/org/apache/ws/policy/PolicyTestCase.java (added)
+++ webservices/commons/trunk/policy/test/org/apache/ws/policy/PolicyTestCase.java Sun Dec 11 11:13:54 2005
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Sanka Samaranayake (sanka@apache.org)
+ */
+public class PolicyTestCase extends TestCase {
+	protected String baseDir = System.getProperty("basedir");
+	protected String testDir = "test" + File.separator;
+	protected String testResourceDir = "test-resources";
+	
+	public PolicyTestCase(String name) {
+		super(name);
+		if (baseDir == null) {
+			baseDir = (String) (new File(".")).getAbsolutePath();
+		}
+		testDir = (String) (new File(baseDir, testDir).getAbsolutePath());	
+	}	
+	
+	public InputStream getResource(String name) {
+		String filePath = (new File(testResourceDir, name)).getAbsolutePath(); 
+		try {
+			FileInputStream fis = new FileInputStream(filePath);
+			return fis;
+		} catch (FileNotFoundException e) {
+			fail("Cannot get resource: " + e.getMessage());
+			throw new RuntimeException();
+		}
+	}
+}
+

Modified: webservices/commons/trunk/policy/test/org/apache/ws/policy/util/PolicyComparator.java
URL: http://svn.apache.org/viewcvs/webservices/commons/trunk/policy/test/org/apache/ws/policy/util/PolicyComparator.java?rev=355996&r1=355995&r2=355996&view=diff
==============================================================================
--- webservices/commons/trunk/policy/test/org/apache/ws/policy/util/PolicyComparator.java (original)
+++ webservices/commons/trunk/policy/test/org/apache/ws/policy/util/PolicyComparator.java Sun Dec 11 11:13:54 2005
@@ -22,12 +22,12 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.ws.policy.model.AndCompositeAssertion;
-import org.apache.ws.policy.model.Assertion;
-import org.apache.ws.policy.model.Policy;
-import org.apache.ws.policy.model.PolicyReference;
-import org.apache.ws.policy.model.PrimitiveAssertion;
-import org.apache.ws.policy.model.XorCompositeAssertion;
+import org.apache.ws.policy.AndCompositeAssertion;
+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.XorCompositeAssertion;
 
 /**
  * @author Sanka Samaranayake (sanka@apache.org)