rave-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramin...@apache.org
Subject svn commit: r1241769 - in /incubator/rave/trunk: pom.xml rave-components/rave-web/src/main/java/org/apache/rave/portal/web/validator/WidgetValidator.java rave-components/rave-web/src/test/java/org/apache/rave/portal/web/validator/WidgetValidatorTest.java
Date Wed, 08 Feb 2012 04:17:03 GMT
Author: raminder
Date: Wed Feb  8 04:17:03 2012
New Revision: 1241769

URL: http://svn.apache.org/viewvc?rev=1241769&view=rev
Log:
updated version of common-validator . RAVE-378

Modified:
    incubator/rave/trunk/pom.xml
    incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/validator/WidgetValidator.java
    incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/validator/WidgetValidatorTest.java

Modified: incubator/rave/trunk/pom.xml
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/pom.xml?rev=1241769&r1=1241768&r2=1241769&view=diff
==============================================================================
--- incubator/rave/trunk/pom.xml (original)
+++ incubator/rave/trunk/pom.xml Wed Feb  8 04:17:03 2012
@@ -55,8 +55,7 @@
         <log4j.version>1.2.16</log4j.version>
         <junit.version>4.7</junit.version>
         <commons-lang.version>2.6</commons-lang.version>
-        <!-- Don't update to commons-validator 1.3.1, it misses a dependency -->
-        <commons-validator.version>1.3.0</commons-validator.version>
+        <commons-validator.version>1.4.0</commons-validator.version>
         <commons-collections.version>3.2.1</commons-collections.version>
         <commons-codec.version>1.4</commons-codec.version>
         <icu4j.version>4.8.1.1</icu4j.version>
@@ -367,7 +366,7 @@
                 <artifactId>commons-codec</artifactId>
                 <version>${commons-codec.version}</version>
             </dependency>
-            
+
             <!-- commons-collections: needed here to enforce proper version instead of
relying on transitive dependencies -->
             <dependency>
                 <groupId>commons-collections</groupId>

Modified: incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/validator/WidgetValidator.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/validator/WidgetValidator.java?rev=1241769&r1=1241768&r2=1241769&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/validator/WidgetValidator.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/main/java/org/apache/rave/portal/web/validator/WidgetValidator.java
Wed Feb  8 04:17:03 2012
@@ -20,7 +20,8 @@
 package org.apache.rave.portal.web.validator;
 
 import org.apache.commons.lang.StringUtils;
-import org.apache.commons.validator.UrlValidator;
+import org.apache.commons.validator.routines.RegexValidator;
+import org.apache.commons.validator.routines.UrlValidator;
 import org.apache.rave.portal.model.Widget;
 import org.springframework.validation.Errors;
 import org.springframework.validation.ValidationUtils;
@@ -36,8 +37,8 @@ public abstract class WidgetValidator im
 
     public WidgetValidator() {
         super();
-        String[] allowedSchemes = {"http", "https"};
-        urlValidator = new UrlValidator(allowedSchemes);
+        RegexValidator regex = new RegexValidator(new String[] {"http", "https","((localhost)(:[0-9]+))"});
+        urlValidator = new UrlValidator(regex, 0);
     }
 
     /**
@@ -63,7 +64,7 @@ public abstract class WidgetValidator im
     }
 
     /**
-     * Checks if a Widget already exists for this URL. 
+     * Checks if a Widget already exists for this URL.
      * @param widget {@link Widget} to validate
      * @param errors {@link Errors}
      */

Modified: incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/validator/WidgetValidatorTest.java
URL: http://svn.apache.org/viewvc/incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/validator/WidgetValidatorTest.java?rev=1241769&r1=1241768&r2=1241769&view=diff
==============================================================================
--- incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/validator/WidgetValidatorTest.java
(original)
+++ incubator/rave/trunk/rave-components/rave-web/src/test/java/org/apache/rave/portal/web/validator/WidgetValidatorTest.java
Wed Feb  8 04:17:03 2012
@@ -19,13 +19,16 @@
 
 package org.apache.rave.portal.web.validator;
 
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+
+import org.apache.commons.validator.routines.RegexValidator;
+import org.apache.commons.validator.routines.UrlValidator;
 import org.apache.rave.portal.model.Widget;
 import org.junit.Before;
 import org.junit.Test;
 import org.springframework.validation.Errors;
 
-import static junit.framework.Assert.assertTrue;
-
 /**
  * Test for {@link WidgetValidator}
  */
@@ -43,7 +46,28 @@ public class WidgetValidatorTest {
         assertTrue("Supports org.apache.rave.portal.model.Widget", widgetValidator.supports(Widget.class));
     }
 
-    private class MockWidgetValidator extends WidgetValidator {
+  /*
+    * Testing the same method of URL validator used in validate method. Its was really hard
to create Error object
+    */
+ @Test
+ public void testValidation() throws Exception {
+      RegexValidator regex = new RegexValidator(new String[]{"http","https","((localhost)(:[0-9]+))",".*\\.linux-server(:[0-9]+)"});
+      UrlValidator validator = new UrlValidator(regex, 0);
+      assertTrue("localhost URL should validate",
+                validator.isValid("http://localhost:8080/demogadgets/CTSSResourcesMapView.xml"));
+        assertTrue("127.0.0.1 should validate",
+                validator.isValid("http://127.0.0.1:8080/demogadgets/CTSSResourcesMapView.xml"));
+        assertTrue("my.linux-server should validate",
+                validator.isValid("http://my.linux-server:8080/demogadgets/CTSSResourcesMapView.xml"));
+
+        assertFalse("broke.my-test should not validate",
+                validator.isValid("http://broke.my-test/test/index.html"));
+
+        assertTrue("www.apache.org should still validate",
+                validator.isValid("http://www.apache.org/test/index.html"));
+    }
+
+     private class MockWidgetValidator extends WidgetValidator {
 
         @Override
         protected void validateIfWidgetAlreadyExists(Widget widget, Errors errors) {



Mime
View raw message