private Customer buildCustomer() {
    Customer customer = new Customer();

    customer.setFirstName(firstNames[generator.nextInt(firstNames.length - 1)]);
    customer.setMiddleInitial(
        String.valueOf(middleInitial.charAt(generator.nextInt(middleInitial.length() - 1))));
    customer.setLastName(lastNames[generator.nextInt(lastNames.length - 1)]);
    customer.setAddress(
        generator.nextInt(9999) + " " + streets[generator.nextInt(streets.length - 1)]);
    customer.setCity(cities[generator.nextInt(cities.length - 1)]);
    customer.setState(states[generator.nextInt(states.length - 1)]);
    customer.setZip(String.valueOf(generator.nextInt(99999)));

    return customer;
  }
Ejemplo n.º 2
0
  /**
   * Get a customer to put in the database
   *
   * @param id for the customer
   * @param warehouse for the customer
   * @param station for the customer
   * @return customer
   */
  public Customer getCustomer(int id, Warehouse warehouse, Station station) {
    Customer customer = new Customer();

    customer.setCustomerID(id);
    customer.setWarehouseID(warehouse.getWarehouseID());
    customer.setStationID(station.getStationID());
    customer.setFirstName(fnames.get(randInt(0, fnames.size())));
    customer.setMiddleInitial(letters[randInt(0, letters.length)]);
    customer.setLastName(lnames.get(randInt(0, lnames.size())));
    customer.setAddress(randAddress());
    customer.setCity(cities.get(randInt(0, cities.size())));
    customer.setState(states.get(randInt(0, states.size())));
    customer.setZip(zips.get(randInt(0, zips.size())));
    customer.setPhone(randInt(100, 1000) + "-" + randInt(100, 1000) + "-" + randInt(1000, 10000));
    customer.setDateAdded(randDate());
    customer.setDiscount(new BigDecimal(randDouble(minDiscount, maxDiscount)));
    customer.setBalance(new BigDecimal(0));
    customer.setTotalPaid(new BigDecimal(0));
    customer.setNumPayments(0);
    customer.setDeliveriesReceived(0);

    return customer;
  }
  public void testDirtyButNotDirty() throws Exception {
    EntityManager manager = getOrCreateEntityManager();
    manager.getTransaction().begin();
    Employee mark = new Employee();
    mark.setName("Mark");
    mark.setTitle("internal sales");
    mark.setSex('M');
    mark.setAddress("buckhead");
    mark.setZip("30305");
    mark.setCountry("USA");

    Customer joe = new Customer();
    joe.setName("Joe");
    joe.setSex('M');
    joe.setAddress("San Francisco");
    joe.setZip("XXXXX");
    joe.setCountry("USA");
    joe.setComments("Very demanding");
    joe.setSalesperson(mark);

    Person yomomma = new Person();
    yomomma.setName("mum");
    yomomma.setSex('F');

    manager.persist(mark);
    manager.persist(joe);
    manager.persist(yomomma);
    long[] ids = {mark.getId(), joe.getId(), yomomma.getId()};
    manager.getTransaction().commit();

    manager.getTransaction().begin();
    assertEquals(
        manager
            .createQuery("select p.address, p.name from Person p order by p.name")
            .getResultList()
            .size(),
        3);
    assertEquals(
        manager
            .createQuery("select p from Person p where p.class = Customer")
            .getResultList()
            .size(),
        1);
    manager.getTransaction().commit();

    manager.getTransaction().begin();
    List customers =
        manager
            .createQuery("select c from Customer c left join fetch c.salesperson")
            .getResultList();
    for (Iterator iter = customers.iterator(); iter.hasNext(); ) {
      Customer c = (Customer) iter.next();
      assertEquals(c.getSalesperson().getName(), "Mark");
    }
    assertEquals(customers.size(), 1);
    manager.getTransaction().commit();

    manager.getTransaction().begin();
    customers = manager.createQuery("select c from Customer c").getResultList();
    for (Iterator iter = customers.iterator(); iter.hasNext(); ) {
      Customer c = (Customer) iter.next();
      assertEquals(c.getSalesperson().getName(), "Mark");
    }
    assertEquals(customers.size(), 1);
    manager.getTransaction().commit();

    manager.getTransaction().begin();
    mark = manager.find(Employee.class, new Long(ids[0]));
    joe = (Customer) manager.find(Customer.class, new Long(ids[1]));
    yomomma = manager.find(Person.class, new Long(ids[2]));

    mark.setZip("30306");
    assertEquals(
        1,
        manager.createQuery("select p from Person p where p.zip = '30306'").getResultList().size());
    manager.remove(mark);
    manager.remove(joe);
    manager.remove(yomomma);
    assertTrue(manager.createQuery("select p from Person p").getResultList().isEmpty());
    manager.getTransaction().commit();
    manager.close();
  }
Ejemplo n.º 4
0
 @Test
 public void validZipCodeShouldPass() {
   instance.setZip("12345");
 }
Ejemplo n.º 5
0
 /** Zip should not be null */
 @Test(expected = IllegalArgumentException.class)
 public void validZipCodeShouldNotBeNull() {
   instance.setZip(null);
 }