From 11ae0ea7d3a17788dca6225c4ccc05d80910e0eb Mon Sep 17 00:00:00 2001 From: Kaiyao Ke <47203510+kaiyaok2@users.noreply.github.com> Date: Fri, 17 May 2024 08:37:43 -0500 Subject: [PATCH] fixed non-idempotent tests (#757) --- .../sismics/docs/core/dao/jpa/TestJpa.java | 4 +++ .../sismics/docs/rest/TestAppResource.java | 26 ++++++++++++------- .../sismics/docs/rest/TestUserResource.java | 6 +++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/docs-core/src/test/java/com/sismics/docs/core/dao/jpa/TestJpa.java b/docs-core/src/test/java/com/sismics/docs/core/dao/jpa/TestJpa.java index 04c41b324..fa979ab36 100644 --- a/docs-core/src/test/java/com/sismics/docs/core/dao/jpa/TestJpa.java +++ b/docs-core/src/test/java/com/sismics/docs/core/dao/jpa/TestJpa.java @@ -29,5 +29,9 @@ public void testJpa() throws Exception { // Authenticate using the database Assert.assertNotNull(new InternalAuthenticationHandler().authenticate("testJpa", "12345678")); + + // Delete the created user + userDao.delete("testJpa", user.getId()); + TransactionUtil.commit(); } } diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java index bd9eea44e..6b6a57fc1 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java @@ -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 void testInbox() { 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 void testInbox() { .param("folder", "INBOX") .param("tag", tagInboxId) ), JsonObject.class); + configInboxChanged = true; // Get inbox configuration json = target().path("/app/config_inbox").request() diff --git a/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java b/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java index 7dcae5d20..74c3a0619 100644 --- a/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java +++ b/docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java @@ -411,6 +411,12 @@ public void testTotp() { .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