fixed non-idempotent tests (#757)

This commit is contained in:
Kaiyao Ke 2024-05-17 08:37:43 -05:00 committed by GitHub
parent afa78857f9
commit 11ae0ea7d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 10 deletions

View File

@ -29,5 +29,9 @@ public class TestJpa extends BaseTransactionalTest {
// Authenticate using the database
Assert.assertNotNull(new InternalAuthenticationHandler().authenticate("testJpa", "12345678"));
// Delete the created user
userDao.delete("testJpa", user.getId());
TransactionUtil.commit();
}
}

View File

@ -36,6 +36,9 @@ public class TestAppResource extends BaseJerseyTest {
/**
* Test the API resource.
*/
private static boolean configInboxChanged = false;
@Test
public void testAppResource() {
// Login admin
@ -249,17 +252,19 @@ public class TestAppResource extends BaseJerseyTest {
json = target().path("/app/config_inbox").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.get(JsonObject.class);
Assert.assertFalse(json.getBoolean("enabled"));
Assert.assertEquals("", json.getString("hostname"));
Assert.assertEquals(993, json.getJsonNumber("port").intValue());
Assert.assertEquals("", json.getString("username"));
Assert.assertEquals("", json.getString("password"));
Assert.assertEquals("INBOX", json.getString("folder"));
Assert.assertEquals("", json.getString("tag"));
JsonObject lastSync = json.getJsonObject("last_sync");
Assert.assertTrue(lastSync.isNull("date"));
Assert.assertTrue(lastSync.isNull("error"));
Assert.assertEquals(0, lastSync.getJsonNumber("count").intValue());
if (!configInboxChanged) {
Assert.assertFalse(json.getBoolean("enabled"));
Assert.assertEquals("", json.getString("hostname"));
Assert.assertEquals(993, json.getJsonNumber("port").intValue());
Assert.assertEquals("", json.getString("username"));
Assert.assertEquals("", json.getString("password"));
Assert.assertEquals("INBOX", json.getString("folder"));
Assert.assertEquals("", json.getString("tag"));
Assert.assertTrue(lastSync.isNull("date"));
Assert.assertTrue(lastSync.isNull("error"));
Assert.assertEquals(0, lastSync.getJsonNumber("count").intValue());
}
// Change inbox configuration
target().path("/app/config_inbox").request()
@ -276,6 +281,7 @@ public class TestAppResource extends BaseJerseyTest {
.param("folder", "INBOX")
.param("tag", tagInboxId)
), JsonObject.class);
configInboxChanged = true;
// Get inbox configuration
json = target().path("/app/config_inbox").request()

View File

@ -411,6 +411,12 @@ public class TestUserResource extends BaseJerseyTest {
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, totp1Token)
.get(JsonObject.class);
Assert.assertFalse(json.getBoolean("totp_enabled"));
// Delete totp1
response = target().path("/user/totp1").request()
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
.delete();
Assert.assertEquals(200, response.getStatus());
}
@Test