public CustomersResource() {
    System.out.println("[CustomerResource] Instantiated  " + this);
    Customer customer1 = new Customer();
    customer1.setId(1111);
    customer1.setName("CustomerOne");
    customer1.setAddress("Bombay, India");

    Customer customer2 = new Customer();
    customer2.setId(2222);
    customer2.setName("CustomerTwo");
    customer2.setAddress("Pune, India");

    Customer customer3 = new Customer();
    customer3.setId(3333);
    customer3.setName("CustomerThree");
    customer3.setAddress("Bangalore, India");

    customerMap.put(customer1.getId(), customer1);
    customerMap.put(customer2.getId(), customer2);
    customerMap.put(customer3.getId(), customer3);

    if (testBean != null) {
      System.out.println("[CustomersResource] testBean NOT NULL " + testBean);
      testBean.setCustomerMap(customerMap);
    } else {
      System.out.println("[CustomersResource] testBean IS NULL");
    }
  }
Пример #2
0
  public static void main(String[] args) throws Exception {
    System.out.println("hello from Customer.java");

    EntityManagerFactory factory = Persistence.createEntityManagerFactory("customerPU");
    EntityManager manager = factory.createEntityManager();
    Query q1 = manager.createQuery("SELECT COUNT(c) FROM Customer c");
    Long count = (Long) q1.getSingleResult();
    if (count == 0) {
      // record is empty, read from data.txst
      System.out.println("record empty, read from data.txt...");
      // try {
      FileReader fr = new FileReader("data.txt");
      BufferedReader br = new BufferedReader(fr);
      String s;
      while ((s = br.readLine()) != null) {

        // System.out.println(s);
        // split the string s
        Object[] items = s.split("\\|");
        // store in string list
        // List<String> itemList= new ArrayList<String>(Arrays.asList(items));
        // string list converted to array

        // Object[] itemArray = itemList.toArray();
        // insert data into database table
        manager.getTransaction().begin();
        Customer c = new Customer();

        // add email
        c.setEmail((String) items[0]);

        // add pass
        c.setPass((String) items[1]);

        // add name
        c.setName((String) items[2]);

        // add address
        c.setAddress((String) items[3]);

        // add yob
        c.setYob((String) items[4]);

        // change to managed state
        manager.persist(c);
        manager.getTransaction().commit();
      }
      fr.close();
    }

    // display the records
    Query q2 = manager.createNamedQuery("Customer.findAll");
    List<Customer> customers = q2.getResultList();
    for (Customer c : customers) {
      System.out.println(c.getName() + ", " + c.getEmail());
    }

    manager.close();
    factory.close();
  }
Пример #3
0
  /** This method tests the requirement that the address can not null */
  @Test(expected = IllegalArgumentException.class)
  public void addressShouldNotBeNull() {
    // Customer customer = new Customer();
    instance.setAddress(null);

    // assertNotNull(instance.getAddress());
  }
  /**
   * Test case to show the usage of the geo-spatial APIs to lookup people within a given distance of
   * a reference point.
   */
  @Test
  public void exposesGeoSpatialFunctionality() {

    GeospatialIndex indexDefinition = new GeospatialIndex("address.location");
    indexDefinition.getIndexOptions().put("min", -180);
    indexDefinition.getIndexOptions().put("max", 180);

    operations.indexOps(Customer.class).ensureIndex(indexDefinition);

    Customer ollie = new Customer("Oliver", "Gierke");
    ollie.setAddress(new Address(new Point(52.52548, 13.41477)));
    ollie = repository.save(ollie);

    Point referenceLocation = new Point(52.51790, 13.41239);
    Distance oneKilometer = new Distance(1, Metrics.KILOMETERS);

    GeoResults<Customer> result =
        repository.findByAddressLocationNear(referenceLocation, oneKilometer);

    assertThat(result.getContent(), hasSize(1));

    Distance distanceToFirstStore = result.getContent().get(0).getDistance();
    assertThat(distanceToFirstStore.getMetric(), is(Metrics.KILOMETERS));
    assertThat(distanceToFirstStore.getValue(), closeTo(0.862, 0.001));
  }
  public void register(ActionEvent actionEvent) {
    CustomerDAO cdao = HibernateDAOFactory.instance().getCustomerDAO();

    RequestContext context = RequestContext.getCurrentInstance();
    FacesMessage msg = null;
    boolean loggedIn = false;
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();

    if (cdao.checklemail(email)) {
      Customer cs = new Customer();
      cs.setEmail(email);
      cs.setPass(pass);
      cs.setFullName(fullName);
      cs.setAddress(address);
      cs.setPhone(phone);
      cs.setVip(vip);
      cdao.add(cs);
      loggedIn = true;
      msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Registe succes! Welcome", email);
      String url = "index.xhtml";
      try {
        ec.redirect(url);
      } catch (IOException ex) {

      }
    } else {
      loggedIn = false;
      msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Registe Error", "Invalid credentials");
    }

    FacesContext.getCurrentInstance().addMessage(null, msg);
    context.addCallbackParam("loggedIn", loggedIn);
  }
Пример #6
0
  public static ArrayList<Customer> getAllCustomers() {
    ArrayList<Customer> list = new ArrayList<Customer>();

    DBHelper db = new DBHelper();

    try {
      String queryString = "SELECT * FROM customer";
      ResultSet rs = db.executeQuery(queryString);

      while (rs.next()) {
        Customer customer = new Customer();

        customer.setId(rs.getInt("id"));
        customer.setFirstName(rs.getString("first_name"));
        customer.setLastName(rs.getString("last_name"));
        customer.setPhone(rs.getString("phone"));
        customer.setAddress(rs.getString("address"));
        customer.setZipCode(rs.getInt("zipcode"));
        customer.setCity(rs.getString("city"));
        customer.setEmail(rs.getString("email"));
        customer.setPassword(rs.getString("password"));

        list.add(customer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    db.close();

    return list;
  }
 public void testSetByPositionalXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   customer.setAddress(address);
   xmlContext.setValueByXPath(
       customer, "contact-info/address/street[2]/text()", null, CONTROL_ADDRESS_STREET2);
   assertEquals(CONTROL_ADDRESS_STREET2, address.getStreet2());
 }
 public void testSetNestedTextValueByXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   customer.setAddress(address);
   xmlContext.setValueByXPath(
       customer, "contact-info/address/city/text()", null, CONTROL_ADDRESS_CITY);
   assertEquals(CONTROL_ADDRESS_CITY, customer.getAddress().getCity());
 }
 public void testGetNestedTextValueByInvalidXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   customer.setAddress(address);
   String testValue =
       xmlContext.getValueByXPath(
           customer, "contact-info/address/INVALID/text()", null, String.class);
   assertEquals(null, testValue);
 }
 public void testGetByPositionalInvalidXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   address.setStreet2(CONTROL_ADDRESS_STREET2);
   customer.setAddress(address);
   String testValue =
       xmlContext.getValueByXPath(
           customer, "contact-info/address/street[10]/text()", null, String.class);
   assertEquals(null, testValue);
 }
 public void testGetNestedTextValueByXPath() {
   Customer customer = new Customer();
   Address address = new Address();
   address.setCity(CONTROL_ADDRESS_CITY);
   customer.setAddress(address);
   String testValue =
       xmlContext.getValueByXPath(
           customer, "contact-info/address/city/text()", null, String.class);
   assertEquals(CONTROL_ADDRESS_CITY, testValue);
 }
Пример #12
0
 private static Customer customerUnmarshaller(Node customerNode) {
   Customer customer = new Customer();
   NamedNodeMap customerAttributes = customerNode.getAttributes();
   customer.setFirstName(customerAttributes.item(0).getNodeValue());
   customer.setLastName(customerAttributes.item(1).getNodeValue());
   Node addressNode = customerNode.getFirstChild().getNextSibling();
   customer.setAddress(unmarshallAddress(addressNode));
   Node dataNode = customerNode.getFirstChild().getNextSibling().getNextSibling().getNextSibling();
   customer.setData(unmarshallData(dataNode));
   return customer;
 }
  @Test
  public void startsANewDeliveryOrder() {
    Customer customer = new Customer("Finn", "*****@*****.**", "+1(999)999-2187");
    customer.setAddress(new Address("2187 Jakku Ave.", "Jakku", "CA", "92187"));
    Order expectedResult = new Order(OrderType.FOR_DELIVERY, customer);

    when(mockCustomerRepository.findOne(1L)).thenReturn(customer);

    Order result = orderService.startNewDeliveryOrder(1L);

    assertThat(result, is(equalTo(expectedResult)));
    verify(mockCustomerRepository).findOne(1L);
    verify(mockOrderRepository).save(expectedResult);
  }
Пример #14
0
  public static Customer getCustomer(int customerNumber) {
    Customer barbara = new Customer();
    barbara.setName("Barbara White");
    barbara.setAddress("3400 Richmond Parkway #3423");
    barbara.setCity("Bristol");
    barbara.setState("CT");
    barbara.setPostalCode("06010");

    if (customerNumber == 1001) {
      return barbara;
    }

    Customer karl = new Customer();
    karl.setName("Karl Vang");
    karl.setAddress("327 Franklin Street");
    karl.setCity("Edina");
    karl.setState("MN");
    karl.setPostalCode("55435");

    if (customerNumber == 1002) {
      return karl;
    }

    Customer ronda = new Customer();
    ronda.setName("Ronda Chavan");
    ronda.setAddress("518 Commanche Dr.");
    ronda.setCity("Greensboro");
    ronda.setState("NC");
    ronda.setPostalCode("27410");

    if (customerNumber == 1003) {
      return ronda;
    }

    return null;
  }
  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;
  }
 @POST
 @Path("add")
 @Produces(MediaType.APPLICATION_XML)
 @Consumes("application/x-www-form-urlencoded")
 public Customer addCustomer(
     @FormParam("custId") int id,
     @FormParam("custName") String name,
     @FormParam("custAddress") String address) {
   Customer customer = new Customer();
   customer.setId(id);
   customer.setName(name);
   customer.setAddress(address);
   customerMap.put(customer.getId(), customer);
   testBean.setCustomerMap(customerMap);
   return customer;
 }
Пример #17
0
 public static Customer getCustomer(int id) {
   Customer customer = new Customer();
   DBHelper db = new DBHelper();
   try {
     String queryString = "SELECT * FROM customer WHERE id = " + id;
     ResultSet rs = db.executeQuery(queryString);
     if (rs != null && rs.next()) {
       customer.setId(rs.getInt("id"));
       customer.setFirstName(rs.getString("first_name"));
       customer.setLastName(rs.getString("last_name"));
       customer.setPhone(rs.getString("phone"));
       customer.setAddress(rs.getString("address"));
       customer.setZipCode(rs.getInt("zipcode"));
       customer.setCity(rs.getString("city"));
       customer.setEmail(rs.getString("email"));
       customer.setPassword(rs.getString("password"));
     }
     db.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return customer;
 }
  @Override
  protected Object getControlObject() {
    Customer customer = new Customer();
    customer.setFirstName(CONTROL_FIRST_NAME);
    customer.setLastName(CONTROL_LAST_NAME);
    customer.setSurname(CONTROL_SURNAME);
    customer.getNicknames().add("A");
    customer.getNicknames().add("B");

    Address address = new Address();
    address.setStreet(CONTROL_STREET);
    customer.setAddress(address);

    PhoneNumber phoneNumber1 = new PhoneNumber();
    phoneNumber1.setValue(CONTROL_PHONE_NUMBER_1);
    customer.getPhoneNumbers().add(phoneNumber1);

    PhoneNumber phoneNumber2 = new PhoneNumber();
    phoneNumber2.setValue(CONTROL_PHONE_NUMBER_2);
    customer.getPhoneNumbers().add(phoneNumber2);

    return customer;
  }
Пример #19
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;
  }
Пример #20
0
  public static Customer createCustomerAddress(EntityManagerFactory factory) {
    System.out.println("Create 1st Customer");
    Customer cust = new Customer();
    cust.setFirstName("Bill");
    cust.setLastName("Burke");
    Address address = new Address();
    address.setStreet("Beacon Street");
    address.setCity("Boston");
    address.setState("MA");
    address.setZip("02115");
    cust.setAddress(address);

    EntityManager manager = factory.createEntityManager();
    try {
      manager.getTransaction().begin();
      manager.persist(cust);
      manager.getTransaction().commit();
    } finally {
      manager.close();
    }
    System.out.println("Address was also persisted with auto-generated key: " + address.getId());
    System.out.println("Return detached Customer instance: " + cust.getId());
    return cust;
  }
Пример #21
0
  /** @param args */
  public static void main(String[] args) {

    int i;

    do {

      System.out.println(
          "***************************************************************************");
      System.out.println("1.Create Account");
      System.out.println("2.Deposit Amount");
      System.out.println("3.Show Balance");
      System.out.println("4.WithDraw Amount");
      System.out.println("5.Print Transcation");
      System.out.println(
          "***************************************************************************");
      System.out.println("Enter Choice:");
      Scanner scan = new Scanner(System.in);

      Customer c = new Customer();
      BankServiceImpl bs = new BankServiceImpl();
      Address add = new Address();

      i = scan.nextInt();

      switch (i) {
        case 1:
          System.out.println("Enter First Name:");
          c.setFname(scan.next());

          System.out.println("Enter Last Name:");
          c.setLname(scan.next());

          System.out.println("Enter Street Name:");
          add.setStreet(scan.next());

          System.out.println("Enter City:");
          add.setCity(scan.next());

          c.setAddress(add);

          bs.createAccount(c, 1000);
          break;

        case 2:
          System.out.println("Enter Account number");

          int AccNo = scan.nextInt();

          System.out.println("Enter Amount");

          float bal = scan.nextFloat();

          float bal2 = bs.deposit(AccNo, bal);
          if (bal2 == -1) {
            System.out.println("Invalid Account Number!!");
          }

          System.out.println(bal2);
          break;

        case 3:
          System.out.println("Enter Account");
          int AccNo1 = scan.nextInt();

          float a = bs.showBalance(AccNo1);

          if (a == -1) {
            System.out.println("Invalid Account Number!!");
          }
          System.out.println(a);
          break;

        case 4:
          System.out.println("Enter Account number");

          int AccNo11 = scan.nextInt();
          System.out.println("Enter Amount");
          float bal1 = scan.nextFloat();

          float bal3 = bs.withDraw(AccNo11, bal1);

          if (bal3 == -1) {
            System.out.println("Invalid!!");
          }
          System.out.println(bal3);
          break;

        default:
          System.out.println("Invalid Choice!!!");
      }

    } while (i < 5);
  }
Пример #22
0
 /** This method tests the requirement that the address can not empty */
 @Test(expected = IllegalArgumentException.class)
 public void addressShouldNotBeEmpty() {
   instance.setAddress("");
 }
Пример #23
0
 /** All valid address should pass validation */
 @Test
 public void validAddressShouldPass() {
   instance.setAddress("1234 Anywhere St");
 }
Пример #24
0
 @Override
 public void addAddress(Address address) {
   System.out.println("addAddress_***************************");
   customer.setAddress(address);
 }
  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();
  }