Пример #1
0
  private User createUser() {
    User user = new User();
    user.setId(System.currentTimeMillis());
    user.setUsername("fred");
    user.setFirstName("Fred");
    user.setLastName("Meyer");
    user.setEmail("*****@*****.**");
    user.setPassword("xxXXxx");
    user.setPhone("408-867-5309");
    user.setUserStatus(123);

    return user;
  }
  @Test
  public void testAdd() {
    HibernateDatabaseUserManager userManager = HibernateDatabaseUserManager.getDefault();
    HibernateDatabaseAddressManager addrManager = HibernateDatabaseAddressManager.getDefault();
    HibernateDatabaseArenaManager arenaManager = HibernateDatabaseArenaManager.getDefault();
    HibernateDatabaseGameManager gameManager = HibernateDatabaseGameManager.getDefault();

    addrManager.setupTable();
    arenaManager.setupTable();
    gameManager.setupTable();
    userManager.setupTable();

    Address addr1 = new Address();
    addr1.setStreetAddress("2185 Arch St.");
    addr1.setCity("Ottawa");
    addr1.setPostalOrZipCode("K1G 2H5");
    addr1.setProvinceOrState("Ontario");
    addr1.setCountry("Canada");

    Arena arena1 = new Arena();
    arena1.setArenaName("Cantebury");
    arena1.setAddress(addr1);
    addr1.setArena(arena1);

    Game game1 = new Game();
    game1.setGameDay("Tuesday");
    game1.setGameTime("7:30 PM");

    arena1.addGame(game1);

    Address addr = new Address();
    addr.setStreetAddress("1264 Walkley Rd. ");
    addr.setCity("Ottawa");
    addr.setPostalOrZipCode("K1V 6P9");
    addr.setProvinceOrState("Ontario");
    addr.setCountry("Canada");

    Arena arena = new Arena();
    arena.setArenaName("Jim Durell");

    Game game = new Game();
    game.setGameDay("Monday");
    game.setGameTime("9:30 PM");

    Game game2 = new Game();
    game2.setGameDay("Wednesday");
    game2.setGameTime("10:30 PM");

    Address addr3 = new Address();
    addr3.setStreetAddress("210 Hopewell Ave.");
    addr3.setCity("Ottawa");
    addr3.setPostalOrZipCode("K1S 2Z5");
    addr3.setProvinceOrState("Ontario");
    addr3.setCountry("Canada");

    Arena arena3 = new Arena();
    arena3.setArenaName("Brewer");
    arena3.setAddress(addr3);
    addr3.setArena(arena3);

    Game game3 = new Game();
    game3.setGameDay("Friday");
    game3.setGameTime("10:30 PM");

    arena3.addGame(game3);

    arena.setAddress(addr);
    addr.setArena(arena);

    arena.addGame(game);
    arena.addGame(game2);

    arenaManager.add(arena);
    arenaManager.add(arena1);
    arenaManager.add(arena3);

    User client = new User();
    client.setFirstName("John");
    client.setLastName("Marsh");
    client.setEmailAddress("*****@*****.**");
    client.setPassword(BCrypt.hashpw("password", BCrypt.gensalt()));
    client.setCity("Ottawa");
    client.setCountry("Canada");
    client.setProvinceORstate("Ontario");
    client.setBirthdate(Timestamp.valueOf("1993-07-21 00:00:00"));

    User client2 = new User();
    client2.setFirstName("Dougall");
    client2.setLastName("Percival");
    client2.setEmailAddress("*****@*****.**");
    client2.setPassword(BCrypt.hashpw("password", BCrypt.gensalt()));
    client2.setCity("Ottawa");
    client2.setCountry("Canada");
    client2.setProvinceORstate("Ontario");
    client2.setBirthdate(Timestamp.valueOf("1993-12-21 00:00:00"));
    client2.addGame(game2);

    assertTrue(userManager.add(client));
    assertTrue(userManager.add(client2));

    userManager.update(client2);
    userManager.update(client);
  }