test(config): tighten audit assertions + @DirtiesContext on ApplicationConfigControllerIT

- Add @DirtiesContext(AFTER_CLASS) so the SpyBean-forked context is torn
  down after the 6 tests finish, preventing permanent cache pollution
- Replace single-row queryForObject with queryForList + hasSize(1) in both
  audit tests so spurious extra rows will fail explicitly
- Assert auditCount == 0 in the 400 test to lock in the no-audit-on-bad-input invariant

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hsiegeln
2026-04-22 22:18:44 +02:00
parent e716dbf8ca
commit 76352c0d6f

View File

@@ -16,7 +16,10 @@ import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import java.util.List;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
@@ -25,6 +28,7 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
class ApplicationConfigControllerIT extends AbstractPostgresIT {
/**
@@ -158,6 +162,10 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
void putConfig_unknownApplyValue_returns400() {
ResponseEntity<String> response = putConfig("BOGUS");
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
int auditCount = jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM audit_log WHERE target = ?", Integer.class, appSlug);
assertThat(auditCount).isZero();
}
@Test
@@ -168,10 +176,11 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String action = jdbcTemplate.queryForObject(
"SELECT action FROM audit_log WHERE target = ? ORDER BY timestamp DESC LIMIT 1",
List<String> actions = jdbcTemplate.queryForList(
"SELECT action FROM audit_log WHERE target = ? ORDER BY timestamp DESC",
String.class, appSlug);
assertThat(action).isEqualTo("stage_app_config");
assertThat(actions).hasSize(1);
assertThat(actions.get(0)).isEqualTo("stage_app_config");
}
@Test
@@ -182,9 +191,10 @@ class ApplicationConfigControllerIT extends AbstractPostgresIT {
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
String action = jdbcTemplate.queryForObject(
"SELECT action FROM audit_log WHERE target = ? ORDER BY timestamp DESC LIMIT 1",
List<String> actions = jdbcTemplate.queryForList(
"SELECT action FROM audit_log WHERE target = ? ORDER BY timestamp DESC",
String.class, appSlug);
assertThat(action).isEqualTo("update_app_config");
assertThat(actions).hasSize(1);
assertThat(actions.get(0)).isEqualTo("update_app_config");
}
}