Commits

Anonymous committed 5da8411

added more test cases.

Issue number:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk/src@1011e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits e5299c4

Comments (0)

Files changed (1)

test/com/opensymphony/xwork/validator/URLValidatorTest.java

 public class URLValidatorTest extends TestCase {
 
 	
+	OgnlValueStack stack;
+	ActionContext actionContext;
+	
 	public void testAcceptNullValueForMutualExclusionOfValidators() throws Exception {
-		OgnlValueStack stack = new OgnlValueStack();
-		ActionContext. getContext().setValueStack(stack);
 		
 		URLValidator validator = new URLValidator();
 		validator.setValidatorContext(new GenericValidatorContext(new Object()));
 	}
 	
 	public void testInvalidEmptyValue() throws Exception {
-		OgnlValueStack stack = new OgnlValueStack();
-		ActionContext.getContext().setValueStack(stack);
 		
 		URLValidator validator = new URLValidator();
 		validator.setValidatorContext(new GenericValidatorContext(new Object()));
 	}
 	
 	public void testInvalidValue() throws Exception {
-		OgnlValueStack stack = new OgnlValueStack();
-		ActionContext.getContext().setValueStack(stack);
 		
 		URLValidator validator = new URLValidator();
 		validator.setValidatorContext(new GenericValidatorContext(new Object()));
 	}
 	
 	
+	public void testValidUrl1() throws Exception {
+		
+		URLValidator validator = new URLValidator();
+		validator.setValidatorContext(new GenericValidatorContext(new Object()));
+		validator.setFieldName("testingUrl4");
+		validator.validate(new MyObject());
+		
+		assertFalse(validator.getValidatorContext().hasErrors());
+		assertFalse(validator.getValidatorContext().hasActionErrors());
+		assertFalse(validator.getValidatorContext().hasActionMessages());
+		assertFalse(validator.getValidatorContext().hasFieldErrors());
+	}
 	
+	public void testValidUrl2() throws Exception {
+		
+		URLValidator validator = new URLValidator();
+		validator.setValidatorContext(new GenericValidatorContext(new Object()));
+		validator.setFieldName("testingUrl5");
+		validator.validate(new MyObject());
+		
+		assertFalse(validator.getValidatorContext().hasErrors());
+		assertFalse(validator.getValidatorContext().hasActionErrors());
+		assertFalse(validator.getValidatorContext().hasActionMessages());
+		assertFalse(validator.getValidatorContext().hasFieldErrors());
+	}
+	
+	protected void setUp() throws Exception {
+		stack = new OgnlValueStack();
+		actionContext = ActionContext.getContext();
+		actionContext.setValueStack(stack);
+	}
+	
+	protected void tearDown() throws Exception {
+		stack = null;
+		actionContext = null;
+	}
 	
 	
 	class MyObject {
 		public String getTestingUrl3() {
 			return "sasdasd@asddd";
 		}
+		
+		public String getTestingUrl4() {
+			//return "http://yahoo.com/";
+			return "http://www.jroller.com1?qwe=qwe";
+		}
+		
+		public String getTestingUrl5() {
+			return "http://yahoo.com/articles?id=123";
+		}
 	}
 }