I currently have to test the data that is being processed from a file into the database. Currently I'm using Java to extract the data from the database and compare the data mapped to the table compared with the data coming from the source file. I'm using Cucumber for BDD purposes. An issue I'm running into is check whether all the fields are equal between the fields coming from the source file vs the fields coming from the database table.
Lets say we have a User class in java which maps to a User table in the Database.
I have a cucumber datatable with one record which has columns for all the fields of a User (i.e: first name, last name, username,etc). In the database User Table I have those same fields mapped to columns; first_name, last_name, user_name.
Currently I was comparing the field values from the DataTable vs the fields coming from the database kinda in the form of this:
In the Cucumber data table I have something like this:
| user_name | first_name | last_name |
| bob1 | bob | bob |
I am getting the userEntity object using jdbcTemplate:
String bobUserName = userList.get(1).get(0);
String sql = "SELECT * FROM USER WHERE USER_NAME = ?";
UserEntity userEntity = (UserEntity) jdbcTemplate.queryForObject(sql, new Object[] { bobUserName }, new UserRowMapper());
Then inside the same method I want to check the field values:
assertEquals(userList.get(1).get(0), userEntity.getUserName());
assertEquals(userList.get(1).get(1), userEntity.getFirstName());
assertEquals(userList.get(1).get(2)), userEntity.getLastName());
the issue is when I run the test lets say the 2nd assertEquals [checking the first names] fails, then the test just stops there and doesn't continue. Ideally I'd like it to go through all the assertEquals and then give me all the ones that failed.
Another way was that I create another User instance and fill its properties from the fields in the cucumber DataTable and then just do a simple:
userFromDataTable.equals(userEntity);
but when this is false it doesn't tell me why its false.
Is there any efficient way in Java to compare the fields like in my scenario?