You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2009/05/05 17:27:54 UTC

svn commit: r771802 - in /jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions: PackageTest.java ResponseAssertionTest.java SizeAssertionTest.java XPathAssertionTest.java

Author: sebb
Date: Tue May  5 15:27:54 2009
New Revision: 771802

URL: http://svn.apache.org/viewvc?rev=771802&view=rev
Log:
Use separate classes for each test

Added:
    jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java   (with props)
    jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java   (with props)
Modified:
    jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/PackageTest.java
    jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/XPathAssertionTest.java

Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/PackageTest.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/PackageTest.java?rev=771802&r1=771801&r2=771802&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/PackageTest.java (original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/PackageTest.java Tue May  5 15:27:54 2009
@@ -254,308 +254,5 @@
 
 	}
 
-	public static class ResponseAssertionTest extends TestCase{
-
-		private JMeterContext jmctx;
-		private ResponseAssertion assertion;
-		private SampleResult sample;
-		private JMeterVariables vars;
-		private AssertionResult result;
-		
-		public void setUp() throws MalformedURLException {
-			jmctx = JMeterContextService.getContext();
-			assertion = new ResponseAssertion();
-			assertion.setThreadContext(jmctx);
-			sample = new SampleResult();
-			vars = new JMeterVariables();
-			jmctx.setVariables(vars);
-			jmctx.setPreviousResult(sample);
-			sample.setResponseData(
-					(
-					"response Data\n" +
-					"line 2\n\nEOF"
-					).getBytes());
-			sample.setURL(new URL("http://localhost/Sampler/Data/"));
-			sample.setResponseCode("401");
-			sample.setResponseHeaders("X-Header: abcd");
-		}
-
-		public void testResponseAssertionEquals() throws Exception{
-			assertion.unsetNotType();
-			assertion.setToEqualsType();
-			assertion.setTestFieldURL();
-			assertion.addTestString("Sampler Label");
-			assertion.addTestString("Sampler labelx");		
-			result = assertion.getResult(sample);
-			assertFailed();
-
-			assertion.setToNotType();
-			assertion.clearTestStrings();
-			assertion.addTestString("Sampler LabeL");
-			assertion.addTestString("Sampler Labelx");		
-			result = assertion.getResult(sample);
-			assertPassed();
-		}
-		
-		public void testResponseAssertionHeaders() throws Exception{
-			assertion.unsetNotType();
-			assertion.setToEqualsType();
-			assertion.setTestFieldResponseHeaders();
-			assertion.addTestString("X-Header: abcd");
-			assertion.addTestString("X-Header: abcdx");
-			result = assertion.getResult(sample);
-			assertFailed();
-
-			assertion.clearTestStrings();
-			assertion.addTestString("X-Header: abcd");
-			result = assertion.getResult(sample);
-			assertPassed();
-		}
-		
-		public void testResponseAssertionContains() throws Exception{
-			assertion.unsetNotType();
-			assertion.setToContainsType();
-			assertion.setTestFieldURL();
-			assertion.addTestString("Sampler");
-			assertion.addTestString("Label");
-			assertion.addTestString(" x");
-			
-			result = assertion.getResult(sample);
-			assertFailed();
-			
-			assertion.setToNotType();
-			
-			result = assertion.getResult(sample);
-			assertFailed();
-
-			assertion.clearTestStrings();
-			assertion.addTestString("r l");
-			result = assertion.getResult(sample);
-			assertPassed();
-
-			assertion.unsetNotType();
-			assertion.setTestFieldResponseData();
-			
-			assertion.clearTestStrings();
-			assertion.addTestString("line 2");
-			result = assertion.getResult(sample);
-			assertPassed();
-
-			assertion.clearTestStrings();
-			assertion.addTestString("(?s)line \\d+.*EOF");
-			result = assertion.getResult(sample);
-			assertPassed();
-
-			assertion.setTestFieldResponseCode();
-			
-			assertion.clearTestStrings();
-			assertion.addTestString("401");
-			result = assertion.getResult(sample);
-			assertPassed();
-
-        }
-		
-        public void testResponseAssertionSubstring() throws Exception{
-            assertion.unsetNotType();
-            assertion.setToSubstringType();
-            assertion.setTestFieldURL();
-            assertion.addTestString("Sampler");
-            assertion.addTestString("Label");
-            assertion.addTestString("+(");
-            
-            result = assertion.getResult(sample);
-            assertFailed();
-            
-            assertion.setToNotType();
-            
-            result = assertion.getResult(sample);
-            assertFailed();
-
-            assertion.clearTestStrings();
-            assertion.addTestString("r l");
-            result = assertion.getResult(sample);
-            assertPassed();
-
-            assertion.unsetNotType();
-            assertion.setTestFieldResponseData();
-            
-            assertion.clearTestStrings();
-            assertion.addTestString("line 2");
-            result = assertion.getResult(sample);
-            assertPassed();
-
-            assertion.clearTestStrings();
-            assertion.addTestString("line 2\n\nEOF");
-            result = assertion.getResult(sample);
-            assertPassed();
-
-            assertion.setTestFieldResponseCode();
-            
-            assertion.clearTestStrings();
-            assertion.addTestString("401");
-            result = assertion.getResult(sample);
-            assertPassed();
-
-        }
-
-// TODO - need a lot more tests
-		
-		private void assertPassed() throws Exception{
-			assertNull(result.getFailureMessage(),result.getFailureMessage());
-            assertFalse("Not expecting error: "+result.getFailureMessage(),result.isError());
-			assertFalse("Not expecting error",result.isError());
-			assertFalse("Not expecting failure",result.isFailure());		
-		}
-		
-		private void assertFailed() throws Exception{
-			assertNotNull(result.getFailureMessage());
-			assertFalse("Should not be: Response was null","Response was null".equals(result.getFailureMessage()));
-			assertFalse("Not expecting error: "+result.getFailureMessage(),result.isError());
-			assertTrue("Expecting failure",result.isFailure());		
-			
-		}
-}
-
-	public static class SizeAssertionTest extends JMeterTestCase{
-
-		private JMeterContext jmctx;
-		private SizeAssertion assertion;
-		private SampleResult sample1,sample0;
-		private JMeterVariables vars;
-		private AssertionResult result;
-		private String data1 = "response Data\n" +	"line 2\n\nEOF";
-		private int data1Len=data1.length();
-		public void setUp() {
-			jmctx = JMeterContextService.getContext();
-			assertion = new SizeAssertion();
-			assertion.setThreadContext(jmctx);
-			vars = new JMeterVariables();
-			jmctx.setVariables(vars);
-			sample0 = new SampleResult();
-			sample1 = new SampleResult();
-			sample1.setResponseData(data1.getBytes());
-		}
-
-		public void testSizeAssertionEquals() throws Exception{
-			assertion.setCompOper(SizeAssertion.EQUAL);
-			assertion.setAllowedSize(0);
-			result = assertion.getResult(sample1);
-			assertFailed();
-
-			result = assertion.getResult(sample0);
-			assertPassed();
-
-			assertion.setAllowedSize(data1Len);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertFailed();
-        }
-		
-		public void testSizeAssertionNotEquals() throws Exception{
-			assertion.setCompOper(SizeAssertion.NOTEQUAL);
-			assertion.setAllowedSize(0);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertFailed();
-
-			assertion.setAllowedSize(data1Len);
-			result = assertion.getResult(sample1);
-			assertFailed();
-
-			result = assertion.getResult(sample0);
-			assertPassed();
-        }
-
-		public void testSizeAssertionGreaterThan() throws Exception{
-			assertion.setCompOper(SizeAssertion.GREATERTHAN);
-			assertion.setAllowedSize(0);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertFailed();
-
-			assertion.setAllowedSize(data1Len);
-			result = assertion.getResult(sample1);
-			assertFailed();
-
-			result = assertion.getResult(sample0);
-			assertFailed();
-        }
-		
-		public void testSizeAssertionGreaterThanEqual() throws Exception{
-			assertion.setCompOper(SizeAssertion.GREATERTHANEQUAL);
-			assertion.setAllowedSize(0);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertPassed();
-
-			assertion.setAllowedSize(data1Len);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertFailed();
-        }
-		
-		public void testSizeAssertionLessThan() throws Exception{
-			assertion.setCompOper(SizeAssertion.LESSTHAN);
-			assertion.setAllowedSize(0);
-			result = assertion.getResult(sample1);
-			assertFailed();
-
-			result = assertion.getResult(sample0);
-			assertFailed();
-
-			assertion.setAllowedSize(data1Len+1);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertPassed();
-        }
-
-		public void testSizeAssertionLessThanEqual() throws Exception{
-			assertion.setCompOper(SizeAssertion.LESSTHANEQUAL);
-			assertion.setAllowedSize(0);
-			result = assertion.getResult(sample1);
-			assertFailed();
-
-			result = assertion.getResult(sample0);
-			assertPassed();
-
-			assertion.setAllowedSize(data1Len+1);
-			result = assertion.getResult(sample1);
-			assertPassed();
-
-			result = assertion.getResult(sample0);
-			assertPassed();
-        }
-// TODO - need a lot more tests
-		
-		private void assertPassed() throws Exception{
-			if (null != result.getFailureMessage()){
-				//System.out.println(result.getFailureMessage());// debug
-			}
-			assertNull("Failure message should be null",result.getFailureMessage());
-			assertFalse(result.isError());
-			assertFalse(result.isFailure());		
-		}
-		
-		private void assertFailed() throws Exception{
-			assertNotNull("Failure nessage should not be null",result.getFailureMessage());
-			//System.out.println(result.getFailureMessage());
-			assertFalse("Should not be: Response was null","Response was null".equals(result.getFailureMessage()));
-			assertFalse(result.isError());
-			assertTrue(result.isFailure());		
-			
-		}
-}
 
 }

Added: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java?rev=771802&view=auto
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java (added)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java Tue May  5 15:27:54 2009
@@ -0,0 +1,194 @@
+/*
+ * 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.jmeter.assertions;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+
+public class ResponseAssertionTest  extends TestCase {
+
+    public ResponseAssertionTest() {
+    }
+
+    private JMeterContext jmctx;
+    private ResponseAssertion assertion;
+    private SampleResult sample;
+    private JMeterVariables vars;
+    private AssertionResult result;
+    
+    public void setUp() throws MalformedURLException {
+        jmctx = JMeterContextService.getContext();
+        assertion = new ResponseAssertion();
+        assertion.setThreadContext(jmctx);
+        sample = new SampleResult();
+        vars = new JMeterVariables();
+        jmctx.setVariables(vars);
+        jmctx.setPreviousResult(sample);
+        sample.setResponseData(
+                (
+                "response Data\n" +
+                "line 2\n\nEOF"
+                ).getBytes());
+        sample.setURL(new URL("http://localhost/Sampler/Data/"));
+        sample.setResponseCode("401");
+        sample.setResponseHeaders("X-Header: abcd");
+    }
+
+    public void testResponseAssertionEquals() throws Exception{
+        assertion.unsetNotType();
+        assertion.setToEqualsType();
+        assertion.setTestFieldURL();
+        assertion.addTestString("Sampler Label");
+        assertion.addTestString("Sampler labelx");      
+        result = assertion.getResult(sample);
+        assertFailed();
+
+        assertion.setToNotType();
+        assertion.clearTestStrings();
+        assertion.addTestString("Sampler LabeL");
+        assertion.addTestString("Sampler Labelx");      
+        result = assertion.getResult(sample);
+        assertPassed();
+    }
+    
+    public void testResponseAssertionHeaders() throws Exception{
+        assertion.unsetNotType();
+        assertion.setToEqualsType();
+        assertion.setTestFieldResponseHeaders();
+        assertion.addTestString("X-Header: abcd");
+        assertion.addTestString("X-Header: abcdx");
+        result = assertion.getResult(sample);
+        assertFailed();
+
+        assertion.clearTestStrings();
+        assertion.addTestString("X-Header: abcd");
+        result = assertion.getResult(sample);
+        assertPassed();
+    }
+    
+    public void testResponseAssertionContains() throws Exception{
+        assertion.unsetNotType();
+        assertion.setToContainsType();
+        assertion.setTestFieldURL();
+        assertion.addTestString("Sampler");
+        assertion.addTestString("Label");
+        assertion.addTestString(" x");
+        
+        result = assertion.getResult(sample);
+        assertFailed();
+        
+        assertion.setToNotType();
+        
+        result = assertion.getResult(sample);
+        assertFailed();
+
+        assertion.clearTestStrings();
+        assertion.addTestString("r l");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+        assertion.unsetNotType();
+        assertion.setTestFieldResponseData();
+        
+        assertion.clearTestStrings();
+        assertion.addTestString("line 2");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+        assertion.clearTestStrings();
+        assertion.addTestString("(?s)line \\d+.*EOF");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+        assertion.setTestFieldResponseCode();
+        
+        assertion.clearTestStrings();
+        assertion.addTestString("401");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+    }
+    
+    public void testResponseAssertionSubstring() throws Exception{
+        assertion.unsetNotType();
+        assertion.setToSubstringType();
+        assertion.setTestFieldURL();
+        assertion.addTestString("Sampler");
+        assertion.addTestString("Label");
+        assertion.addTestString("+(");
+        
+        result = assertion.getResult(sample);
+        assertFailed();
+        
+        assertion.setToNotType();
+        
+        result = assertion.getResult(sample);
+        assertFailed();
+
+        assertion.clearTestStrings();
+        assertion.addTestString("r l");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+        assertion.unsetNotType();
+        assertion.setTestFieldResponseData();
+        
+        assertion.clearTestStrings();
+        assertion.addTestString("line 2");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+        assertion.clearTestStrings();
+        assertion.addTestString("line 2\n\nEOF");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+        assertion.setTestFieldResponseCode();
+        
+        assertion.clearTestStrings();
+        assertion.addTestString("401");
+        result = assertion.getResult(sample);
+        assertPassed();
+
+    }
+
+//TODO - need a lot more tests
+    
+    private void assertPassed() throws Exception{
+        assertNull(result.getFailureMessage(),result.getFailureMessage());
+        assertFalse("Not expecting error: "+result.getFailureMessage(),result.isError());
+        assertFalse("Not expecting error",result.isError());
+        assertFalse("Not expecting failure",result.isFailure());        
+    }
+    
+    private void assertFailed() throws Exception{
+        assertNotNull(result.getFailureMessage());
+        assertFalse("Should not be: Response was null","Response was null".equals(result.getFailureMessage()));
+        assertFalse("Not expecting error: "+result.getFailureMessage(),result.isError());
+        assertTrue("Expecting failure",result.isFailure());     
+        
+    }
+}
\ No newline at end of file

Propchange: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/ResponseAssertionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java?rev=771802&view=auto
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java (added)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java Tue May  5 15:27:54 2009
@@ -0,0 +1,168 @@
+/*
+ * 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.jmeter.assertions;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.threads.JMeterContext;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+
+public class SizeAssertionTest extends JMeterTestCase{
+
+      private JMeterContext jmctx;
+      private SizeAssertion assertion;
+      private SampleResult sample1,sample0;
+      private JMeterVariables vars;
+      private AssertionResult result;
+      private String data1 = "response Data\n" +  "line 2\n\nEOF";
+      private int data1Len=data1.length();
+      
+      public void setUp() {
+          jmctx = JMeterContextService.getContext();
+          assertion = new SizeAssertion();
+          assertion.setThreadContext(jmctx);
+          vars = new JMeterVariables();
+          jmctx.setVariables(vars);
+          sample0 = new SampleResult();
+          sample1 = new SampleResult();
+          sample1.setResponseData(data1.getBytes());
+      }
+
+      public void testSizeAssertionEquals() throws Exception{
+          assertion.setCompOper(SizeAssertion.EQUAL);
+          assertion.setAllowedSize(0);
+          result = assertion.getResult(sample1);
+          assertFailed();
+
+          result = assertion.getResult(sample0);
+          assertPassed();
+
+          assertion.setAllowedSize(data1Len);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertFailed();
+        }
+      
+      public void testSizeAssertionNotEquals() throws Exception{
+          assertion.setCompOper(SizeAssertion.NOTEQUAL);
+          assertion.setAllowedSize(0);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertFailed();
+
+          assertion.setAllowedSize(data1Len);
+          result = assertion.getResult(sample1);
+          assertFailed();
+
+          result = assertion.getResult(sample0);
+          assertPassed();
+        }
+
+      public void testSizeAssertionGreaterThan() throws Exception{
+          assertion.setCompOper(SizeAssertion.GREATERTHAN);
+          assertion.setAllowedSize(0);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertFailed();
+
+          assertion.setAllowedSize(data1Len);
+          result = assertion.getResult(sample1);
+          assertFailed();
+
+          result = assertion.getResult(sample0);
+          assertFailed();
+        }
+      
+      public void testSizeAssertionGreaterThanEqual() throws Exception{
+          assertion.setCompOper(SizeAssertion.GREATERTHANEQUAL);
+          assertion.setAllowedSize(0);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertPassed();
+
+          assertion.setAllowedSize(data1Len);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertFailed();
+        }
+      
+      public void testSizeAssertionLessThan() throws Exception{
+          assertion.setCompOper(SizeAssertion.LESSTHAN);
+          assertion.setAllowedSize(0);
+          result = assertion.getResult(sample1);
+          assertFailed();
+
+          result = assertion.getResult(sample0);
+          assertFailed();
+
+          assertion.setAllowedSize(data1Len+1);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertPassed();
+        }
+
+      public void testSizeAssertionLessThanEqual() throws Exception{
+          assertion.setCompOper(SizeAssertion.LESSTHANEQUAL);
+          assertion.setAllowedSize(0);
+          result = assertion.getResult(sample1);
+          assertFailed();
+
+          result = assertion.getResult(sample0);
+          assertPassed();
+
+          assertion.setAllowedSize(data1Len+1);
+          result = assertion.getResult(sample1);
+          assertPassed();
+
+          result = assertion.getResult(sample0);
+          assertPassed();
+        }
+// TODO - need a lot more tests
+      
+      private void assertPassed() throws Exception{
+          if (null != result.getFailureMessage()){
+              //System.out.println(result.getFailureMessage());// debug
+          }
+          assertNull("Failure message should be null",result.getFailureMessage());
+          assertFalse(result.isError());
+          assertFalse(result.isFailure());        
+      }
+      
+      private void assertFailed() throws Exception{
+          assertNotNull("Failure nessage should not be null",result.getFailureMessage());
+          //System.out.println(result.getFailureMessage());
+          assertFalse("Should not be: Response was null","Response was null".equals(result.getFailureMessage()));
+          assertFalse(result.isError());
+          assertTrue(result.isFailure());     
+          
+      }
+}

Propchange: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/SizeAssertionTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/XPathAssertionTest.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/XPathAssertionTest.java?rev=771802&r1=771801&r2=771802&view=diff
==============================================================================
--- jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/XPathAssertionTest.java (original)
+++ jakarta/jmeter/trunk/test/src/org/apache/jmeter/assertions/XPathAssertionTest.java Tue May  5 15:27:54 2009
@@ -28,8 +28,11 @@
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
 
 public class XPathAssertionTest extends JMeterTestCase {
+    private static final Logger log = LoggingManager.getLoggerForClass();
 
 	private XPathAssertion assertion;
 
@@ -47,16 +50,26 @@
 		super.setUp();
 		jmctx = JMeterContextService.getContext();
 		assertion = new XPathAssertion();
-		assertion.setThreadContext(jmctx);// This would be done by the run
-											// command
+		assertion.setThreadContext(jmctx);// This would be done by the run command
 		result = new SampleResult();
 		result.setResponseData(readFile("testfiles/XPathAssertionTest.xml"));
 		vars = new JMeterVariables();
 		jmctx.setVariables(vars);
-		//jmctx.setPreviousResult(result);
+		jmctx.setPreviousResult(result);
 		//testLog.setPriority(org.apache.log.Priority.DEBUG);
 	}
 
+	private void setAlternateResponseData(){
+        String data = "<company-xmlext-query-ret>" + "<row>" + "<value field=\"RetCode\">LIS_OK</value>"
+              + "<value field=\"RetCodeExtension\"></value>" + "<value field=\"alias\"></value>"
+              + "<value field=\"positioncount\"></value>" + "<value field=\"invalidpincount\">0</value>"
+              + "<value field=\"pinposition1\">1</value>" + "<value field=\"pinpositionvalue1\"></value>"
+              + "<value field=\"pinposition2\">5</value>" + "<value field=\"pinpositionvalue2\"></value>"
+              + "<value field=\"pinposition3\">6</value>" + "<value field=\"pinpositionvalue3\"></value>"
+              + "</row>" + "</company-xmlext-query-ret>";
+        result.setResponseData(data.getBytes());
+    }
+
 	private ByteArrayOutputStream readBA(String name) throws IOException {
 		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(findTestFile(name)));
 		ByteArrayOutputStream baos = new ByteArrayOutputStream(1000);
@@ -185,4 +198,124 @@
 		assertFalse("Should not be a failure", res.isFailure());
 	}
 
+    public void testNoTolerance() throws Exception {
+        String data = "<html><head><title>testtitle</title></head>" + "<body>"
+                + "<p><i><b>invalid tag nesting</i></b><hr>" + "</body></html>";
+
+        result.setResponseData(data.getBytes());
+        vars = new JMeterVariables();
+        jmctx.setVariables(vars);
+        jmctx.setPreviousResult(result);
+        assertion.setXPathString("/html/head/title");
+        assertion.setValidating(false);
+        assertion.setTolerant(false);
+        AssertionResult res = assertion.getResult(result);
+        log.debug("failureMessage: " + res.getFailureMessage());
+        assertTrue(res.isError());
+        assertFalse(res.isFailure());
+    }
+
+    public void testAssertion() throws Exception {
+        setAlternateResponseData();
+        assertion.setXPathString("//row/value[@field = 'alias']");
+        AssertionResult res = assertion.getResult(jmctx.getPreviousResult());
+        log.debug(" res " + res.isError());
+        log.debug(" failure " + res.getFailureMessage());
+        assertFalse(res.isError());
+        assertFalse(res.isFailure());
+    }
+
+    public void testNegateAssertion() throws Exception {
+        setAlternateResponseData();
+        assertion.setXPathString("//row/value[@field = 'noalias']");
+        assertion.setNegated(true);
+
+        AssertionResult res = assertion.getResult(jmctx.getPreviousResult());
+        log.debug(" res " + res.isError());
+        log.debug(" failure " + res.getFailureMessage());
+        assertFalse(res.isError());
+        assertFalse(res.isFailure());
+    }
+
+    public void testValidationFailure() throws Exception {
+        setAlternateResponseData();
+        assertion.setXPathString("//row/value[@field = 'alias']");
+        assertion.setNegated(false);
+        assertion.setValidating(true);
+        AssertionResult res = assertion.getResult(jmctx.getPreviousResult());
+        log.debug(res.getFailureMessage() + " error: " + res.isError() + " failure: " + res.isFailure());
+        assertTrue(res.isError());
+        assertFalse(res.isFailure());
+    }
+
+    public void testValidationSuccess() throws Exception {
+        String data = "<?xml version=\"1.0\"?>" + "<!DOCTYPE BOOK [" + "<!ELEMENT p (#PCDATA)>"
+                + "<!ELEMENT BOOK         (OPENER,SUBTITLE?,INTRODUCTION?,(SECTION | PART)+)>"
+                + "<!ELEMENT OPENER       (TITLE_TEXT)*>" + "<!ELEMENT TITLE_TEXT   (#PCDATA)>"
+                + "<!ELEMENT SUBTITLE     (#PCDATA)>" + "<!ELEMENT INTRODUCTION (HEADER, p+)+>"
+                + "<!ELEMENT PART         (HEADER, CHAPTER+)>" + "<!ELEMENT SECTION      (HEADER, p+)>"
+                + "<!ELEMENT HEADER       (#PCDATA)>" + "<!ELEMENT CHAPTER      (CHAPTER_NUMBER, CHAPTER_TEXT)>"
+                + "<!ELEMENT CHAPTER_NUMBER (#PCDATA)>" + "<!ELEMENT CHAPTER_TEXT (p)+>" + "]>" + "<BOOK>"
+                + "<OPENER>" + "<TITLE_TEXT>All About Me</TITLE_TEXT>" + "</OPENER>" + "<PART>"
+                + "<HEADER>Welcome To My Book</HEADER>" + "<CHAPTER>"
+                + "<CHAPTER_NUMBER>CHAPTER 1</CHAPTER_NUMBER>" + "<CHAPTER_TEXT>"
+                + "<p>Glad you want to hear about me.</p>" + "<p>There's so much to say!</p>"
+                + "<p>Where should we start?</p>" + "<p>How about more about me?</p>" + "</CHAPTER_TEXT>"
+                + "</CHAPTER>" + "</PART>" + "</BOOK>";
+
+        result.setResponseData(data.getBytes());
+        vars = new JMeterVariables();
+        jmctx.setVariables(vars);
+        jmctx.setPreviousResult(result);
+        assertion.setXPathString("/");
+        assertion.setValidating(true);
+        AssertionResult res = assertion.getResult(result);
+        assertFalse(res.isError());
+        assertFalse(res.isFailure());
+    }
+
+    public void testValidationFailureWithDTD() throws Exception {
+        String data = "<?xml version=\"1.0\"?>" + "<!DOCTYPE BOOK [" + "<!ELEMENT p (#PCDATA)>"
+                + "<!ELEMENT BOOK         (OPENER,SUBTITLE?,INTRODUCTION?,(SECTION | PART)+)>"
+                + "<!ELEMENT OPENER       (TITLE_TEXT)*>" + "<!ELEMENT TITLE_TEXT   (#PCDATA)>"
+                + "<!ELEMENT SUBTITLE     (#PCDATA)>" + "<!ELEMENT INTRODUCTION (HEADER, p+)+>"
+                + "<!ELEMENT PART         (HEADER, CHAPTER+)>" + "<!ELEMENT SECTION      (HEADER, p+)>"
+                + "<!ELEMENT HEADER       (#PCDATA)>" + "<!ELEMENT CHAPTER      (CHAPTER_NUMBER, CHAPTER_TEXT)>"
+                + "<!ELEMENT CHAPTER_NUMBER (#PCDATA)>" + "<!ELEMENT CHAPTER_TEXT (p)+>" + "]>" + "<BOOK>"
+                + "<OPENER>" + "<TITLE_TEXT>All About Me</TITLE_TEXT>" + "</OPENER>" + "<PART>"
+                + "<HEADER>Welcome To My Book</HEADER>" + "<CHAPTER>"
+                + "<CHAPTER_NUMBER>CHAPTER 1</CHAPTER_NUMBER>" + "<CHAPTER_TEXT>"
+                + "<p>Glad you want to hear about me.</p>" + "<p>There's so much to say!</p>"
+                + "<p>Where should we start?</p>" + "<p>How about more about me?</p>" + "</CHAPTER_TEXT>"
+                + "</CHAPTER>" + "<illegal>not defined in dtd</illegal>" + "</PART>" + "</BOOK>";
+
+        result.setResponseData(data.getBytes());
+        vars = new JMeterVariables();
+        jmctx.setVariables(vars);
+        jmctx.setPreviousResult(result);
+        assertion.setXPathString("/");
+        assertion.setValidating(true);
+        AssertionResult res = assertion.getResult(result);
+        log.debug("failureMessage: " + res.getFailureMessage());
+        assertTrue(res.isError());
+        assertFalse(res.isFailure());
+    }
+
+    public void testTolerance() throws Exception {
+        String data = "<html><head><title>testtitle</title></head>" + "<body>"
+                + "<p><i><b>invalid tag nesting</i></b><hr>" + "</body></html>";
+
+        result.setResponseData(data.getBytes());
+        vars = new JMeterVariables();
+        jmctx.setVariables(vars);
+        jmctx.setPreviousResult(result);
+        assertion.setXPathString("/html/head/title");
+        assertion.setValidating(true);
+        assertion.setTolerant(true);
+        AssertionResult res = assertion.getResult(result);
+        log.debug("failureMessage: " + res.getFailureMessage());
+        assertFalse(res.isFailure());
+        assertFalse(res.isError());
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org