@Override
  public void run(String... args) throws Exception {

    repository.deleteAll();

    // save a couple of customers
    repository.save(new Customer("Alice", "Smith"));
    repository.save(new Customer("Bob", "Smith"));

    // fetch all customers
    System.out.println("Customers found with findAll():");
    System.out.println("-------------------------------");
    for (Customer customer : repository.findAll()) {
      System.out.println(customer);
    }
    System.out.println();

    // fetch an individual customer
    System.out.println("Customer found with findByFirstName('Alice'):");
    System.out.println("--------------------------------");
    System.out.println(repository.findByFirstName("Alice"));

    System.out.println("Customers found with findByLastName('Smith'):");
    System.out.println("--------------------------------");
    for (Customer customer : repository.findByLastName("Smith")) {
      System.out.println(customer);
    }
  }
  @Test
  public void findsAllCustomers() throws Exception {

    List<Customer> result = repository.findAll();

    assertThat(result, is(notNullValue()));
    assertFalse(result.isEmpty());
  }
Ejemplo n.º 3
0
  /**
   * Shows the cart. For employees a list of their connected business customers is shown, so they
   * can buy products for them.
   *
   * @param userAccount currently logged in user
   * @param modelMap if logged in user is employee: list of customers
   * @param model if logged in user is employee: current employee
   * @return cart
   */
  @RequestMapping(value = "/cart", method = RequestMethod.GET)
  public String basket(
      @LoggedIn Optional<UserAccount> userAccount, ModelMap modelMap, Model model) {

    for (Role role : userAccount.get().getRoles()) {
      if (role.getName().equals("ROLE_EMPLOYEE")) {
        model.addAttribute("employee", userAccount.get());
        modelMap.addAttribute("customer_list", customerRepository.findAll());
      }
    }

    return "cart";
  }