-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
app/src/test/java/com/techcourse/dao/UserHistoryDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.techcourse.dao; | ||
|
||
import com.techcourse.config.DataSourceConfig; | ||
import com.techcourse.domain.User; | ||
import com.techcourse.domain.UserHistory; | ||
import com.techcourse.support.jdbc.init.DatabasePopulatorUtils; | ||
import org.assertj.core.api.SoftAssertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class UserHistoryDaoTest { | ||
|
||
private UserHistoryDao userHistoryDao; | ||
private JdbcTemplate jdbcTemplate; | ||
|
||
@BeforeEach | ||
void setup() { | ||
DatabasePopulatorUtils.execute(DataSourceConfig.getInstance()); | ||
|
||
userHistoryDao = new UserHistoryDao(DataSourceConfig.getInstance()); | ||
jdbcTemplate = new JdbcTemplate(DataSourceConfig.getInstance()); | ||
} | ||
|
||
@Test | ||
void log() { | ||
final User philip = new User(1L, "philip", "jaepil", "[email protected]"); | ||
final UserHistory userHistory = new UserHistory(philip, "sun-shot"); | ||
|
||
userHistoryDao.log(userHistory); | ||
|
||
var selectSql = "select id, user_id, account, password, email, created_at, created_by from user_history where created_by = ?"; | ||
Optional<UserHistory> result = jdbcTemplate.queryForObject(selectSql, | ||
resultSet -> new UserHistory( | ||
resultSet.getLong("id"), | ||
resultSet.getLong("user_id"), | ||
resultSet.getString("account"), | ||
resultSet.getString("password"), | ||
resultSet.getString("email"), | ||
resultSet.getString("created_by") | ||
), | ||
"sun-shot"); | ||
|
||
SoftAssertions.assertSoftly(softly -> { | ||
softly.assertThat(result).isPresent(); | ||
softly.assertThat(result.get().getAccount()).isEqualTo("philip"); | ||
softly.assertThat(result.get().getCreateBy()).isEqualTo("sun-shot"); | ||
}); | ||
} | ||
|
||
} |