コード例 #1
0
  /** Testing registration of new EmployeeEntity to Data Base */
  @Test
  public void testAdd() {
    // creating new server entity
    ServerEntity entity = new ServerEntity();
    ServerState serverState = ServerState.FAIL;
    String serverStateString = ServerState.getStringFromEnum(serverState);
    entity.setServer_name("Test_Server");
    entity.setAddress("255.255.255.0");
    entity.setPort(8080);
    entity.setUrl("http://localhost/");
    entity.setState(serverState);
    entity.setResponse(serverStateString);
    entity.setCreated(timestamp);
    entity.setLastCheck(timestamp);
    entity.setActive(1);
    serverDao.addServer(entity);

    // selecting by login & asserting
    ServerEntity entity2 = serverDao.findByServerName("Test_Server");
    assertNotNull("failure - Server entity2 must not be null", entity2);
    assertEquals("failure - address should be same", "255.255.255.0", entity2.getAddress());
    assertEquals("failure - port should be same", (Object) 8080, entity2.getPort());
    assertEquals("failure - url should be same", "http://localhost/", entity2.getUrl());
    assertEquals("failure - state should be same", serverState, entity2.getState());
    assertEquals("failure - state should be same", serverStateString, entity2.getResponse());
    assertEquals("failure - isActive should be same", (Object) 1, entity2.getActive());
  }
コード例 #2
0
  /** Testing update of existing ServerEntity in Data Base */
  @Test
  public void testUpdate() {
    ServerEntity entity = new ServerEntity();
    ServerState serverState = ServerState.OK;
    String serverStateString = ServerState.getStringFromEnum(serverState);
    entity.setServer_name("Test_Server");
    entity.setAddress("255.255.255.0");
    entity.setPort(8080);
    entity.setUrl("http://localhost/");
    entity.setState(serverState);
    entity.setResponse(serverStateString);
    entity.setCreated(timestamp);
    entity.setLastCheck(timestamp);
    entity.setActive(1);
    entity.setResponsible(null);
    serverDao.addServer(entity);

    // selecting existent entity
    ServerEntity entity2 = serverDao.findByServerName("Test_Server");
    entity2.setAddress("255.255.255.10");
    entity2.setPort(9090);
    entity2.setActive(0);
    serverDao.updateServer(entity2);

    // selection and asserting
    ServerEntity entity3 = serverDao.findByServerName("Test_Server");
    assertNotNull("failure - Employee entity2 must not be null", entity3);

    // asserting
    assertNotNull("failure - Server entity must not be null", entity3);
    assertEquals("failure - address should be same", "255.255.255.10", entity3.getAddress());
    assertEquals("failure - port should be same", (Object) 9090, entity3.getPort());
    assertEquals("failure - isActive should be same", (Object) 0, entity3.getActive());
  }