Migrate PendingAccountsTest to JUnit 5

This commit is contained in:
Chris Eager 2021-03-26 11:02:15 -05:00 committed by Chris Eager
parent bab5e5769b
commit 4c019aef15
1 changed files with 24 additions and 25 deletions

View File

@ -5,39 +5,38 @@
package org.whispersystems.textsecuregcm.tests.storage; package org.whispersystems.textsecuregcm.tests.storage;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import com.opentable.db.postgres.embedded.LiquibasePreparer; import com.opentable.db.postgres.embedded.LiquibasePreparer;
import com.opentable.db.postgres.junit.EmbeddedPostgresRules; import com.opentable.db.postgres.junit5.EmbeddedPostgresExtension;
import com.opentable.db.postgres.junit.PreparedDbRule; import com.opentable.db.postgres.junit5.PreparedDbExtension;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Optional;
import org.jdbi.v3.core.Jdbi; import org.jdbi.v3.core.Jdbi;
import org.junit.Before; import org.junit.jupiter.api.BeforeEach;
import org.junit.Rule; import org.junit.jupiter.api.Test;
import org.junit.Test; import org.junit.jupiter.api.extension.RegisterExtension;
import org.whispersystems.textsecuregcm.auth.StoredVerificationCode; import org.whispersystems.textsecuregcm.auth.StoredVerificationCode;
import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration; import org.whispersystems.textsecuregcm.configuration.CircuitBreakerConfiguration;
import org.whispersystems.textsecuregcm.storage.FaultTolerantDatabase; import org.whispersystems.textsecuregcm.storage.FaultTolerantDatabase;
import org.whispersystems.textsecuregcm.storage.PendingAccounts; import org.whispersystems.textsecuregcm.storage.PendingAccounts;
import java.sql.PreparedStatement; class PendingAccountsTest {
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Optional;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @RegisterExtension
static PreparedDbExtension db = EmbeddedPostgresExtension.preparedDatabase(LiquibasePreparer.forClasspathLocation("accountsdb.xml"));
public class PendingAccountsTest {
@Rule
public PreparedDbRule db = EmbeddedPostgresRules.preparedDatabase(LiquibasePreparer.forClasspathLocation("accountsdb.xml"));
private PendingAccounts pendingAccounts; private PendingAccounts pendingAccounts;
@Before @BeforeEach
public void setupAccountsDao() { void setupAccountsDao() {
this.pendingAccounts = new PendingAccounts(new FaultTolerantDatabase("pending_accounts-test", Jdbi.create(db.getTestDatabase()), new CircuitBreakerConfiguration())); this.pendingAccounts = new PendingAccounts(new FaultTolerantDatabase("pending_accounts-test", Jdbi.create(db.getTestDatabase()), new CircuitBreakerConfiguration()));
} }
@Test @Test
public void testStore() throws SQLException { void testStore() throws SQLException {
pendingAccounts.insert("+14151112222", "1234", 1111, null); pendingAccounts.insert("+14151112222", "1234", 1111, null);
PreparedStatement statement = db.getTestDatabase().getConnection().prepareStatement("SELECT * FROM pending_accounts WHERE number = ?"); PreparedStatement statement = db.getTestDatabase().getConnection().prepareStatement("SELECT * FROM pending_accounts WHERE number = ?");
@ -57,7 +56,7 @@ public class PendingAccountsTest {
} }
@Test @Test
public void testStoreWithPushChallenge() throws SQLException { void testStoreWithPushChallenge() throws SQLException {
pendingAccounts.insert("+14151112222", null, 1111, "112233"); pendingAccounts.insert("+14151112222", null, 1111, "112233");
PreparedStatement statement = db.getTestDatabase().getConnection().prepareStatement("SELECT * FROM pending_accounts WHERE number = ?"); PreparedStatement statement = db.getTestDatabase().getConnection().prepareStatement("SELECT * FROM pending_accounts WHERE number = ?");
@ -77,7 +76,7 @@ public class PendingAccountsTest {
} }
@Test @Test
public void testRetrieve() throws Exception { void testRetrieve() throws Exception {
pendingAccounts.insert("+14151112222", "4321", 2222, null); pendingAccounts.insert("+14151112222", "4321", 2222, null);
pendingAccounts.insert("+14151113333", "1212", 5555, null); pendingAccounts.insert("+14151113333", "1212", 5555, null);
@ -92,7 +91,7 @@ public class PendingAccountsTest {
} }
@Test @Test
public void testRetrieveWithPushChallenge() throws Exception { void testRetrieveWithPushChallenge() throws Exception {
pendingAccounts.insert("+14151112222", "4321", 2222, "bar"); pendingAccounts.insert("+14151112222", "4321", 2222, "bar");
pendingAccounts.insert("+14151113333", "1212", 5555, "bang"); pendingAccounts.insert("+14151113333", "1212", 5555, "bang");
@ -108,7 +107,7 @@ public class PendingAccountsTest {
} }
@Test @Test
public void testOverwrite() throws Exception { void testOverwrite() throws Exception {
pendingAccounts.insert("+14151112222", "4321", 2222, null); pendingAccounts.insert("+14151112222", "4321", 2222, null);
pendingAccounts.insert("+14151112222", "4444", 3333, null); pendingAccounts.insert("+14151112222", "4444", 3333, null);
@ -120,7 +119,7 @@ public class PendingAccountsTest {
} }
@Test @Test
public void testOverwriteWithPushToken() throws Exception { void testOverwriteWithPushToken() throws Exception {
pendingAccounts.insert("+14151112222", "4321", 2222, "bar"); pendingAccounts.insert("+14151112222", "4321", 2222, "bar");
pendingAccounts.insert("+14151112222", "4444", 3333, "bang"); pendingAccounts.insert("+14151112222", "4444", 3333, "bang");
@ -134,7 +133,7 @@ public class PendingAccountsTest {
@Test @Test
public void testVacuum() { void testVacuum() {
pendingAccounts.insert("+14151112222", "4321", 2222, null); pendingAccounts.insert("+14151112222", "4321", 2222, null);
pendingAccounts.insert("+14151112222", "4444", 3333, null); pendingAccounts.insert("+14151112222", "4444", 3333, null);
pendingAccounts.vacuum(); pendingAccounts.vacuum();
@ -147,7 +146,7 @@ public class PendingAccountsTest {
} }
@Test @Test
public void testRemove() { void testRemove() {
pendingAccounts.insert("+14151112222", "4321", 2222, "bar"); pendingAccounts.insert("+14151112222", "4321", 2222, "bar");
pendingAccounts.insert("+14151113333", "1212", 5555, null); pendingAccounts.insert("+14151113333", "1212", 5555, null);