После следования приведенным примерам была предпринята попытка создать свой собственный тест junit, однако эта штука продолжает ловить код assertTrue(rs.next());
, который я пытаюсь проверить
public void insertEmployee(Employees emp) {
Connection conn = null;
PreparedStatement ps = null;
final String SQL = "INSERT INTO " + '"' + "Remburstment"+ '"' + ".employee values(?,?,?,?,?,?,?,?)";
try {
conn = ConnectionFactory.getConnection();
ps = conn.prepareStatement(SQL);
ps.setString(1, emp.getEmail());
ps.setString(2, emp.getPassword());
ps.setString(3, emp.getFirstName());
ps.setString(4, emp.getLastName());
ps.setBoolean(5, emp.getIsAManager());
ps.setString(6, emp.getMyManagerEmail());
ps.setString(7, emp.getMyManagerFirstName());
ps.setString(8, emp.getMyManagerLastName());
ps.execute();
}catch(SQLException e) {
e.printStackTrace();
}finally {
ConnectionClosers.closeConnection(conn);
ConnectionClosers.closeStatement(ps);
}
LOGGY.debug("The EmployeeRepository insertEmployee was successfully called, and it created: " + emp);
}
Тест Junit
@Test
public void TestInsertEmployee()
{
Connection conn= null;
try
{
conn = ConnectionFactory.getConnection();
try(Statement stCheck=conn.createStatement())
{
conn.setAutoCommit(false);
// Initial cleanup:
stCheck.executeUpdate("DELETE FROM " +'"' + "Remburstment"+ '"' + ".manager");
stCheck.executeUpdate("DELETE FROM " + '"' + "Remburstment"+ '"' + ".employee");
// Setting input parameters
String userName = "employee";
String Password = "password1";
String firstName = "bob";
String lastName = "Kelco";
String myManagerEmail = "manger";
String myManagerFirstName = "Robert";
String myManagerLastName= "Cox";
Boolean isAManager = false;
// Do the call:
Manager manguy = new Manager(myManagerEmail, Password, myManagerFirstName, myManagerLastName );
Employees guy = new Employees(myManagerEmail, Password, myManagerFirstName, myManagerLastName, true, myManagerEmail, myManagerFirstName, myManagerLastName);
Employees emp = new Employees(userName, Password, firstName, lastName,isAManager, myManagerEmail, myManagerFirstName, myManagerLastName );
empRepository.insertManager(guy);
empRepository.insertEmployee(guy);
empRepository.insertEmployee(emp);
// Javabean Checks: Check the javabean contains the expected values:
assertEquals(userName, emp.getEmail());
assertEquals(firstName, emp.getFirstName());
assertEquals(Password, emp.getPassword());
assertEquals(lastName, emp.getLastName());
assertEquals(isAManager, emp.getIsAManager());
assertEquals(myManagerEmail, emp.getMyManagerEmail());
assertEquals(myManagerFirstName, emp.getMyManagerFirstName());
assertEquals(myManagerLastName, emp.getMyManagerLastName());
// Database Checks:
// Check the Person table contains one row with the expected values:
try(ResultSet rs=stCheck.executeQuery("SELECT * FROM " + '"' + "Remburstment"+ '"' + ".employee "))
{
//System.out.println(rs.getString(1));
// assertTrue(rs.next());
rs.next();
System.out.println(rs);
assertEquals(userName, rs.getString(1));
assertEquals(firstName, emp.getFirstName());
assertEquals(Password, emp.getPassword());
assertEquals(lastName, emp.getLastName());
assertEquals(isAManager, emp.getIsAManager());
assertEquals(myManagerEmail, emp.getMyManagerEmail());
assertEquals(myManagerFirstName, emp.getMyManagerFirstName());
assertEquals(myManagerLastName, emp.getMyManagerLastName());
assertFalse(rs.next());
}
// Check the Contractor table contains one row with the expected values:
System.out.println(userName);
try(ResultSet rs=stCheck.executeQuery("SELECT * FROM " + '"' + "Remburstment"+ '"' + ".employee WHERE userName ="+ userName ))
{
assertTrue(rs.next());
System.out.println(rs.getString(1));
assertEquals(userName, rs.getString(1));
assertEquals(firstName, emp.getFirstName());
assertEquals(Password, emp.getPassword());
assertEquals(lastName, emp.getLastName());
assertEquals(isAManager, emp.getIsAManager());
assertEquals(myManagerEmail, emp.getMyManagerEmail());
assertEquals(myManagerFirstName, emp.getMyManagerFirstName());
assertEquals(myManagerLastName, emp.getMyManagerLastName());
assertFalse(rs.next());
}
}
finally
{
// Undo the testing operations:
conn.rollback();
}
}
catch (SQLException e)
{
fail(e.toString());
}
}