You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by gs...@apache.org on 2007/10/15 23:23:31 UTC
svn commit: r584925 [34/34] - in /wicket/trunk/jdk-1.4/wicket/src:
main/java/org/apache/wicket/ main/java/org/apache/wicket/ajax/
main/java/org/apache/wicket/ajax/calldecorator/
main/java/org/apache/wicket/ajax/form/ main/java/org/apache/wicket/ajax/ma...
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/DurationTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/DurationTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/DurationTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/DurationTest.java Mon Oct 15 14:21:25 2007
@@ -27,84 +27,83 @@
/**
* Test cases for this object
+ *
* @author Jonathan Locke
*/
public final class DurationTest extends TestCase
{
- /**
- *
- * @throws StringValueConversionException
- */
- public void testValues() throws StringValueConversionException
- {
- Assert.assertEquals(Duration.milliseconds(3000), Duration.seconds(3));
- Assert.assertEquals(Duration.seconds(120), Duration.minutes(2));
- Assert.assertEquals(Duration.minutes(1440), Duration.hours(24));
- Assert.assertEquals(Duration.hours(48), Duration.days(2));
- Assert.assertEquals(Duration.minutes(90), Duration.valueOf("90 minutes"));
- Assert.assertEquals(Duration.days(9), Duration.valueOf("9 days"));
- Assert.assertEquals(Duration.hours(1), Duration.valueOf("1 hour"));
- Assert.assertTrue(9 == Duration.days(9).days());
- Assert.assertTrue(11 == Duration.hours(11).hours());
- Assert.assertTrue(21 == Duration.minutes(21).minutes());
- Assert.assertTrue(51 == Duration.seconds(51).seconds());
- }
-
- /**
- *
- *
- */
- public void testOperations()
- {
- Assert.assertTrue(Duration.milliseconds(3001).greaterThan(Duration.seconds(3)));
- Assert.assertTrue(Duration.milliseconds(2999).lessThan(Duration.seconds(3)));
- Assert.assertEquals(-1, Duration.milliseconds(2999).compareTo(Duration.seconds(3)));
- Assert.assertEquals(1, Duration.milliseconds(3001).compareTo(Duration.seconds(3)));
- Assert.assertEquals(0, Duration.milliseconds(3000).compareTo(Duration.seconds(3)));
- Assert.assertEquals(Duration.minutes(10), Duration.minutes(4).add(Duration.minutes(6)));
- Assert.assertEquals(Duration.ONE_HOUR, Duration.minutes(90).subtract(Duration.minutes(30)));
-
- String value = NumberFormat.getNumberInstance().format(1.5);
-
- Assert.assertEquals(value + " minutes", Duration.seconds(90).toString());
- Assert.assertEquals("12 hours", Duration.days(0.5).toString());
- }
-
- /**
- *
- *
- */
- public void testSleep()
- {
- Assert.assertTrue(Duration.seconds(0.5).lessThan(Duration.benchmark(new Runnable()
- {
- public void run()
- {
- Duration.seconds(1.5).sleep();
- }
- })));
-
- Assert.assertTrue(Duration.seconds(1).greaterThan(Duration.benchmark(new Runnable()
- {
- public void run()
- {
- Duration.hours(-1).sleep();
- }
- })));
- }
-
- /**
- *
- * @throws StringValueConversionException
- */
- public void testLocale() throws StringValueConversionException
- {
- Assert.assertEquals(Duration.minutes(90), Duration.valueOf("90 minutes"));
- Assert.assertEquals(Duration.hours(1.5), Duration.valueOf("1.5 hour", Locale.US));
- Assert.assertEquals(Duration.hours(1.5), Duration.valueOf("1,5 hour", Locale.GERMAN));
- Assert.assertEquals("1.5 hours", Duration.hours(1.5).toString(Locale.US));
- Assert.assertEquals("1,5 hours", Duration.hours(1.5).toString(Locale.GERMAN));
- }
+ /**
+ *
+ * @throws StringValueConversionException
+ */
+ public void testValues() throws StringValueConversionException
+ {
+ Assert.assertEquals(Duration.milliseconds(3000), Duration.seconds(3));
+ Assert.assertEquals(Duration.seconds(120), Duration.minutes(2));
+ Assert.assertEquals(Duration.minutes(1440), Duration.hours(24));
+ Assert.assertEquals(Duration.hours(48), Duration.days(2));
+ Assert.assertEquals(Duration.minutes(90), Duration.valueOf("90 minutes"));
+ Assert.assertEquals(Duration.days(9), Duration.valueOf("9 days"));
+ Assert.assertEquals(Duration.hours(1), Duration.valueOf("1 hour"));
+ Assert.assertTrue(9 == Duration.days(9).days());
+ Assert.assertTrue(11 == Duration.hours(11).hours());
+ Assert.assertTrue(21 == Duration.minutes(21).minutes());
+ Assert.assertTrue(51 == Duration.seconds(51).seconds());
+ }
+
+ /**
+ *
+ *
+ */
+ public void testOperations()
+ {
+ Assert.assertTrue(Duration.milliseconds(3001).greaterThan(Duration.seconds(3)));
+ Assert.assertTrue(Duration.milliseconds(2999).lessThan(Duration.seconds(3)));
+ Assert.assertEquals(-1, Duration.milliseconds(2999).compareTo(Duration.seconds(3)));
+ Assert.assertEquals(1, Duration.milliseconds(3001).compareTo(Duration.seconds(3)));
+ Assert.assertEquals(0, Duration.milliseconds(3000).compareTo(Duration.seconds(3)));
+ Assert.assertEquals(Duration.minutes(10), Duration.minutes(4).add(Duration.minutes(6)));
+ Assert.assertEquals(Duration.ONE_HOUR, Duration.minutes(90).subtract(Duration.minutes(30)));
+
+ String value = NumberFormat.getNumberInstance().format(1.5);
+
+ Assert.assertEquals(value + " minutes", Duration.seconds(90).toString());
+ Assert.assertEquals("12 hours", Duration.days(0.5).toString());
+ }
+
+ /**
+ *
+ *
+ */
+ public void testSleep()
+ {
+ Assert.assertTrue(Duration.seconds(0.5).lessThan(Duration.benchmark(new Runnable()
+ {
+ public void run()
+ {
+ Duration.seconds(1.5).sleep();
+ }
+ })));
+
+ Assert.assertTrue(Duration.seconds(1).greaterThan(Duration.benchmark(new Runnable()
+ {
+ public void run()
+ {
+ Duration.hours(-1).sleep();
+ }
+ })));
+ }
+
+ /**
+ *
+ * @throws StringValueConversionException
+ */
+ public void testLocale() throws StringValueConversionException
+ {
+ Assert.assertEquals(Duration.minutes(90), Duration.valueOf("90 minutes"));
+ Assert.assertEquals(Duration.hours(1.5), Duration.valueOf("1.5 hour", Locale.US));
+ Assert.assertEquals(Duration.hours(1.5), Duration.valueOf("1,5 hour", Locale.GERMAN));
+ Assert.assertEquals("1.5 hours", Duration.hours(1.5).toString(Locale.US));
+ Assert.assertEquals("1,5 hours", Duration.hours(1.5).toString(Locale.GERMAN));
+ }
}
-
-
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeMapTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeMapTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeMapTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeMapTest.java Mon Oct 15 14:21:25 2007
@@ -26,24 +26,30 @@
/**
* Test cases for this object
+ *
* @author Jonathan Locke
*/
public final class TimeMapTest extends TestCase
{
- /**
- *
- * @throws ParseException
- */
- public void testSimpleStaticTimeFrame() throws ParseException
- {
- final TimeMap map = new TimeMap();
- final Time start = Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH), "3.14pm"));
- final Time end = Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH), "3.20pm"));
- final String value = "test";
+ /**
+ *
+ * @throws ParseException
+ */
+ public void testSimpleStaticTimeFrame() throws ParseException
+ {
+ final TimeMap map = new TimeMap();
+ final Time start = Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH),
+ "3.14pm"));
+ final Time end = Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH),
+ "3.20pm"));
+ final String value = "test";
- map.put(TimeFrame.valueOf(start, end), value);
- Assert.assertEquals(value, map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH), "3.15pm"))));
- Assert.assertNull(map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH), "3.21pm"))));
- Assert.assertNull(map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(Locale.ENGLISH), "3.13pm"))));
- }
+ map.put(TimeFrame.valueOf(start, end), value);
+ Assert.assertEquals(value, map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(
+ Locale.ENGLISH), "3.15pm"))));
+ Assert.assertNull(map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(
+ Locale.ENGLISH), "3.21pm"))));
+ Assert.assertNull(map.get(Time.valueOf(TimeOfDay.valueOf(new GregorianCalendar(
+ Locale.ENGLISH), "3.13pm"))));
+ }
}
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeOfDayTest.java Mon Oct 15 14:21:25 2007
@@ -22,23 +22,22 @@
/**
* Test cases for this object
+ *
* @author Jonathan Locke
*/
public final class TimeOfDayTest extends TestCase
{
- /**
- *
- */
- public void test()
- {
- Assert.assertEquals(0, TimeOfDay.MIDNIGHT.hour());
- Assert.assertEquals(TimeOfDay.MIDNIGHT, TimeOfDay.valueOf(TimeOfDay.MIDNIGHT.next()));
+ /**
+ *
+ */
+ public void test()
+ {
+ Assert.assertEquals(0, TimeOfDay.MIDNIGHT.hour());
+ Assert.assertEquals(TimeOfDay.MIDNIGHT, TimeOfDay.valueOf(TimeOfDay.MIDNIGHT.next()));
- final TimeOfDay three = TimeOfDay.time(3, 0, TimeOfDay.PM);
- final TimeOfDay five = TimeOfDay.time(5, 0, TimeOfDay.PM);
+ final TimeOfDay three = TimeOfDay.time(3, 0, TimeOfDay.PM);
+ final TimeOfDay five = TimeOfDay.time(5, 0, TimeOfDay.PM);
- Assert.assertTrue(five.after(three));
- }
+ Assert.assertTrue(five.after(three));
+ }
}
-
-
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTest.java Mon Oct 15 14:21:25 2007
@@ -39,7 +39,7 @@
final Time start = Time.now();
// TODO Post 1.2: Bug: Eelco mentioned this test fails on his computer
- // from time to time. I have seen this and it's very weird -- Jonathan
+ // from time to time. I have seen this and it's very weird -- Jonathan
// Assert.assertTrue(Time.now().after(start) || Time.now().equals(start));
final Time birthday = Time.parseDate("1966.06.01");
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTests.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTests.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTests.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/time/TimeTests.java Mon Oct 15 14:21:25 2007
@@ -24,23 +24,21 @@
*/
public final class TimeTests
{
- /**
- *
- * @return suite
- */
- public static Test suite()
- {
- final TestSuite suite = new TestSuite("Test for org.apache.wicket.util.time");
+ /**
+ *
+ * @return suite
+ */
+ public static Test suite()
+ {
+ final TestSuite suite = new TestSuite("Test for org.apache.wicket.util.time");
- //$JUnit-BEGIN$
- suite.addTest(new TestSuite(TimeTest.class));
- suite.addTest(new TestSuite(DurationTest.class));
- suite.addTest(new TestSuite(TimeOfDayTest.class));
- suite.addTest(new TestSuite(TimeMapTest.class));
+ // $JUnit-BEGIN$
+ suite.addTest(new TestSuite(TimeTest.class));
+ suite.addTest(new TestSuite(DurationTest.class));
+ suite.addTest(new TestSuite(TimeOfDayTest.class));
+ suite.addTest(new TestSuite(TimeMapTest.class));
- //$JUnit-END$
- return suite;
- }
+ // $JUnit-END$
+ return suite;
+ }
}
-
-
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/value/ValueMapTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/value/ValueMapTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/value/ValueMapTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/util/value/ValueMapTest.java Mon Oct 15 14:21:25 2007
@@ -31,7 +31,7 @@
ValueMap vm = new ValueMap("param=value");
assertEquals(1, vm.size());
assertEquals("value", vm.get("param"));
-
+
vm = new ValueMap("param1=value1,param2=value2");
assertEquals(2, vm.size());
@@ -80,7 +80,7 @@
assertEquals(2, vm.size());
assertEquals("value1", vm.get("param1"));
assertEquals("val=ue2", vm.get("param2"));
-
+
vm = new ValueMap("param1=val;ue1;param2=value2", ";");
assertEquals(2, vm.size());
assertEquals("val;ue1", vm.get("param1"));
@@ -96,6 +96,6 @@
assertEquals("va=l;ue1", vm.get("param1"));
assertEquals("val;ue2", vm.get("param2"));
assertEquals("val=ue3", vm.get("param3"));
-
+
}
}
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/EmailValidatorTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/EmailValidatorTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/EmailValidatorTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/EmailValidatorTest.java Mon Oct 15 14:21:25 2007
@@ -20,6 +20,7 @@
/**
* Tests a couple of valid and invalid email patterns.
+ *
* @author Maurice Marrink
*/
public class EmailValidatorTest extends TestCase
@@ -34,6 +35,7 @@
/**
* Constructor.
+ *
* @param name
*/
public EmailValidatorTest(String name)
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java?rev=584925&r1=584924&r2=584925&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/validation/validator/UrlValidatorTest.java Mon Oct 15 14:21:25 2007
@@ -23,259 +23,268 @@
public class UrlValidatorTest extends TestCase
{
- private boolean printStatus = false;
- private boolean printIndex = false;//print index that indicates current scheme,host,port,path, query test were using.
+ private boolean printStatus = false;
+ private boolean printIndex = false;// print index that indicates current scheme,host,port,path,
+
+ // query test were using.
+
+ public static Test suite()
+ {
+ return new TestSuite(UrlValidatorTest.class);
+ }
+
+ protected void setUp()
+ {
+ for (int index = 0; index < testPartsIndex.length - 1; index++)
+ {
+ testPartsIndex[index] = 0;
+ }
+ }
+
+ protected void tearDown()
+ {
+ }
+
+ public void testIsValid()
+ {
+ testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES);
+ setUp();
+ int options = UrlValidator.ALLOW_2_SLASHES + UrlValidator.ALLOW_ALL_SCHEMES +
+ UrlValidator.NO_FRAGMENTS;
+
+ testIsValid(testUrlPartsOptions, options);
+ }
+
+ public void testIsValidScheme()
+ {
+ if (printStatus)
+ {
+ System.out.print("\n testIsValidScheme() ");
+ }
+ String[] schemes = { "http", "gopher" };
+ // UrlValidator urlVal = new UrlValidator(schemes,false,false,false);
+ UrlValidator urlVal = new UrlValidator(schemes, 0);
+ for (int sIndex = 0; sIndex < testScheme.length; sIndex++)
+ {
+ ResultPair testPair = testScheme[sIndex];
+ boolean result = urlVal.isValidScheme(testPair.item);
+ assertEquals(testPair.item, testPair.valid, result);
+ if (printStatus)
+ {
+ if (result == testPair.valid)
+ {
+ System.out.print('.');
+ }
+ else
+ {
+ System.out.print('X');
+ }
+ }
+ }
+ if (printStatus)
+ {
+ System.out.println();
+ }
+
+ }
+
+ /**
+ * Create set of tests by taking the testUrlXXX arrays and running through all possible
+ * permutations of their combinations.
+ *
+ * @param testObjects
+ * Used to create a url.
+ */
+ public void testIsValid(Object[] testObjects, int options)
+ {
+ UrlValidator urlVal = new UrlValidator(null, options);
+ assertTrue(urlVal.isValid("http://www.google.com"));
+ assertTrue(urlVal.isValid("http://www.google.com/"));
+ int statusPerLine = 60;
+ int printed = 0;
+ if (printIndex)
+ {
+ statusPerLine = 6;
+ }
+ do
+ {
+ StringBuffer testBuffer = new StringBuffer();
+ boolean expected = true;
+ for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex)
+ {
+ int index = testPartsIndex[testPartsIndexIndex];
+ ResultPair[] part = (ResultPair[])testObjects[testPartsIndexIndex];
+ testBuffer.append(part[index].item);
+ expected &= part[index].valid;
+ }
+ String url = testBuffer.toString();
+ boolean result = urlVal.isValid(url);
+ assertEquals(url, expected, result);
+ if (printStatus)
+ {
+ if (printIndex)
+ {
+ System.out.print(testPartsIndextoString());
+ }
+ else
+ {
+ if (result == expected)
+ {
+ System.out.print('.');
+ }
+ else
+ {
+ System.out.print('X');
+ }
+ }
+ printed++;
+ if (printed == statusPerLine)
+ {
+ System.out.println();
+ printed = 0;
+ }
+ }
+ }
+ while (incrementTestPartsIndex(testPartsIndex, testObjects));
+ if (printStatus)
+ {
+ System.out.println();
+ }
+ }
+
+ public void testValidator202()
+ {
+ String[] schemes = { "http", "https" };
+ UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS);
+ urlValidator
+ .isValid("http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log");
+ }
+
+ public void testValidator204()
+ {
+ String[] schemes = { "http", "https" };
+ UrlValidator UrlValidator = new UrlValidator(schemes);
+ assertTrue(UrlValidator
+ .isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
+ }
+
+ static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts)
+ {
+ boolean carry = true; // add 1 to lowest order part.
+ boolean maxIndex = true;
+ for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex)
+ {
+ int index = testPartsIndex[testPartsIndexIndex];
+ ResultPair[] part = (ResultPair[])testParts[testPartsIndexIndex];
+ if (carry)
+ {
+ if (index < part.length - 1)
+ {
+ index++;
+ testPartsIndex[testPartsIndexIndex] = index;
+ carry = false;
+ }
+ else
+ {
+ testPartsIndex[testPartsIndexIndex] = 0;
+ carry = true;
+ }
+ }
+ maxIndex &= (index == (part.length - 1));
+ }
+
+
+ return (!maxIndex);
+ }
+
+ private String testPartsIndextoString()
+ {
+ StringBuffer carryMsg = new StringBuffer("{");
+ for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex)
+ {
+ carryMsg.append(testPartsIndex[testPartsIndexIndex]);
+ if (testPartsIndexIndex < testPartsIndex.length - 1)
+ {
+ carryMsg.append(',');
+ }
+ else
+ {
+ carryMsg.append('}');
+ }
+ }
+ return carryMsg.toString();
+
+ }
+
+ public void testValidateUrl()
+ {
+ assertTrue(true);
+ }
+
+ // -------------------- Test data for creating a composite URL
+ /**
+ * The data given below approximates the 4 parts of a URL <scheme>://<authority><path>?<query>
+ * except that the port number
+ * is broken out of authority to increase the number of permutations.
+ * A complete URL is composed of a scheme+authority+port+path+query,
+ * all of which must be individually valid for the entire URL to be considered
+ * valid.
+ */
+ ResultPair[] testUrlScheme = { new ResultPair("http://", true), new ResultPair("ftp://", true),
+ new ResultPair("h3t://", true), new ResultPair("3ht://", false),
+ new ResultPair("http:/", false), new ResultPair("http:", false),
+ new ResultPair("http/", false), new ResultPair("://", false), new ResultPair("", true) };
+
+ ResultPair[] testUrlAuthority = { new ResultPair("www.google.com", true),
+ new ResultPair("go.com", true), new ResultPair("go.au", true),
+ new ResultPair("0.0.0.0", true), new ResultPair("255.255.255.255", true),
+ new ResultPair("256.256.256.256", false), new ResultPair("255.com", true),
+ new ResultPair("1.2.3.4.5", false), new ResultPair("1.2.3.4.", false),
+ new ResultPair("1.2.3", false), new ResultPair(".1.2.3.4", false),
+ new ResultPair("go.a", false), new ResultPair("go.a1a", true),
+ new ResultPair("go.1aa", false), new ResultPair("aaa.", false),
+ new ResultPair(".aaa", false), new ResultPair("aaa", false), new ResultPair("", false) };
+ ResultPair[] testUrlPort = { new ResultPair(":80", true), new ResultPair(":65535", true),
+ new ResultPair(":0", true), new ResultPair("", true), new ResultPair(":-1", false),
+ new ResultPair(":65636", true), new ResultPair(":65a", false) };
+ ResultPair[] testPath = { new ResultPair("/test1", true), new ResultPair("/t123", true),
+ new ResultPair("/$23", true), new ResultPair("/..", false),
+ new ResultPair("/../", false), new ResultPair("/test1/", true),
+ new ResultPair("", true), new ResultPair("/test1/file", true),
+ new ResultPair("/..//file", false), new ResultPair("/test1//file", false) };
+ // Test allow2slash, noFragment
+ ResultPair[] testUrlPathOptions = { new ResultPair("/test1", true),
+ new ResultPair("/t123", true), new ResultPair("/$23", true),
+ new ResultPair("/..", false), new ResultPair("/../", false),
+ new ResultPair("/test1/", true), new ResultPair("/#", false), new ResultPair("", true),
+ new ResultPair("/test1/file", true), new ResultPair("/t123/file", true),
+ new ResultPair("/$23/file", true), new ResultPair("/../file", false),
+ new ResultPair("/..//file", false), new ResultPair("/test1//file", true),
+ new ResultPair("/#/file", false) };
+
+ ResultPair[] testUrlQuery = { new ResultPair("?action=view", true),
+ new ResultPair("?action=edit&mode=up", true), new ResultPair("", true) };
+
+ Object[] testUrlParts = { testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery };
+ Object[] testUrlPartsOptions = { testUrlScheme, testUrlAuthority, testUrlPort,
+ testUrlPathOptions, testUrlQuery };
+ int[] testPartsIndex = { 0, 0, 0, 0, 0 };
+
+ // ---------------- Test data for individual url parts ----------------
+ ResultPair[] testScheme = { new ResultPair("http", true), new ResultPair("ftp", false),
+ new ResultPair("httpd", false), new ResultPair("telnet", false) };
+
+
+ class ResultPair
+ {
+ public String item;
+ public boolean valid;
+
+ public ResultPair(String item, boolean valid)
+ {
+ this.item = item;
+ this.valid = valid; // Weather the individual part of url is valid.
+ }
+ }
- public static Test suite() {
- return new TestSuite(UrlValidatorTest.class);
- }
-
- protected void setUp() {
- for (int index = 0; index < testPartsIndex.length - 1; index++) {
- testPartsIndex[index] = 0;
- }
- }
-
- protected void tearDown() {
- }
-
- public void testIsValid() {
- testIsValid(testUrlParts, UrlValidator.ALLOW_ALL_SCHEMES);
- setUp();
- int options =
- UrlValidator.ALLOW_2_SLASHES
- + UrlValidator.ALLOW_ALL_SCHEMES
- + UrlValidator.NO_FRAGMENTS;
-
- testIsValid(testUrlPartsOptions, options);
- }
-
- public void testIsValidScheme() {
- if (printStatus) {
- System.out.print("\n testIsValidScheme() ");
- }
- String[] schemes = {"http", "gopher"};
- //UrlValidator urlVal = new UrlValidator(schemes,false,false,false);
- UrlValidator urlVal = new UrlValidator(schemes, 0);
- for (int sIndex = 0; sIndex < testScheme.length; sIndex++) {
- ResultPair testPair = testScheme[sIndex];
- boolean result = urlVal.isValidScheme(testPair.item);
- assertEquals(testPair.item, testPair.valid, result);
- if (printStatus) {
- if (result == testPair.valid) {
- System.out.print('.');
- } else {
- System.out.print('X');
- }
- }
- }
- if (printStatus) {
- System.out.println();
- }
-
- }
-
- /**
- * Create set of tests by taking the testUrlXXX arrays and
- * running through all possible permutations of their combinations.
- *
- * @param testObjects Used to create a url.
- */
- public void testIsValid(Object[] testObjects, int options) {
- UrlValidator urlVal = new UrlValidator(null, options);
- assertTrue(urlVal.isValid("http://www.google.com"));
- assertTrue(urlVal.isValid("http://www.google.com/"));
- int statusPerLine = 60;
- int printed = 0;
- if (printIndex) {
- statusPerLine = 6;
- }
- do {
- StringBuffer testBuffer = new StringBuffer();
- boolean expected = true;
- for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
- int index = testPartsIndex[testPartsIndexIndex];
- ResultPair[] part = (ResultPair[]) testObjects[testPartsIndexIndex];
- testBuffer.append(part[index].item);
- expected &= part[index].valid;
- }
- String url = testBuffer.toString();
- boolean result = urlVal.isValid(url);
- assertEquals(url, expected, result);
- if (printStatus) {
- if (printIndex) {
- System.out.print(testPartsIndextoString());
- } else {
- if (result == expected) {
- System.out.print('.');
- } else {
- System.out.print('X');
- }
- }
- printed++;
- if (printed == statusPerLine) {
- System.out.println();
- printed = 0;
- }
- }
- } while (incrementTestPartsIndex(testPartsIndex, testObjects));
- if (printStatus) {
- System.out.println();
- }
- }
-
- public void testValidator202() {
- String[] schemes = {"http","https"};
- UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.NO_FRAGMENTS);
- urlValidator.isValid("http://www.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.logoworks.comwww.log");
- }
-
- public void testValidator204() {
- String[] schemes = {"http","https"};
- UrlValidator UrlValidator = new UrlValidator(schemes);
- assertTrue(UrlValidator.isValid("http://tech.yahoo.com/rc/desktops/102;_ylt=Ao8yevQHlZ4On0O3ZJGXLEQFLZA5"));
- }
-
- static boolean incrementTestPartsIndex(int[] testPartsIndex, Object[] testParts) {
- boolean carry = true; //add 1 to lowest order part.
- boolean maxIndex = true;
- for (int testPartsIndexIndex = testPartsIndex.length - 1; testPartsIndexIndex >= 0; --testPartsIndexIndex) {
- int index = testPartsIndex[testPartsIndexIndex];
- ResultPair[] part = (ResultPair[]) testParts[testPartsIndexIndex];
- if (carry) {
- if (index < part.length - 1) {
- index++;
- testPartsIndex[testPartsIndexIndex] = index;
- carry = false;
- } else {
- testPartsIndex[testPartsIndexIndex] = 0;
- carry = true;
- }
- }
- maxIndex &= (index == (part.length - 1));
- }
-
-
- return (!maxIndex);
- }
-
- private String testPartsIndextoString() {
- StringBuffer carryMsg = new StringBuffer("{");
- for (int testPartsIndexIndex = 0; testPartsIndexIndex < testPartsIndex.length; ++testPartsIndexIndex) {
- carryMsg.append(testPartsIndex[testPartsIndexIndex]);
- if (testPartsIndexIndex < testPartsIndex.length - 1) {
- carryMsg.append(',');
- } else {
- carryMsg.append('}');
- }
- }
- return carryMsg.toString();
-
- }
-
- public void testValidateUrl() {
- assertTrue(true);
- }
-
- //-------------------- Test data for creating a composite URL
- /**
- * The data given below approximates the 4 parts of a URL
- * <scheme>://<authority><path>?<query> except that the port number
- * is broken out of authority to increase the number of permutations.
- * A complete URL is composed of a scheme+authority+port+path+query,
- * all of which must be individually valid for the entire URL to be considered
- * valid.
- */
- ResultPair[] testUrlScheme = {new ResultPair("http://", true),
- new ResultPair("ftp://", true),
- new ResultPair("h3t://", true),
- new ResultPair("3ht://", false),
- new ResultPair("http:/", false),
- new ResultPair("http:", false),
- new ResultPair("http/", false),
- new ResultPair("://", false),
- new ResultPair("", true)};
-
- ResultPair[] testUrlAuthority = {new ResultPair("www.google.com", true),
- new ResultPair("go.com", true),
- new ResultPair("go.au", true),
- new ResultPair("0.0.0.0", true),
- new ResultPair("255.255.255.255", true),
- new ResultPair("256.256.256.256", false),
- new ResultPair("255.com", true),
- new ResultPair("1.2.3.4.5", false),
- new ResultPair("1.2.3.4.", false),
- new ResultPair("1.2.3", false),
- new ResultPair(".1.2.3.4", false),
- new ResultPair("go.a", false),
- new ResultPair("go.a1a", true),
- new ResultPair("go.1aa", false),
- new ResultPair("aaa.", false),
- new ResultPair(".aaa", false),
- new ResultPair("aaa", false),
- new ResultPair("", false)
- };
- ResultPair[] testUrlPort = {new ResultPair(":80", true),
- new ResultPair(":65535", true),
- new ResultPair(":0", true),
- new ResultPair("", true),
- new ResultPair(":-1", false),
- new ResultPair(":65636", true),
- new ResultPair(":65a", false)
- };
- ResultPair[] testPath = {new ResultPair("/test1", true),
- new ResultPair("/t123", true),
- new ResultPair("/$23", true),
- new ResultPair("/..", false),
- new ResultPair("/../", false),
- new ResultPair("/test1/", true),
- new ResultPair("", true),
- new ResultPair("/test1/file", true),
- new ResultPair("/..//file", false),
- new ResultPair("/test1//file", false)
- };
- //Test allow2slash, noFragment
- ResultPair[] testUrlPathOptions = {new ResultPair("/test1", true),
- new ResultPair("/t123", true),
- new ResultPair("/$23", true),
- new ResultPair("/..", false),
- new ResultPair("/../", false),
- new ResultPair("/test1/", true),
- new ResultPair("/#", false),
- new ResultPair("", true),
- new ResultPair("/test1/file", true),
- new ResultPair("/t123/file", true),
- new ResultPair("/$23/file", true),
- new ResultPair("/../file", false),
- new ResultPair("/..//file", false),
- new ResultPair("/test1//file", true),
- new ResultPair("/#/file", false)
- };
-
- ResultPair[] testUrlQuery = {new ResultPair("?action=view", true),
- new ResultPair("?action=edit&mode=up", true),
- new ResultPair("", true)
- };
-
- Object[] testUrlParts = {testUrlScheme, testUrlAuthority, testUrlPort, testPath, testUrlQuery};
- Object[] testUrlPartsOptions = {testUrlScheme, testUrlAuthority, testUrlPort, testUrlPathOptions, testUrlQuery};
- int[] testPartsIndex = {0, 0, 0, 0, 0};
-
- //---------------- Test data for individual url parts ----------------
- ResultPair[] testScheme = {new ResultPair("http", true),
- new ResultPair("ftp", false),
- new ResultPair("httpd", false),
- new ResultPair("telnet", false)};
-
-
- class ResultPair {
- public String item;
- public boolean valid;
-
- public ResultPair(String item, boolean valid) {
- this.item = item;
- this.valid = valid; //Weather the individual part of url is valid.
- }
- }
-
}