You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TestDataGenerator.java 3.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package com.vaadin.tests.util;
  2. import java.math.BigDecimal;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.EnumSet;
  6. import java.util.Locale;
  7. import java.util.Random;
  8. import java.util.TimeZone;
  9. public class TestDataGenerator {
  10. final static String[] fnames = { "Peter", "Alice", "Joshua", "Mike",
  11. "Olivia", "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik",
  12. "Rene", "Lisa", "Marge" };
  13. final static String[] lnames = { "Smith", "Gordon", "Simpson", "Brown",
  14. "Clavel", "Simons", "Verne", "Scott", "Allison", "Gates", "Rowling",
  15. "Barks", "Ross", "Schneider", "Tate" };
  16. final static String cities[] = { "Amsterdam", "Berlin", "Helsinki",
  17. "Hong Kong", "London", "Luxemburg", "New York", "Oslo", "Paris",
  18. "Rome", "Stockholm", "Tokyo", "Turku" };
  19. final static String streets[] = { "4215 Blandit Av.", "452-8121 Sem Ave",
  20. "279-4475 Tellus Road", "4062 Libero. Av.", "7081 Pede. Ave",
  21. "6800 Aliquet St.", "P.O. Box 298, 9401 Mauris St.",
  22. "161-7279 Augue Ave", "P.O. Box 496, 1390 Sagittis. Rd.",
  23. "448-8295 Mi Avenue", "6419 Non Av.", "659-2538 Elementum Street",
  24. "2205 Quis St.", "252-5213 Tincidunt St.",
  25. "P.O. Box 175, 4049 Adipiscing Rd.", "3217 Nam Ave",
  26. "P.O. Box 859, 7661 Auctor St.", "2873 Nonummy Av.",
  27. "7342 Mi, Avenue", "539-3914 Dignissim. Rd.",
  28. "539-3675 Magna Avenue", "Ap #357-5640 Pharetra Avenue",
  29. "416-2983 Posuere Rd.", "141-1287 Adipiscing Avenue",
  30. "Ap #781-3145 Gravida St.", "6897 Suscipit Rd.",
  31. "8336 Purus Avenue", "2603 Bibendum. Av.", "2870 Vestibulum St.",
  32. "Ap #722 Aenean Avenue", "446-968 Augue Ave",
  33. "1141 Ultricies Street", "Ap #992-5769 Nunc Street",
  34. "6690 Porttitor Avenue", "Ap #105-1700 Risus Street",
  35. "P.O. Box 532, 3225 Lacus. Avenue", "736 Metus Street",
  36. "414-1417 Fringilla Street", "Ap #183-928 Scelerisque Road",
  37. "561-9262 Iaculis Avenue" };
  38. public static String getStreetAddress(Random r) {
  39. return streets[r.nextInt(streets.length)];
  40. }
  41. public static Integer getPostalCode(Random r) {
  42. int n = r.nextInt(100000);
  43. if (n < 10000) {
  44. n += 10000;
  45. }
  46. return n;
  47. }
  48. public static String getPhoneNumber(Random r) {
  49. return "+358 02 555 " + r.nextInt(10) + r.nextInt(10) + r.nextInt(10)
  50. + r.nextInt(10);
  51. }
  52. public static String getCity(Random r) {
  53. return cities[r.nextInt(cities.length)];
  54. }
  55. public static String getLastName(Random r) {
  56. return lnames[r.nextInt(lnames.length)];
  57. }
  58. public static String getFirstName(Random r) {
  59. return fnames[r.nextInt(fnames.length)];
  60. }
  61. public static int getAge(Random r) {
  62. return r.nextInt(100) + 10;
  63. }
  64. public static Date getBirthDate(Random r) {
  65. Calendar c = Calendar.getInstance(TimeZone.getTimeZone("EET"),
  66. new Locale("FI", "fi"));
  67. c.setLenient(true);
  68. c.setTimeInMillis(0);
  69. c.set(Calendar.YEAR, r.nextInt(100) + 1900);
  70. c.set(Calendar.MONTH, r.nextInt(12));
  71. c.set(Calendar.DAY_OF_MONTH, r.nextInt(31));
  72. c.set(Calendar.HOUR_OF_DAY, 11);
  73. c.set(Calendar.HOUR, 11);
  74. c.set(Calendar.AM_PM, Calendar.AM);
  75. return c.getTime();
  76. }
  77. public static BigDecimal getSalary(Random r) {
  78. return new BigDecimal(r.nextInt(80000));
  79. }
  80. public static <T extends Enum<T>> T getEnum(Class<T> class1, Random r) {
  81. EnumSet<T> foo = EnumSet.allOf(class1);
  82. return (T) foo.toArray()[r.nextInt(foo.size() - 1)];
  83. }
  84. }