|
|
|
@ -62,6 +62,9 @@ import static org.mockito.Mockito.verify; |
|
|
|
@DaoSqlTest |
|
|
|
public class AuditLogControllerTest extends AbstractControllerTest { |
|
|
|
|
|
|
|
// Small enough to force multiple pages, verifying pagination loop correctness
|
|
|
|
private static final int SMALL_PAGE_SIZE = 5; |
|
|
|
|
|
|
|
private Tenant savedTenant; |
|
|
|
private User tenantAdmin; |
|
|
|
|
|
|
|
@ -113,17 +116,14 @@ public class AuditLogControllerTest extends AbstractControllerTest { |
|
|
|
doPost("/api/device", device, Device.class); |
|
|
|
} |
|
|
|
|
|
|
|
List<AuditLog> loadedAuditLogs = getAuditLogs(5, "/api/audit/logs?"); |
|
|
|
|
|
|
|
Assert.assertEquals(11 + 1, loadedAuditLogs.size()); |
|
|
|
|
|
|
|
loadedAuditLogs = getAuditLogs(5, "/api/audit/logs/customer/" + ModelConstants.NULL_UUID + "?"); |
|
|
|
Awaitility.await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
assertThat(getAuditLogs(SMALL_PAGE_SIZE, "/api/audit/logs?")).hasSize(11 + 1)); |
|
|
|
|
|
|
|
Assert.assertEquals(11 + 1, loadedAuditLogs.size()); |
|
|
|
Awaitility.await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
assertThat(getAuditLogs(SMALL_PAGE_SIZE, "/api/audit/logs/customer/" + ModelConstants.NULL_UUID + "?")).hasSize(11 + 1)); |
|
|
|
|
|
|
|
loadedAuditLogs = getAuditLogs(5, "/api/audit/logs/user/" + tenantAdmin.getId().getId().toString() + "?"); |
|
|
|
|
|
|
|
Assert.assertEquals(11 + 1, loadedAuditLogs.size()); |
|
|
|
Awaitility.await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
assertThat(getAuditLogs(SMALL_PAGE_SIZE, "/api/audit/logs/user/" + tenantAdmin.getId().getId().toString() + "?")).hasSize(11 + 1)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -138,7 +138,7 @@ public class AuditLogControllerTest extends AbstractControllerTest { |
|
|
|
} |
|
|
|
|
|
|
|
int expectedSize = loadedAuditLogsBefore.size() + 3; |
|
|
|
Awaitility.await().atMost(10, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
Awaitility.await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
Assert.assertEquals("Have X audit log before this test + New tenant profiles in the test", |
|
|
|
expectedSize, getAuditLogs(100, "/api/audit/logs?").size())); |
|
|
|
} |
|
|
|
@ -170,9 +170,9 @@ public class AuditLogControllerTest extends AbstractControllerTest { |
|
|
|
savedDevice = doPost("/api/device", savedDevice, Device.class); |
|
|
|
} |
|
|
|
|
|
|
|
List<AuditLog> loadedAuditLogs = getAuditLogs(5, "/api/audit/logs/entity/DEVICE/" + savedDevice.getId().getId() + "?"); |
|
|
|
|
|
|
|
Assert.assertEquals(11 + 1, loadedAuditLogs.size()); |
|
|
|
Device finalSavedDevice = savedDevice; |
|
|
|
Awaitility.await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
assertThat(getAuditLogs(SMALL_PAGE_SIZE, "/api/audit/logs/entity/DEVICE/" + finalSavedDevice.getId().getId() + "?")).hasSize(11 + 1)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
@ -188,9 +188,10 @@ public class AuditLogControllerTest extends AbstractControllerTest { |
|
|
|
tenantProfile.setName(tenantProfile.getName() + "(old)"); |
|
|
|
tenantProfile = doPost("/api/tenantProfile", tenantProfile, TenantProfile.class); |
|
|
|
|
|
|
|
List<AuditLog> loadedAuditLogs = getAuditLogs(5, "/api/audit/logs/entity/" +tenantProfile.getId().getEntityType()+ "/" + tenantProfile.getId().getId() + "?"); |
|
|
|
|
|
|
|
Assert.assertEquals("Audit logs count by Tenant Profile entity", 2, loadedAuditLogs.size()); |
|
|
|
TenantProfile finalTenantProfile = tenantProfile; |
|
|
|
Awaitility.await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> |
|
|
|
assertThat(getAuditLogs(SMALL_PAGE_SIZE, "/api/audit/logs/entity/" + finalTenantProfile.getId().getEntityType() + "/" + finalTenantProfile.getId().getId() + "?")) |
|
|
|
.as("Audit logs count by Tenant Profile entity").hasSize(2)); |
|
|
|
|
|
|
|
//cleanup
|
|
|
|
doDelete("/api/tenantProfile/" + tenantProfile.getId().getId().toString()); |
|
|
|
|