Esempio n. 1
0
  @Test
  public void testUpdate() {

    String id = UUID.randomUUID().toString();
    PlayerDAO dao = new PlayerDAO();

    Player p = new Player();
    p.setId(id);
    p.setFirstName("Test");
    p.setLastName("Player");
    p.setNflTeam("Testers");
    p.setPosition("QB");
    p.setJerseyNumber(33);
    p.setHeight(80);
    p.setWeight(215);
    p.setBirthdate(new Date());
    p.setCollege("Penn State");

    assertTrue(dao.store(p));

    Player p2 = dao.getById(id);
    assertEquals(215, p2.getWeight());
    assertEquals(id, p2.getId());

    p2.setWeight(200);
    dao.store(p2);

    Player p3 = dao.getById(id);
    assertEquals(200, p3.getWeight());
    assertEquals(id, p3.getId());

    assertTrue(dao.remove(p3));
  }
Esempio n. 2
0
  private Player getPlayer(Element el) {

    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    Player p = new Player();

    try {

      String guid = el.getAttribute("id");
      String firstName = el.getAttribute("name_first");
      String lastName = el.getAttribute("name_last");
      String bdate = el.getAttribute("birthdate");
      String height = el.getAttribute("height");
      String weight = el.getAttribute("weight");
      String college = el.getAttribute("college");
      String position = el.getAttribute("position");
      String jersey = el.getAttribute("jersey_number");

      p.setId(guid);
      p.setFirstName(firstName);
      p.setLastName(lastName);
      p.setCollege(college);
      p.setPosition(position);
      p.setHeight(Integer.parseInt(height));
      p.setWeight(Integer.parseInt(weight));
      p.setBirthdate(formatter.parse(bdate));
      p.setJerseyNumber(Integer.parseInt(jersey));

    } catch (Exception e) {
      e.printStackTrace();
    }

    return p;
  }