Skip to content

Commit 11ae0ea

Browse files
authored
fixed non-idempotent tests (#757)
1 parent afa7885 commit 11ae0ea

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

docs-core/src/test/java/com/sismics/docs/core/dao/jpa/TestJpa.java

+4
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ public void testJpa() throws Exception {
2929

3030
// Authenticate using the database
3131
Assert.assertNotNull(new InternalAuthenticationHandler().authenticate("testJpa", "12345678"));
32+
33+
// Delete the created user
34+
userDao.delete("testJpa", user.getId());
35+
TransactionUtil.commit();
3236
}
3337
}

docs-web/src/test/java/com/sismics/docs/rest/TestAppResource.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class TestAppResource extends BaseJerseyTest {
3636
/**
3737
* Test the API resource.
3838
*/
39+
40+
private static boolean configInboxChanged = false;
41+
3942
@Test
4043
public void testAppResource() {
4144
// Login admin
@@ -249,17 +252,19 @@ public void testInbox() {
249252
json = target().path("/app/config_inbox").request()
250253
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
251254
.get(JsonObject.class);
252-
Assert.assertFalse(json.getBoolean("enabled"));
253-
Assert.assertEquals("", json.getString("hostname"));
254-
Assert.assertEquals(993, json.getJsonNumber("port").intValue());
255-
Assert.assertEquals("", json.getString("username"));
256-
Assert.assertEquals("", json.getString("password"));
257-
Assert.assertEquals("INBOX", json.getString("folder"));
258-
Assert.assertEquals("", json.getString("tag"));
259255
JsonObject lastSync = json.getJsonObject("last_sync");
260-
Assert.assertTrue(lastSync.isNull("date"));
261-
Assert.assertTrue(lastSync.isNull("error"));
262-
Assert.assertEquals(0, lastSync.getJsonNumber("count").intValue());
256+
if (!configInboxChanged) {
257+
Assert.assertFalse(json.getBoolean("enabled"));
258+
Assert.assertEquals("", json.getString("hostname"));
259+
Assert.assertEquals(993, json.getJsonNumber("port").intValue());
260+
Assert.assertEquals("", json.getString("username"));
261+
Assert.assertEquals("", json.getString("password"));
262+
Assert.assertEquals("INBOX", json.getString("folder"));
263+
Assert.assertEquals("", json.getString("tag"));
264+
Assert.assertTrue(lastSync.isNull("date"));
265+
Assert.assertTrue(lastSync.isNull("error"));
266+
Assert.assertEquals(0, lastSync.getJsonNumber("count").intValue());
267+
}
263268

264269
// Change inbox configuration
265270
target().path("/app/config_inbox").request()
@@ -276,6 +281,7 @@ public void testInbox() {
276281
.param("folder", "INBOX")
277282
.param("tag", tagInboxId)
278283
), JsonObject.class);
284+
configInboxChanged = true;
279285

280286
// Get inbox configuration
281287
json = target().path("/app/config_inbox").request()

docs-web/src/test/java/com/sismics/docs/rest/TestUserResource.java

+6
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ public void testTotp() {
411411
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, totp1Token)
412412
.get(JsonObject.class);
413413
Assert.assertFalse(json.getBoolean("totp_enabled"));
414+
415+
// Delete totp1
416+
response = target().path("/user/totp1").request()
417+
.cookie(TokenBasedSecurityFilter.COOKIE_NAME, adminToken)
418+
.delete();
419+
Assert.assertEquals(200, response.getStatus());
414420
}
415421

416422
@Test

0 commit comments

Comments
 (0)