From dbdf466d4e15aa8398e9ed573b3d0ec556a21342 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Sat, 24 Aug 2024 07:18:52 +0100 Subject: [PATCH 1/7] BAEL-7262: renamed package to lower case --- .../controller/UserController.java | 6 +++--- .../{switchIfEmpty => switchifempty}/model/User.java | 2 +- .../service/UserService.java | 4 ++-- .../controller/UserControllerTest.java | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchIfEmpty => switchifempty}/controller/UserController.java (86%) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchIfEmpty => switchifempty}/model/User.java (93%) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchIfEmpty => switchifempty}/service/UserService.java (95%) rename spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/{switchIfEmpty => switchifempty}/controller/UserControllerTest.java (97%) diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/controller/UserController.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/controller/UserController.java similarity index 86% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/controller/UserController.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/controller/UserController.java index 1c56f1203644..5fe40f93b1e4 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/controller/UserController.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/controller/UserController.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfEmpty.controller; +package com.baeldung.switchifempty.controller; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.switchIfEmpty.model.User; -import com.baeldung.switchIfEmpty.service.UserService; +import com.baeldung.switchifempty.model.User; +import com.baeldung.switchifempty.service.UserService; import reactor.core.publisher.Mono; diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/model/User.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/model/User.java similarity index 93% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/model/User.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/model/User.java index 589099144e39..5e60e7da60b1 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/model/User.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/model/User.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfEmpty.model; +package com.baeldung.switchifempty.model; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/service/UserService.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/service/UserService.java similarity index 95% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/service/UserService.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/service/UserService.java index 47c4b9b35d94..cd07e66250e7 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/service/UserService.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/service/UserService.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfEmpty.service; +package com.baeldung.switchifempty.service; import java.io.File; import java.io.IOException; @@ -12,7 +12,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import com.baeldung.switchIfEmpty.model.User; +import com.baeldung.switchifempty.model.User; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfEmpty/controller/UserControllerTest.java b/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchifempty/controller/UserControllerTest.java similarity index 97% rename from spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfEmpty/controller/UserControllerTest.java rename to spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchifempty/controller/UserControllerTest.java index 72c57d8b1a4c..baddd4a2810e 100644 --- a/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfEmpty/controller/UserControllerTest.java +++ b/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchifempty/controller/UserControllerTest.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfEmpty.controller; +package com.baeldung.switchifempty.controller; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -12,8 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.reactive.server.WebTestClient; -import com.baeldung.switchIfEmpty.model.User; -import com.baeldung.switchIfEmpty.service.UserService; +import com.baeldung.switchifempty.model.User; +import com.baeldung.switchifempty.service.UserService; import com.fasterxml.jackson.databind.ObjectMapper; import ch.qos.logback.classic.Level; From ce09611387b8a6c59f1ed06a918c044ab5e8ec5c Mon Sep 17 00:00:00 2001 From: balasr3 Date: Wed, 9 Oct 2024 23:00:20 +0100 Subject: [PATCH 2/7] BAEL-5972: added implementation for performing seek in Java --- spring-kafka-4/pom.xml | 13 +++ .../java/com/baeldung/seek/Application.java | 13 +++ .../com/baeldung/seek/ConsumerListener.java | 27 +++++ .../main/java/com/baeldung/seek/Response.java | 5 + .../com/baeldung/seek/SeekController.java | 75 ++++++++++++++ .../seek/ConsumerListenerSeekTest.java | 72 ++++++++++++++ .../com/baeldung/seek/SeekControllerTest.java | 99 +++++++++++++++++++ 7 files changed, 304 insertions(+) create mode 100644 spring-kafka-4/src/main/java/com/baeldung/seek/Application.java create mode 100644 spring-kafka-4/src/main/java/com/baeldung/seek/ConsumerListener.java create mode 100644 spring-kafka-4/src/main/java/com/baeldung/seek/Response.java create mode 100644 spring-kafka-4/src/main/java/com/baeldung/seek/SeekController.java create mode 100644 spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java create mode 100644 spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java diff --git a/spring-kafka-4/pom.xml b/spring-kafka-4/pom.xml index 3086d0993b04..b113ec0f1490 100644 --- a/spring-kafka-4/pom.xml +++ b/spring-kafka-4/pom.xml @@ -19,11 +19,24 @@ org.springframework.boot spring-boot-starter + + org.springframework.boot + spring-boot-starter-web + org.springframework.kafka spring-kafka ${spring-kafka.version} + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-test + test + org.springframework.kafka spring-kafka-test diff --git a/spring-kafka-4/src/main/java/com/baeldung/seek/Application.java b/spring-kafka-4/src/main/java/com/baeldung/seek/Application.java new file mode 100644 index 000000000000..f6e2ad92b894 --- /dev/null +++ b/spring-kafka-4/src/main/java/com/baeldung/seek/Application.java @@ -0,0 +1,13 @@ +package com.baeldung.seek; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-kafka-4/src/main/java/com/baeldung/seek/ConsumerListener.java b/spring-kafka-4/src/main/java/com/baeldung/seek/ConsumerListener.java new file mode 100644 index 000000000000..6bdf3670d30b --- /dev/null +++ b/spring-kafka-4/src/main/java/com/baeldung/seek/ConsumerListener.java @@ -0,0 +1,27 @@ +package com.baeldung.seek; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.common.TopicPartition; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.listener.AbstractConsumerSeekAware; +import org.springframework.stereotype.Component; + +@Component +class ConsumerListener extends AbstractConsumerSeekAware { + + public static final Map MESSAGES = new HashMap<>(); + + @Override + public void onPartitionsAssigned(Map assignments, ConsumerSeekCallback callback) { + assignments.keySet() + .forEach(tp -> callback.seekRelative(tp.topic(), tp.partition(), -1, false)); + } + + @KafkaListener(id = "test-seek", topics = "test-seek-topic") + public void listen(ConsumerRecord in) { + MESSAGES.put(in.key(), in.value()); + } +} diff --git a/spring-kafka-4/src/main/java/com/baeldung/seek/Response.java b/spring-kafka-4/src/main/java/com/baeldung/seek/Response.java new file mode 100644 index 000000000000..70fc5aaa0aeb --- /dev/null +++ b/spring-kafka-4/src/main/java/com/baeldung/seek/Response.java @@ -0,0 +1,5 @@ +package com.baeldung.seek; + +public record Response(int partition, long offset, String value) { + +} diff --git a/spring-kafka-4/src/main/java/com/baeldung/seek/SeekController.java b/spring-kafka-4/src/main/java/com/baeldung/seek/SeekController.java new file mode 100644 index 000000000000..3383f4cc8a75 --- /dev/null +++ b/spring-kafka-4/src/main/java/com/baeldung/seek/SeekController.java @@ -0,0 +1,75 @@ +package com.baeldung.seek; + +import java.time.Duration; +import java.util.Collections; +import java.util.Iterator; + +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.common.TopicPartition; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.kafka.core.DefaultKafkaConsumerFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/seek/api/v1/") +public class SeekController { + + public static final String TOPIC_NAME = "test-topic"; + + private final DefaultKafkaConsumerFactory consumerFactory; + + public SeekController(DefaultKafkaConsumerFactory consumerFactory) { + this.consumerFactory = consumerFactory; + } + + @GetMapping("partition/{partition}/offset/{offset}") + public ResponseEntity getOneByPartitionAndOffset(@PathVariable("partition") int partition, @PathVariable("offset") int offset) { + try (KafkaConsumer consumer = (KafkaConsumer) consumerFactory.createConsumer()) { + TopicPartition topicPartition = new TopicPartition(TOPIC_NAME, partition); + consumer.assign(Collections.singletonList(topicPartition)); + consumer.seek(topicPartition, offset); + ConsumerRecords records = consumer.poll(Duration.ofMillis(100)); + Iterator> recordIterator = records.iterator(); + if (recordIterator.hasNext()) { + ConsumerRecord consumerRecord = recordIterator.next(); + Response response = new Response(consumerRecord.partition(), consumerRecord.offset(), consumerRecord.value()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + } + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + @GetMapping("partition/{partition}/beginning") + public ResponseEntity getOneByPartitionToBeginningOffset(@PathVariable("partition") int partition) { + try (KafkaConsumer consumer = (KafkaConsumer) consumerFactory.createConsumer()) { + TopicPartition topicPartition = new TopicPartition(TOPIC_NAME, partition); + consumer.assign(Collections.singletonList(topicPartition)); + consumer.seekToBeginning(Collections.singleton(topicPartition)); + ConsumerRecords records = consumer.poll(Duration.ofMillis(100)); + Iterator> recordIterator = records.iterator(); + if (recordIterator.hasNext()) { + ConsumerRecord consumerRecord = recordIterator.next(); + Response response = new Response(consumerRecord.partition(), consumerRecord.offset(), consumerRecord.value()); + return new ResponseEntity<>(response, HttpStatus.OK); + } + } + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + @GetMapping("partition/{partition}/end") + public ResponseEntity getOneByPartitionToEndOffset(@PathVariable("partition") int partition) { + try (KafkaConsumer consumer = (KafkaConsumer) consumerFactory.createConsumer()) { + TopicPartition topicPartition = new TopicPartition(TOPIC_NAME, partition); + consumer.assign(Collections.singletonList(topicPartition)); + consumer.seekToEnd(Collections.singleton(topicPartition)); + return new ResponseEntity<>(consumer.position(topicPartition), HttpStatus.OK); + } + } + +} diff --git a/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java b/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java new file mode 100644 index 000000000000..8e573d976ad3 --- /dev/null +++ b/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java @@ -0,0 +1,72 @@ +package com.baeldung.seek; + +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.stream.IntStream; + +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.common.serialization.StringSerializer; +import org.junit.jupiter.api.Assertions; +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.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.read.ListAppender; + +@Testcontainers +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +class ConsumerListenerSeekTest { + + protected static ListAppender listAppender; + + @Autowired + ConsumerListener consumerListener; + + @Container + private static KafkaContainer KAFKA = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + private static KafkaProducer testKafkaProducer; + + @DynamicPropertySource + static void setProps(DynamicPropertyRegistry registry) { + registry.add("spring.kafka.bootstrap-servers", KAFKA::getBootstrapServers); + } + + @BeforeAll + static void beforeAll() { + Properties props = new Properties(); + props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA.getBootstrapServers()); + props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + testKafkaProducer = new KafkaProducer<>(props); + IntStream.range(0, 5) + .forEach(m -> { + ProducerRecord record = new ProducerRecord<>("test-seek-topic", 0, String.valueOf(m), "Message no : %s".formatted(m)); + try { + testKafkaProducer.send(record) + .get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }); + testKafkaProducer.flush(); + } + + @Test + void givenKafkaBrokerExists_whenMessagesAreSent_ThenLastMessageShouldBeRetrieved() { + Map messages = consumerListener.MESSAGES; + Assertions.assertEquals(1, messages.size()); + Assertions.assertEquals("Message no : 4", messages.get("4")); + } + +} \ No newline at end of file diff --git a/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java b/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java new file mode 100644 index 000000000000..95c54d4519d8 --- /dev/null +++ b/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java @@ -0,0 +1,99 @@ +package com.baeldung.seek; + +import static com.baeldung.seek.SeekController.TOPIC_NAME; + +import java.util.Properties; +import java.util.Random; +import java.util.concurrent.ExecutionException; +import java.util.stream.IntStream; + +import org.apache.kafka.clients.producer.KafkaProducer; +import org.apache.kafka.clients.producer.ProducerConfig; +import org.apache.kafka.clients.producer.ProducerRecord; +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.autoconfigure.web.reactive.AutoConfigureWebTestClient; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +@Testcontainers +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureWebTestClient +class SeekControllerTest { + + @Autowired + private WebTestClient webClient; + + @Container + private static KafkaContainer KAFKA = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:latest")); + private static KafkaProducer testKafkaProducer; + + @DynamicPropertySource + static void setProps(DynamicPropertyRegistry registry) { + registry.add("spring.kafka.bootstrap-servers", KAFKA::getBootstrapServers); + } + + @BeforeAll + static void beforeAll() { + Properties props = new Properties(); + props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA.getBootstrapServers()); + props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName()); + testKafkaProducer = new KafkaProducer<>(props); + int partition = 0; + IntStream.range(0, 5) + .forEach(m -> { + String key = String.valueOf(new Random().nextInt()); + String value = "Message no : %s".formatted(m); + ProducerRecord record = new ProducerRecord<>(TOPIC_NAME, partition, key, value); + try { + testKafkaProducer.send(record) + .get(); + } catch (InterruptedException | ExecutionException e) { + throw new RuntimeException(e); + } + }); + } + + @Test + void givenKafkaBrokerExists_whenSeekByPartition_thenMessageShouldBeRetrieved() { + this.webClient.get() + .uri("/seek/api/v1/partition/0/offset/2") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("{\"partition\":0,\"offset\":2,\"value\":\"Message no : 2\"}"); + } + + @Test + void givenKafkaBrokerExists_whenSeekByBeginning_thenFirstMessageShouldBeRetrieved() { + this.webClient.get() + .uri("/seek/api/v1/partition/0/beginning") + .exchange() + .expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("{\"partition\":0,\"offset\":0,\"value\":\"Message no : 0\"}"); + } + + @Test + void givenKafkaBrokerExists_whenSeekByEnd_thenLastMessageShouldBeRetrieved() { + this.webClient.get() + .uri("/seek/api/v1/partition/0/end") + .exchange() + .expectStatus() + .isOk() + .expectBody(Long.class) + .isEqualTo(5L); + } + +} \ No newline at end of file From e8ae13e5517f15c24e90495393ee1b8f2c709a03 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Thu, 10 Oct 2024 14:00:27 +0100 Subject: [PATCH 3/7] BAEL-5972: renamed tests appropriately --- .../src/test/java/com/baeldung/seek/SeekControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java b/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java index 95c54d4519d8..07017c35a9ac 100644 --- a/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java +++ b/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java @@ -64,7 +64,7 @@ static void beforeAll() { } @Test - void givenKafkaBrokerExists_whenSeekByPartition_thenMessageShouldBeRetrieved() { + void givenKafkaBrokerExists_whenSeekByPartitionAndOffset_thenMessageShouldBeRetrieved() { this.webClient.get() .uri("/seek/api/v1/partition/0/offset/2") .exchange() @@ -86,7 +86,7 @@ void givenKafkaBrokerExists_whenSeekByBeginning_thenFirstMessageShouldBeRetrieve } @Test - void givenKafkaBrokerExists_whenSeekByEnd_thenLastMessageShouldBeRetrieved() { + void givenKafkaBrokerExists_whenSeekByEnd_thenLatestOffsetShouldBeRetrieved() { this.webClient.get() .uri("/seek/api/v1/partition/0/end") .exchange() From 5fea5d11cc5d6cc2300ddc2c9119df93d39b2c03 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Thu, 10 Oct 2024 14:01:15 +0100 Subject: [PATCH 4/7] BAEL-5972: renamed tests appropriately --- ...rListenerSeekTest.java => ConsumerListenerSeekLiveTest.java} | 2 +- .../{SeekControllerTest.java => SeekControllerLiveTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spring-kafka-4/src/test/java/com/baeldung/seek/{ConsumerListenerSeekTest.java => ConsumerListenerSeekLiveTest.java} (98%) rename spring-kafka-4/src/test/java/com/baeldung/seek/{SeekControllerTest.java => SeekControllerLiveTest.java} (99%) diff --git a/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java b/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java similarity index 98% rename from spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java rename to spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java index 8e573d976ad3..80b546a3c953 100644 --- a/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekTest.java +++ b/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java @@ -26,7 +26,7 @@ @Testcontainers @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -class ConsumerListenerSeekTest { +class ConsumerListenerSeekLiveTest { protected static ListAppender listAppender; diff --git a/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java b/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerLiveTest.java similarity index 99% rename from spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java rename to spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerLiveTest.java index 07017c35a9ac..358c79414ae5 100644 --- a/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerTest.java +++ b/spring-kafka-4/src/test/java/com/baeldung/seek/SeekControllerLiveTest.java @@ -27,7 +27,7 @@ @Testcontainers @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureWebTestClient -class SeekControllerTest { +class SeekControllerLiveTest { @Autowired private WebTestClient webClient; From 6c66eb8d66e2a921a1523efdaecfdcdb2ca979df Mon Sep 17 00:00:00 2001 From: balasr3 Date: Thu, 10 Oct 2024 14:02:57 +0100 Subject: [PATCH 5/7] BAEL-5972: renamed tests appropriately --- .../java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java b/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java index 80b546a3c953..f14bba50c16a 100644 --- a/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java +++ b/spring-kafka-4/src/test/java/com/baeldung/seek/ConsumerListenerSeekLiveTest.java @@ -63,7 +63,7 @@ static void beforeAll() { } @Test - void givenKafkaBrokerExists_whenMessagesAreSent_ThenLastMessageShouldBeRetrieved() { + void givenKafkaBrokerExists_whenMessagesAreSent_thenLastMessageShouldBeRetrieved() { Map messages = consumerListener.MESSAGES; Assertions.assertEquals(1, messages.size()); Assertions.assertEquals("Message no : 4", messages.get("4")); From 4f5ff472a01eb27c176068552155dac18671ead7 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Thu, 10 Oct 2024 14:15:06 +0100 Subject: [PATCH 6/7] BAEL-5972: removed unnecessary change --- .../controller/UserController.java | 6 +++--- .../{switchifempty => switchIfempty}/model/User.java | 2 +- .../service/UserService.java | 4 ++-- .../controller/UserControllerTest.java | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchifempty => switchIfempty}/controller/UserController.java (86%) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchifempty => switchIfempty}/model/User.java (93%) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchifempty => switchIfempty}/service/UserService.java (95%) rename spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/{switchifempty => switchIfempty}/controller/UserControllerTest.java (97%) diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/controller/UserController.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/controller/UserController.java similarity index 86% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/controller/UserController.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/controller/UserController.java index 5fe40f93b1e4..b73b5d186627 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/controller/UserController.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/controller/UserController.java @@ -1,4 +1,4 @@ -package com.baeldung.switchifempty.controller; +package com.baeldung.switchIfempty.controller; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.switchifempty.model.User; -import com.baeldung.switchifempty.service.UserService; +import com.baeldung.switchIfempty.model.User; +import com.baeldung.switchIfempty.service.UserService; import reactor.core.publisher.Mono; diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/model/User.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/model/User.java similarity index 93% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/model/User.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/model/User.java index 5e60e7da60b1..bfefe854696b 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/model/User.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/model/User.java @@ -1,4 +1,4 @@ -package com.baeldung.switchifempty.model; +package com.baeldung.switchIfempty.model; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/service/UserService.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/service/UserService.java similarity index 95% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/service/UserService.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/service/UserService.java index cd07e66250e7..909f20e8a721 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchifempty/service/UserService.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/service/UserService.java @@ -1,4 +1,4 @@ -package com.baeldung.switchifempty.service; +package com.baeldung.switchIfempty.service; import java.io.File; import java.io.IOException; @@ -12,7 +12,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import com.baeldung.switchifempty.model.User; +import com.baeldung.switchIfempty.model.User; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchifempty/controller/UserControllerTest.java b/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfempty/controller/UserControllerTest.java similarity index 97% rename from spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchifempty/controller/UserControllerTest.java rename to spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfempty/controller/UserControllerTest.java index baddd4a2810e..e6b662e09e96 100644 --- a/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchifempty/controller/UserControllerTest.java +++ b/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfempty/controller/UserControllerTest.java @@ -1,4 +1,4 @@ -package com.baeldung.switchifempty.controller; +package com.baeldung.switchIfempty.controller; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -12,8 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.reactive.server.WebTestClient; -import com.baeldung.switchifempty.model.User; -import com.baeldung.switchifempty.service.UserService; +import com.baeldung.switchIfempty.model.User; +import com.baeldung.switchIfempty.service.UserService; import com.fasterxml.jackson.databind.ObjectMapper; import ch.qos.logback.classic.Level; From 84386f343e3660c62ab19d90f085c8f512690548 Mon Sep 17 00:00:00 2001 From: balasr3 Date: Thu, 10 Oct 2024 14:16:40 +0100 Subject: [PATCH 7/7] BAEL-5972: removed unnecessary change --- .../controller/UserController.java | 6 +++--- .../{switchIfempty => switchIfEmpty}/model/User.java | 2 +- .../service/UserService.java | 4 ++-- .../controller/UserControllerTest.java | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchIfempty => switchIfEmpty}/controller/UserController.java (86%) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchIfempty => switchIfEmpty}/model/User.java (93%) rename spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/{switchIfempty => switchIfEmpty}/service/UserService.java (95%) rename spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/{switchIfempty => switchIfEmpty}/controller/UserControllerTest.java (97%) diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/controller/UserController.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/controller/UserController.java similarity index 86% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/controller/UserController.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/controller/UserController.java index b73b5d186627..1c56f1203644 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/controller/UserController.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/controller/UserController.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfempty.controller; +package com.baeldung.switchIfEmpty.controller; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -7,8 +7,8 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.switchIfempty.model.User; -import com.baeldung.switchIfempty.service.UserService; +import com.baeldung.switchIfEmpty.model.User; +import com.baeldung.switchIfEmpty.service.UserService; import reactor.core.publisher.Mono; diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/model/User.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/model/User.java similarity index 93% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/model/User.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/model/User.java index bfefe854696b..589099144e39 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/model/User.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/model/User.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfempty.model; +package com.baeldung.switchIfEmpty.model; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/service/UserService.java b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/service/UserService.java similarity index 95% rename from spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/service/UserService.java rename to spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/service/UserService.java index 909f20e8a721..47c4b9b35d94 100644 --- a/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfempty/service/UserService.java +++ b/spring-reactive-modules/spring-reactive-4/src/main/java/com/baeldung/switchIfEmpty/service/UserService.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfempty.service; +package com.baeldung.switchIfEmpty.service; import java.io.File; import java.io.IOException; @@ -12,7 +12,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import com.baeldung.switchIfempty.model.User; +import com.baeldung.switchIfEmpty.model.User; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; diff --git a/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfempty/controller/UserControllerTest.java b/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfEmpty/controller/UserControllerTest.java similarity index 97% rename from spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfempty/controller/UserControllerTest.java rename to spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfEmpty/controller/UserControllerTest.java index e6b662e09e96..72c57d8b1a4c 100644 --- a/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfempty/controller/UserControllerTest.java +++ b/spring-reactive-modules/spring-reactive-4/src/test/java/com/baeldung/switchIfEmpty/controller/UserControllerTest.java @@ -1,4 +1,4 @@ -package com.baeldung.switchIfempty.controller; +package com.baeldung.switchIfEmpty.controller; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -12,8 +12,8 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.web.reactive.server.WebTestClient; -import com.baeldung.switchIfempty.model.User; -import com.baeldung.switchIfempty.service.UserService; +import com.baeldung.switchIfEmpty.model.User; +import com.baeldung.switchIfEmpty.service.UserService; import com.fasterxml.jackson.databind.ObjectMapper; import ch.qos.logback.classic.Level;