Skip to content

Commit

Permalink
fixed non-idempotent tests (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiyaok2 authored May 17, 2024
1 parent afa7885 commit 11ae0ea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
26 changes: 16 additions & 10 deletions docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class TestAppResource extends BaseJerseyTest {
/**
* Test the API resource.
*/

private static boolean configInboxChanged = false;

@Test
public void testAppResource() {
// Login admin
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 11ae0ea

Please sign in to comment.