@Test
  public void testFindIterate() {

    // insert 1000 customers
    int j = 0;
    for (int i = 0; i < 1000; i++) {
      Customer customer = new Customer();
      customer.setName("Hello" + j++);
      customer.save();
    }

    QueryIterator<Customer> iterate =
        Customer.find
            .query()
            .select("id") // .fetch("contacts", new FetchConfig().lazy(20))
            .findIterate();

    try {

      while (iterate.hasNext()) {
        Customer customer = iterate.next();
        // do something interesting with customer
        // customer.getContacts().size();
        System.out.println("got name " + customer.getId() + " " + customer.getName());
      }

    } finally {
      // close the underlying resources held by the QueryIterator
      // those are:  ResultSet and Connection
      iterate.close();
    }
  }
 private static void processUpdate(String type, String id, String att, String value) {
   if (type == null || type.trim().length() == 0) return;
   if ("Order".equals(type)) {
     PurchaseOrder order = PurchaseOrder.findById(new Long(id));
     if ("paid".equals(att)) {
       Boolean oldValue = order.paid;
       if (oldValue == null) oldValue = Boolean.FALSE;
       order.paid = !oldValue;
       if (oldValue) setCurrentUseCaseName("Order unpaid");
       else setCurrentUseCaseName("Order paid");
     } else if ("customer".equals(att)) {
       if (value == null
           || value.startsWith(
               "- ")) // Do nothing if somehow the "- select a customer -" item was selected
       return;
       Customer customer = Customer.findById(new Long(value));
       order.customer = customer;
       Flash.current().success("The order has been reassigned to customer " + customer.name);
       setCurrentUseCaseName("Order reassigned");
     } else if ("notes".equals(att)) {
       order.notes = value;
       setCurrentUseCaseName("Order notes updated");
     }
     order.save();
   } else if ("Customer".equals(type)) {
     Customer customer = Customer.findById(new Long(id));
     if ("creditLimit".equals(att)) {
       BigDecimal val = NumberFormat.parseMoney(value);
       customer.creditLimit = val;
       setCurrentUseCaseName("Customer credit limit updated");
     }
     customer.save();
   } else if ("LineItem".equals(type)) {
     LineItem lineitem = LineItem.findById(new Long(id));
     if ("quantity".equals(att)) {
       Integer val = NumberFormat.parseNumber(value);
       lineitem.qtyOrdered = val;
       setCurrentUseCaseName("Line Item quantity updated");
     } else if ("unitPrice".equals(att)) {
       BigDecimal val = NumberFormat.parseMoney(value);
       lineitem.productPrice = val;
       setCurrentUseCaseName("Line Item unit price updated");
     } else if ("product".equals(att)) {
       Product product = Product.findById(new Long(value));
       lineitem.product = product;
       setCurrentUseCaseName("Line Item product changed");
     }
     lineitem.save();
   }
 }
  @Test
  public void testMerchantStatusNoMatch() throws HTTPError {
    Map<String, Object> payload = new HashMap<String, Object>();

    payload.put("name", "John Lee Hooker");
    payload.put("phone", "(904) 555-1796");

    Map<String, String> address = new HashMap<String, String>();
    address.put("city", "San Francisco");
    address.put("state", "CA");
    address.put("postal_code", "94103");
    address.put("line1", "965 Mission St");
    address.put("country_code", "US");
    payload.put("address", address);

    payload.put("ssn_last4", "3209");

    Customer merchant = new Customer(payload);
    merchant.save();
    assertEquals("no-match", merchant.merchant_status);
  }
 @Test
 public void testCreateBusinessCustomer() throws HTTPError {
   Map<String, Object> payload = businessCustomerPayload();
   Customer customer = new Customer(payload);
   customer.save();
 }