Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.config.KafkaListenerEndpointRegistry;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
Expand All @@ -23,6 +22,7 @@
import org.springframework.kafka.test.utils.ContainerTestUtils;
import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
Expand Down Expand Up @@ -66,6 +66,7 @@
* of the module test suite.
*/
@Testcontainers(disabledWithoutDocker = true)
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@SpringBootTest(
classes = AuditWriterServiceApplication.class,
properties = {
Expand Down Expand Up @@ -113,13 +114,17 @@ static void overrideProperties(DynamicPropertyRegistry registry) {
@MockitoBean
private BlockchainWriterService blockchainWriterService;

private final KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry;

AuditEventConsumerKafkaTestcontainersTest(KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry) {
this.kafkaListenerEndpointRegistry = kafkaListenerEndpointRegistry;
}

@BeforeEach
void resetMock() {
reset(blockchainWriterService);
}

@Autowired
private KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry;

// -------------------------------------------------------------------------
// Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import lt.satsyuk.distributed.audit.contracts.auth.AuthTokenResponse;
import lt.satsyuk.distributed.audit.contracts.auth.UserRole;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;
Expand All @@ -22,11 +22,15 @@

@WebFluxTest(controllers = AuthController.class)
@Import(GlobalExceptionHandler.class)
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@WithMockUser
class AuthControllerWebFluxTest {

@Autowired
private WebTestClient webTestClient;
private final WebTestClient webTestClient;

AuthControllerWebFluxTest(WebTestClient webTestClient) {
this.webTestClient = webTestClient;
}

@MockitoBean
private AuthenticationService authenticationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import lt.satsyuk.distributed.audit.command.service.UserLoginCommandService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;
Expand All @@ -20,11 +20,15 @@

@WebFluxTest(controllers = CommandController.class)
@Import(GlobalExceptionHandler.class)
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@WithMockUser(roles = {"USER"})
class CommandControllerWebFluxValidationTest {

@Autowired
private WebTestClient webTestClient;
private final WebTestClient webTestClient;

CommandControllerWebFluxValidationTest(WebTestClient webTestClient) {
this.webTestClient = webTestClient;
}

@MockitoBean
private UserLoginCommandService userLoginCommandService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.TestPropertySource;

import java.util.Map;
Expand All @@ -23,6 +23,7 @@
* is wired successfully from the real application context.
*/
@CommandServiceIntegrationTest
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@TestPropertySource(properties = {
"spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
"spring.kafka.properties.client.id=command-service-it",
Expand All @@ -33,17 +34,20 @@ class KafkaProducerConfigIntegrationTest {
private static final String JSON_SERIALIZER_FQCN =
"org.springframework.kafka.support.serializer.JsonSerializer";

@Autowired
private KafkaTemplate<String, AuditEvent> auditEventKafkaTemplate;

@Autowired
private ProducerFactory<String, AuditEvent> auditEventProducerFactory;

@Autowired
private AuditCommandPublisher auditCommandPublisher;

@Value("${spring.embedded.kafka.brokers}")
private String embeddedKafkaBrokers;
private final KafkaTemplate<String, AuditEvent> auditEventKafkaTemplate;
private final ProducerFactory<String, AuditEvent> auditEventProducerFactory;
private final AuditCommandPublisher auditCommandPublisher;
private final String embeddedKafkaBrokers;

KafkaProducerConfigIntegrationTest(KafkaTemplate<String, AuditEvent> auditEventKafkaTemplate,
ProducerFactory<String, AuditEvent> auditEventProducerFactory,
AuditCommandPublisher auditCommandPublisher,
@Value("${spring.embedded.kafka.brokers}") String embeddedKafkaBrokers) {
this.auditEventKafkaTemplate = auditEventKafkaTemplate;
this.auditEventProducerFactory = auditEventProducerFactory;
this.auditCommandPublisher = auditCommandPublisher;
this.embeddedKafkaBrokers = embeddedKafkaBrokers;
}

@Test
void auditEventKafkaTemplateBeanIsCreated() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
Expand All @@ -27,6 +26,7 @@
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.TestPropertySource;
import org.springframework.context.annotation.Import;

Expand All @@ -36,6 +36,7 @@
import java.util.UUID;

@CommandServiceIntegrationTest
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@TestPropertySource(properties = {
"spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}"
})
Expand All @@ -44,11 +45,14 @@ class UserLoginCommandServiceKafkaIntegrationTest {

private static final String TOPIC = "user.login.events";

@Autowired
private UserLoginCommandService userLoginCommandService;
private final UserLoginCommandService userLoginCommandService;
private final org.springframework.kafka.test.EmbeddedKafkaBroker embeddedKafkaBroker;

@Autowired
private org.springframework.kafka.test.EmbeddedKafkaBroker embeddedKafkaBroker;
UserLoginCommandServiceKafkaIntegrationTest(UserLoginCommandService userLoginCommandService,
org.springframework.kafka.test.EmbeddedKafkaBroker embeddedKafkaBroker) {
this.userLoginCommandService = userLoginCommandService;
this.embeddedKafkaBroker = embeddedKafkaBroker;
}

private Consumer<String, String> consumer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import org.apache.kafka.common.serialization.StringSerializer;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.PostgreSQLContainer;
Expand All @@ -42,6 +42,7 @@
import reactor.core.publisher.Mono;

@SpringBootTest
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@Testcontainers(disabledWithoutDocker = true)
Comment thread
igorsatsyuk marked this conversation as resolved.
@SuppressWarnings({"SqlNoDataSourceInspection", "SqlResolve"})
class EventStoreKafkaToPostgresIntegrationTest {
Expand Down Expand Up @@ -102,11 +103,14 @@ event_hash VARCHAR(64),
}
}

@Autowired
private KafkaTemplate<String, String> kafkaTemplate;
private final KafkaTemplate<String, String> kafkaTemplate;
private final ObjectMapper objectMapper;

@Autowired
private ObjectMapper objectMapper;
EventStoreKafkaToPostgresIntegrationTest(KafkaTemplate<String, String> kafkaTemplate,
ObjectMapper objectMapper) {
this.kafkaTemplate = kafkaTemplate;
this.objectMapper = objectMapper;
}

@Test
void userLoginEventIsPersistedToPostgresFromKafkaTopic() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ public class ReconciliationQuartzJob extends QuartzJobBean {
private ReconciliationProperties reconciliationProperties;

public ReconciliationQuartzJob() {
}

@Autowired
public ReconciliationQuartzJob(ReconciliationReportService reconciliationReportService,
ReconciliationProperties reconciliationProperties) {
this.reconciliationReportService = reconciliationReportService;
this.reconciliationProperties = reconciliationProperties;
// Required for Quartz instantiation paths that construct the job reflectively.
}

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import lt.satsyuk.distributed.audit.query.blockchain.AuditLedgerBlockchainClient;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpHeaders;
import org.springframework.r2dbc.core.DatabaseClient;
import org.springframework.test.context.TestConstructor;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
Expand All @@ -38,13 +38,13 @@
* codes for the various blockchain response/error scenarios.
*/
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL)
@Testcontainers
class IntegrityCheckIntegrationTest {

/** Valid 64-char hex hash used across multiple test cases. */
private static final String HASH_64 = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
@Autowired
JwtService jwtService;
private final JwtService jwtService;

@SuppressWarnings("resource")
@Container
Expand All @@ -71,14 +71,18 @@ static void r2dbcProperties(DynamicPropertyRegistry registry) {
@MockitoBean
AuditLedgerBlockchainClient blockchainClient;

@Autowired
DatabaseClient databaseClient;
private final DatabaseClient databaseClient;

@LocalServerPort
int port;

WebTestClient webTestClient;

IntegrityCheckIntegrationTest(JwtService jwtService, DatabaseClient databaseClient) {
this.jwtService = jwtService;
this.databaseClient = databaseClient;
}

@BeforeEach
void setUp() {
webTestClient = WebTestClient.bindToServer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ private ReconciliationProperties reconciliationProperties() {

@Test
void executeInternalRunsScheduledReconciliation() {
ReconciliationQuartzJob job = new ReconciliationQuartzJob(reconciliationReportService, reconciliationProperties());
ReconciliationQuartzJob job = new ReconciliationQuartzJob();
job.setDependencies(reconciliationReportService, reconciliationProperties());
when(reconciliationReportService.runScheduled()).thenReturn(Mono.just(new ReconciliationReportResponse(
"SCHEDULED",
Instant.parse("2026-05-24T10:00:00Z"),
Expand All @@ -55,7 +56,8 @@ void executeInternalRunsScheduledReconciliation() {

@Test
void executeInternalAllowsEmptyScheduledResponse() {
ReconciliationQuartzJob job = new ReconciliationQuartzJob(reconciliationReportService, reconciliationProperties());
ReconciliationQuartzJob job = new ReconciliationQuartzJob();
job.setDependencies(reconciliationReportService, reconciliationProperties());
when(reconciliationReportService.runScheduled()).thenReturn(Mono.empty());

assertDoesNotThrow(() -> job.executeInternal(jobExecutionContext));
Expand All @@ -64,7 +66,8 @@ void executeInternalAllowsEmptyScheduledResponse() {

@Test
void executeInternalWrapsRuntimeExceptionIntoJobExecutionException() {
ReconciliationQuartzJob job = new ReconciliationQuartzJob(reconciliationReportService, reconciliationProperties());
ReconciliationQuartzJob job = new ReconciliationQuartzJob();
job.setDependencies(reconciliationReportService, reconciliationProperties());
when(reconciliationReportService.runScheduled()).thenReturn(Mono.error(new IllegalStateException("boom")));

assertThrows(JobExecutionException.class, () -> job.executeInternal(jobExecutionContext));
Expand All @@ -73,7 +76,8 @@ void executeInternalWrapsRuntimeExceptionIntoJobExecutionException() {

@Test
void executeInternalSkipsWhenRunAlreadyInProgress() {
ReconciliationQuartzJob job = new ReconciliationQuartzJob(reconciliationReportService, reconciliationProperties());
ReconciliationQuartzJob job = new ReconciliationQuartzJob();
job.setDependencies(reconciliationReportService, reconciliationProperties());
when(reconciliationReportService.runScheduled()).thenReturn(Mono.error(new ReconciliationAlreadyRunningException()));

assertDoesNotThrow(() -> job.executeInternal(jobExecutionContext));
Expand Down