Auto-create account in both MySQL and PG
This commit is contained in:
@@ -9,6 +9,7 @@ import database.PgDatabaseConfig;
|
||||
import database.PgDatabaseConnection;
|
||||
import database.migration.FlywayRunner;
|
||||
import database.monsterbook.MonsterCardRepository;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
@@ -120,10 +121,12 @@ class CharacterSaverTest {
|
||||
SELECT level
|
||||
FROM chr
|
||||
WHERE id = :id""";
|
||||
return pgConnection.getHandle().createQuery(sql)
|
||||
.bind("id", chrId)
|
||||
.mapTo(Integer.class)
|
||||
.one();
|
||||
try (Handle handle = pgConnection.getHandle()) {
|
||||
return handle.createQuery(sql)
|
||||
.bind("id", chrId)
|
||||
.mapTo(Integer.class)
|
||||
.one();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package testutil;
|
||||
|
||||
import client.CharacterStats;
|
||||
import database.PgDatabaseConnection;
|
||||
import database.account.Account;
|
||||
import database.account.AccountRepository;
|
||||
import database.character.CharacterRepository;
|
||||
import org.jdbi.v3.core.Handle;
|
||||
|
||||
@@ -10,24 +12,20 @@ import java.time.LocalDate;
|
||||
public class TestData {
|
||||
|
||||
public static GeneratedIds create(PgDatabaseConnection connection) {
|
||||
int accountId = insertAccount(connection);
|
||||
try (Handle handle = connection.getHandle()) {
|
||||
int accountId = insertAccount(handle);
|
||||
int chrId = insertChr(handle, accountId);
|
||||
return new GeneratedIds(accountId, chrId);
|
||||
}
|
||||
}
|
||||
|
||||
private static int insertAccount(Handle handle) {
|
||||
String sql = """
|
||||
INSERT INTO account (name, password, birthday)
|
||||
VALUES (:name, :password, :birthday)""";
|
||||
return handle.createUpdate(sql)
|
||||
.bind("name", "accountname")
|
||||
.bind("password", "accountpassword")
|
||||
.bind("birthday", LocalDate.of(2005, 5, 11))
|
||||
.executeAndReturnGeneratedKeys()
|
||||
.mapTo(Integer.class)
|
||||
.one();
|
||||
private static int insertAccount(PgDatabaseConnection connection) {
|
||||
Account account = Account.builder()
|
||||
.name("accountname")
|
||||
.password("accountpassword")
|
||||
.birthdate(LocalDate.now())
|
||||
.build();
|
||||
return new AccountRepository(connection).insert(account);
|
||||
}
|
||||
|
||||
private static int insertChr(Handle handle, int accountId) {
|
||||
|
||||
Reference in New Issue
Block a user