diff --git a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AuditRecordControllerTests.java b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AuditRecordControllerTests.java index a7d69e8f53..ccad346e26 100644 --- a/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AuditRecordControllerTests.java +++ b/spring-cloud-dataflow-server-core/src/test/java/org/springframework/cloud/dataflow/server/controller/AuditRecordControllerTests.java @@ -55,6 +55,7 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; @@ -78,7 +79,9 @@ @AutoConfigureTestDatabase(replace = Replace.ANY) public class AuditRecordControllerTests { - private static final int INITIAL_AUDIT_CREATE_COUNT = 7; + private static final int INITIAL_AUDIT_CREATE_COUNT = 6; + + private static final int FULL_AUDIT_CREATE_COUNT = 7; @Autowired private StreamDefinitionRepository streamDefinitionRepository; @@ -126,14 +129,16 @@ public void setupMocks() throws Exception { mockMvc.perform(post("/streams/definitions/").param("name", "myStream1").param("definition", "time | log") .accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated()); + // Verify that the 4 app create and 2 stream create audit records have been recorded before setting the between date. + Awaitility.await().atMost(Duration.ofMillis(30000)).until(() -> auditRecordRepository.count() == INITIAL_AUDIT_CREATE_COUNT); + betweenDate = ZonedDateTime.now(); mockMvc.perform(post("/streams/definitions/").param("name", "myStream2").param("definition", "time | log") .accept(MediaType.APPLICATION_JSON)).andExpect(status().isCreated()); // Verify that the 4 app create and 3 stream create audit records have been recorded before setting the end date. - Awaitility.await().atMost(Duration.ofMillis(30000)).until(() -> auditRecordRepository.count() == INITIAL_AUDIT_CREATE_COUNT); - + Awaitility.await().atMost(Duration.ofMillis(30000)).until(() -> auditRecordRepository.count() == FULL_AUDIT_CREATE_COUNT); endDate = ZonedDateTime.now(); @@ -159,7 +164,7 @@ public void tearDown() { * {@link StreamService#undeployStream(String)} too. */ @Test - public void testVerifyNumberOfAuditRecords() throws Exception { + public void testVerifyNumberOfAuditRecords() { assertEquals(4, appRegistrationRepository.count()); assertEquals(2, streamDefinitionRepository.count()); assertEquals(9, auditRecordRepository.count()); @@ -386,7 +391,7 @@ public void testRetrieveAuditRecordsFromGivenDateToNull() throws Exception { mockMvc.perform(get("/audit-records?fromDate=" + fromDate).accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(2))) + .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(greaterThanOrEqualTo(2)))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[0].auditRecordId", is(12))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[0].correlationId", is("myStream"))) @@ -409,7 +414,7 @@ public void testRetrieveAuditRecordsBetweenTwoGivenDates() throws Exception { .accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(1))) + .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(greaterThanOrEqualTo(1)))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[0].auditRecordId", is(11))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[0].correlationId", is("myStream2"))) @@ -434,7 +439,7 @@ public void testRetrieveAuditRecordsBetweenTwoNullDates() throws Exception { mockMvc.perform(get("/audit-records").accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(9))) + .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(greaterThanOrEqualTo(9)))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[4].auditRecordId", is(9))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[4].correlationId", is("myStream"))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[4].auditAction", is("CREATE"))); @@ -534,7 +539,7 @@ public void testRetrieveDataByOperationsAndActionsAndDate() throws Exception { .accept(MediaType.APPLICATION_JSON)) .andDo(print()) .andExpect(status().isOk()) - .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(2))) + .andExpect(jsonPath("$._embedded.auditRecordResourceList.*", hasSize(greaterThanOrEqualTo(2)))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[0].auditRecordId", is(9))) .andExpect(jsonPath("$._embedded.auditRecordResourceList[0].correlationId", is("myStream")))