Пример #1
0
 private static String generateKey(final int size) {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < size; i++) {
     int idx = rand.nextInt(ALPHANUMERIC.length());
     sb.append(ALPHANUMERIC.substring(idx, idx + 1));
   }
   return (sb.toString());
 }
Пример #2
0
 public static Shipment randomShipment() {
   Shipment s = create(Shipment.class);
   s.setExternalReferenceId(generateKey(7));
   s.setFromAddress(randomAddress());
   s.setToAddress(randomAddress());
   s.setShippingServiceName(randomShippingService().getName());
   for (int i = 0; i < rand.nextInt(5) + 1; i++) {
     Parcel p = create(Parcel.class);
     p.setShipmentId(rand.nextInt(5000));
     p.setContents(randomize(CONTENTS));
     p.setWidth(rand.nextInt(5) + 1);
     p.setHeight(rand.nextInt(5) + 1);
     p.setLength(rand.nextInt(5) + 1);
     p.setWeight(rand.nextInt(5) + 1);
     p.setParcelStatus(randomEnum(ParcelStatus.values()));
     s.getParcels().add(p);
   }
   return (s);
 }
Пример #3
0
 public static Address randomAddress() {
   Address a = create(Address.class);
   a.setAddressee(randomize(ADDRESSEE));
   if (rand.nextBoolean()) {
     a.setAddressLine1(randomize(ADDRESS));
     a.setAddressLine2("");
   } else {
     a.setAddressLine1("");
     a.setAddressLine2(randomize(ADDRESS));
   }
   a.setCity(randomize(CITY));
   a.setPostalCode(generateKey(5));
   a.setState(randomize(STATE));
   return (a);
 }
Пример #4
0
 public static <T extends BaseEntity> T create(Class<T> baseEntityClass) {
   T obj = null;
   try {
     obj = baseEntityClass.newInstance();
   } catch (Exception e) {
     logger.log(Level.SEVERE, "Instantiating " + baseEntityClass.getName(), e);
     return (null);
   }
   obj.setId(rand.nextInt(5000));
   Calendar cal = Calendar.getInstance();
   cal.setTime(new Date());
   obj.setCreatedDate(cal);
   obj.setModifiedDate(cal);
   return (obj);
 }
Пример #5
0
 private static <T extends Enum> T randomEnum(T[] values) {
   return (values[rand.nextInt(values.length)]);
 }
Пример #6
0
 private static String randomize(final String[] vals) {
   return (vals[rand.nextInt(vals.length)]);
 }