Merge pull request #4 from eugenp/master

Sync merge
This commit is contained in:
smokeyrobot 2020-02-28 19:36:57 -05:00 committed by GitHub
commit 98cd6c524a
31 changed files with 163 additions and 124 deletions

View File

@ -5,3 +5,4 @@ This module contains articles about Scala's core features
### Relevant Articles: ### Relevant Articles:
- [Introduction to Scala](https://www.baeldung.com/scala-intro) - [Introduction to Scala](https://www.baeldung.com/scala-intro)
- [Regular Expressions in Scala](https://www.baeldung.com/scala/regular-expressions)

View File

@ -1,4 +1,4 @@
package com.baeldung.scala package com.baeldung.scala.regex
import org.junit.Test import org.junit.Test
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals

View File

@ -11,7 +11,7 @@
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath> <relativePath>../../../parent-boot-2</relativePath>
</parent> </parent>
<dependencies> <dependencies>

View File

@ -12,7 +12,7 @@
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId> <artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath> <relativePath>../../../parent-boot-2</relativePath>
</parent> </parent>
<dependencyManagement> <dependencyManagement>

View File

@ -31,3 +31,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) - [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)

View File

@ -35,7 +35,7 @@
<module>spring-cloud-archaius</module> <module>spring-cloud-archaius</module>
<module>spring-cloud-functions</module> <module>spring-cloud-functions</module>
<module>spring-cloud-vault</module> <module>spring-cloud-vault</module>
<!-- <module>spring-cloud-security</module> --> <!-- Fixing in BAEL-10887 --> <module>spring-cloud-security</module>
<module>spring-cloud-task</module> <module>spring-cloud-task</module>
<module>spring-cloud-zuul</module> <module>spring-cloud-zuul</module>
<module>spring-cloud-zuul-fallback</module> <module>spring-cloud-zuul-fallback</module>

View File

@ -6,9 +6,18 @@ import javax.ejb.Singleton;
public class CounterEJB implements CounterEJBRemote { public class CounterEJB implements CounterEJBRemote {
private int count = 1; private int count = 1;
private String name;
public int count() { public int count() {
return count++; return count++;
} }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
} }

View File

@ -5,4 +5,6 @@ import javax.ejb.Remote;
@Remote @Remote
public interface CounterEJBRemote { public interface CounterEJBRemote {
int count(); int count();
String getName();
void setName(String name);
} }

View File

@ -7,7 +7,7 @@ import javax.ejb.Stateful;
@Stateful @Stateful
public class ShoppingCartEJB implements ShoppingCartEJBRemote { public class ShoppingCartEJB implements ShoppingCartEJBRemote {
private String name;
private List<String> shoppingCart; private List<String> shoppingCart;
public ShoppingCartEJB() { public ShoppingCartEJB() {
@ -22,4 +22,11 @@ public class ShoppingCartEJB implements ShoppingCartEJBRemote {
return shoppingCart; return shoppingCart;
} }
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
} }

View File

@ -10,4 +10,8 @@ public interface ShoppingCartEJBRemote {
void addItem(String item); void addItem(String item);
List<String> getItems(); List<String> getItems();
void setName(String name);
String getName();
} }

View File

@ -5,8 +5,18 @@ import org.springframework.stereotype.Component;
@Component @Component
public class CounterBean { public class CounterBean {
private int count = 1; private int count = 1;
private String name;
public int count() { public int count() {
return count++; return count++;
} }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
} }

View File

@ -11,6 +11,7 @@ import org.springframework.stereotype.Component;
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class ShoppingCartBean { public class ShoppingCartBean {
private String name;
private List<String> shoppingCart; private List<String> shoppingCart;
public ShoppingCartBean() { public ShoppingCartBean() {
@ -25,4 +26,11 @@ public class ShoppingCartBean {
return shoppingCart; return shoppingCart;
} }
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
} }

View File

@ -1,9 +1,7 @@
package com.baeldung.ejb.spring.comparison.ejb; package com.baeldung.ejb.spring.comparison.ejb;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.ejb.EJB; import javax.ejb.EJB;
@ -51,7 +49,7 @@ public class EJBUnitTest {
public static void start() throws NamingException { public static void start() throws NamingException {
ejbContainer = EJBContainer.createEJBContainer(); ejbContainer = EJBContainer.createEJBContainer();
} }
@Before @Before
public void initializeContext() throws NamingException { public void initializeContext() throws NamingException {
context = ejbContainer.getContext(); context = ejbContainer.getContext();
@ -60,42 +58,44 @@ public class EJBUnitTest {
@Test @Test
public void givenSingletonBean_whenCounterInvoked_thenCountIsIncremented() throws NamingException { public void givenSingletonBean_whenCounterInvoked_thenCountIsIncremented() throws NamingException {
int count = 0; int count = 0;
CounterEJBRemote counterEJB = (CounterEJBRemote) context.lookup("java:global/ejb-beans/CounterEJB"); CounterEJBRemote firstCounter = (CounterEJBRemote) context.lookup("java:global/ejb-beans/CounterEJB");
firstCounter.setName("first");
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++) {
count = counterEJB.count(); count = firstCounter.count();
}
assertThat(count, is(not(1)));
}
@Test
public void givenSingletonBean_whenCounterInvokedAgain_thenCountIsIncremented() throws NamingException {
CounterEJBRemote counterEJB = (CounterEJBRemote) context.lookup("java:global/ejb-beans/CounterEJB");
int count = 0; assertEquals(10, count);
for (int i = 0; i < 10; i++) assertEquals("first", firstCounter.getName());
count = counterEJB.count();
CounterEJBRemote secondCounter = (CounterEJBRemote) context.lookup("java:global/ejb-beans/CounterEJB");
int count2 = 0;
for (int i = 0; i < 10; i++) {
count2 = secondCounter.count();
}
assertEquals(20, count2);
assertEquals("first", secondCounter.getName());
assertThat(count, is(not(1)));
} }
@Test @Test
public void givenStatefulBean_whenBathingCartWithThreeItemsAdded_thenItemsSizeIsThree() throws NamingException { public void givenStatefulBean_whenBathingCartWithThreeItemsAdded_thenItemsSizeIsThree() throws NamingException {
ShoppingCartEJBRemote bathingCart = (ShoppingCartEJBRemote) context.lookup("java:global/ejb-beans/ShoppingCartEJB"); ShoppingCartEJBRemote bathingCart = (ShoppingCartEJBRemote) context.lookup("java:global/ejb-beans/ShoppingCartEJB");
bathingCart.setName("bathingCart");
bathingCart.addItem("soap"); bathingCart.addItem("soap");
bathingCart.addItem("shampoo"); bathingCart.addItem("shampoo");
bathingCart.addItem("oil"); bathingCart.addItem("oil");
assertEquals(3, bathingCart.getItems() assertEquals(3, bathingCart.getItems()
.size()); .size());
} assertEquals("bathingCart", bathingCart.getName());
@Test
public void givenStatefulBean_whenFruitCartWithTwoItemsAdded_thenItemsSizeIsTwo() throws NamingException {
ShoppingCartEJBRemote fruitCart = (ShoppingCartEJBRemote) context.lookup("java:global/ejb-beans/ShoppingCartEJB"); ShoppingCartEJBRemote fruitCart = (ShoppingCartEJBRemote) context.lookup("java:global/ejb-beans/ShoppingCartEJB");
fruitCart.addItem("apples"); fruitCart.addItem("apples");
@ -103,6 +103,7 @@ public class EJBUnitTest {
assertEquals(2, fruitCart.getItems() assertEquals(2, fruitCart.getItems()
.size()); .size());
assertNull(fruitCart.getName());
} }
@Test @Test
@ -131,10 +132,7 @@ public class EJBUnitTest {
} }
@AfterClass @AfterClass
public static void checkTotalCountAndcloseContext() throws NamingException { public static void closeContext() throws NamingException {
CounterEJBRemote counterEJB = (CounterEJBRemote) context.lookup("java:global/ejb-beans/CounterEJB");
assertEquals(21, counterEJB.count());
context.close(); context.close();
ejbContainer.close(); ejbContainer.close();
} }

View File

@ -1,9 +1,7 @@
package com.baeldung.ejb.spring.comparison.spring; package com.baeldung.ejb.spring.comparison.spring;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import javax.naming.NamingException; import javax.naming.NamingException;
@ -46,40 +44,44 @@ public class SpringUnitTest {
@Test @Test
public void whenCounterInvoked_thenCountIsIncremented() throws NamingException { public void whenCounterInvoked_thenCountIsIncremented() throws NamingException {
CounterBean counterBean = context.getBean(CounterBean.class);
CounterBean firstCounter = context.getBean(CounterBean.class);
firstCounter.setName("first");
int count = 0; int count = 0;
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++) {
count = counterBean.count(); count = firstCounter.count();
}
assertThat(count, is(not(1))); assertEquals(10, count);
} assertEquals("first", firstCounter.getName());
@Test CounterBean secondCounter = context.getBean(CounterBean.class);
public void whenCounterInvokedAgain_thenCountIsIncremented() throws NamingException {
CounterBean counterBean = context.getBean(CounterBean.class);
int count = 0; int count2 = 0;
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++) {
count = counterBean.count(); count2 = secondCounter.count();
}
assertEquals(20, count2);
assertEquals("first", secondCounter.getName());
assertThat(count, is(not(1)));
} }
@Test @Test
public void whenBathingCartWithThreeItemsAdded_thenItemsSizeIsThree() throws NamingException { public void whenBathingCartWithThreeItemsAdded_thenItemsSizeIsThree() throws NamingException {
ShoppingCartBean bathingCart = context.getBean(ShoppingCartBean.class); ShoppingCartBean bathingCart = context.getBean(ShoppingCartBean.class);
bathingCart.setName("bathingCart");
bathingCart.addItem("soap"); bathingCart.addItem("soap");
bathingCart.addItem("shampoo"); bathingCart.addItem("shampoo");
bathingCart.addItem("oil"); bathingCart.addItem("oil");
assertEquals(3, bathingCart.getItems() assertEquals(3, bathingCart.getItems()
.size()); .size());
}
@Test assertEquals("bathingCart", bathingCart.getName());
public void whenFruitCartWithTwoItemsAdded_thenItemsSizeIsTwo() throws NamingException {
ShoppingCartBean fruitCart = context.getBean(ShoppingCartBean.class); ShoppingCartBean fruitCart = context.getBean(ShoppingCartBean.class);
fruitCart.addItem("apples"); fruitCart.addItem("apples");
@ -87,6 +89,7 @@ public class SpringUnitTest {
assertEquals(2, fruitCart.getItems() assertEquals(2, fruitCart.getItems()
.size()); .size());
assertNull(fruitCart.getName());
} }
@Test @Test
@ -98,10 +101,7 @@ public class SpringUnitTest {
} }
@AfterClass @AfterClass
public static void checkTotalCountAndcloseContext() throws NamingException { public static void closeContext() throws NamingException {
CounterBean counterBean = context.getBean(CounterBean.class);
int count = counterBean.count();
assertEquals(21, count);
context.close(); context.close();
} }

View File

@ -25,7 +25,7 @@ public class KafkaApplication {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ConfigurableApplicationContext context = SpringApplication.run(KafkaApplication.class, args); ConfigurableApplicationContext context = SpringApplication.run(KafkaApplication.class, args);
MessageProducer producer = context.getBean(MessageProducer.class); MessageProducer producer = context.getBean(MessageProducer.class);
MessageListener listener = context.getBean(MessageListener.class); MessageListener listener = context.getBean(MessageListener.class);
/* /*
@ -101,15 +101,17 @@ public class KafkaApplication {
private String greetingTopicName; private String greetingTopicName;
public void sendMessage(String message) { public void sendMessage(String message) {
ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topicName, message); ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send(topicName, message);
future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
@Override @Override
public void onSuccess(SendResult<String, String> result) { public void onSuccess(SendResult<String, String> result) {
System.out.println("Sent message=[" + message + "] with offset=[" + result.getRecordMetadata().offset() + "]"); System.out.println("Sent message=[" + message + "] with offset=[" + result.getRecordMetadata()
.offset() + "]");
} }
@Override @Override
public void onFailure(Throwable ex) { public void onFailure(Throwable ex) {
System.out.println("Unable to send message=[" + message + "] due to : " + ex.getMessage()); System.out.println("Unable to send message=[" + message + "] due to : " + ex.getMessage());
@ -158,7 +160,7 @@ public class KafkaApplication {
latch.countDown(); latch.countDown();
} }
@KafkaListener(topicPartitions = @TopicPartition(topic = "${partitioned.topic.name}", partitions = { "0", "3" })) @KafkaListener(topicPartitions = @TopicPartition(topic = "${partitioned.topic.name}", partitions = { "0", "3" }), containerFactory = "partitionsKafkaListenerContainerFactory")
public void listenToParition(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) { public void listenToParition(@Payload String message, @Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition) {
System.out.println("Received Message: " + message + " from partition: " + partition); System.out.println("Received Message: " + message + " from partition: " + partition);
this.partitionLatch.countDown(); this.partitionLatch.countDown();

View File

@ -29,7 +29,7 @@ public class KafkaConsumerConfig {
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class); props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
return new DefaultKafkaConsumerFactory<>(props); return new DefaultKafkaConsumerFactory<>(props);
} }
public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(String groupId) { public ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(String groupId) {
ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>(); ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
factory.setConsumerFactory(consumerFactory(groupId)); factory.setConsumerFactory(consumerFactory(groupId));
@ -50,12 +50,12 @@ public class KafkaConsumerConfig {
public ConcurrentKafkaListenerContainerFactory<String, String> headersKafkaListenerContainerFactory() { public ConcurrentKafkaListenerContainerFactory<String, String> headersKafkaListenerContainerFactory() {
return kafkaListenerContainerFactory("headers"); return kafkaListenerContainerFactory("headers");
} }
@Bean @Bean
public ConcurrentKafkaListenerContainerFactory<String, String> partitionsKafkaListenerContainerFactory() { public ConcurrentKafkaListenerContainerFactory<String, String> partitionsKafkaListenerContainerFactory() {
return kafkaListenerContainerFactory("partitions"); return kafkaListenerContainerFactory("partitions");
} }
@Bean @Bean
public ConcurrentKafkaListenerContainerFactory<String, String> filterKafkaListenerContainerFactory() { public ConcurrentKafkaListenerContainerFactory<String, String> filterKafkaListenerContainerFactory() {
ConcurrentKafkaListenerContainerFactory<String, String> factory = kafkaListenerContainerFactory("filter"); ConcurrentKafkaListenerContainerFactory<String, String> factory = kafkaListenerContainerFactory("filter");

View File

@ -32,7 +32,7 @@ public class KafkaProducerConfig {
public KafkaTemplate<String, String> kafkaTemplate() { public KafkaTemplate<String, String> kafkaTemplate() {
return new KafkaTemplate<>(producerFactory()); return new KafkaTemplate<>(producerFactory());
} }
@Bean @Bean
public ProducerFactory<String, Greeting> greetingProducerFactory() { public ProducerFactory<String, Greeting> greetingProducerFactory() {
Map<String, Object> configProps = new HashMap<>(); Map<String, Object> configProps = new HashMap<>();
@ -41,10 +41,10 @@ public class KafkaProducerConfig {
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class); configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, JsonSerializer.class);
return new DefaultKafkaProducerFactory<>(configProps); return new DefaultKafkaProducerFactory<>(configProps);
} }
@Bean @Bean
public KafkaTemplate<String, Greeting> greetingKafkaTemplate() { public KafkaTemplate<String, Greeting> greetingKafkaTemplate() {
return new KafkaTemplate<>(greetingProducerFactory()); return new KafkaTemplate<>(greetingProducerFactory());
} }
} }

View File

@ -12,10 +12,10 @@ import org.springframework.kafka.core.KafkaAdmin;
@Configuration @Configuration
public class KafkaTopicConfig { public class KafkaTopicConfig {
@Value(value = "${kafka.bootstrapAddress}") @Value(value = "${kafka.bootstrapAddress}")
private String bootstrapAddress; private String bootstrapAddress;
@Value(value = "${message.topic.name}") @Value(value = "${message.topic.name}")
private String topicName; private String topicName;
@ -27,31 +27,31 @@ public class KafkaTopicConfig {
@Value(value = "${greeting.topic.name}") @Value(value = "${greeting.topic.name}")
private String greetingTopicName; private String greetingTopicName;
@Bean @Bean
public KafkaAdmin kafkaAdmin() { public KafkaAdmin kafkaAdmin() {
Map<String, Object> configs = new HashMap<>(); Map<String, Object> configs = new HashMap<>();
configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress); configs.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapAddress);
return new KafkaAdmin(configs); return new KafkaAdmin(configs);
} }
@Bean @Bean
public NewTopic topic1() { public NewTopic topic1() {
return new NewTopic(topicName, 1, (short) 1); return new NewTopic(topicName, 1, (short) 1);
} }
@Bean @Bean
public NewTopic topic2() { public NewTopic topic2() {
return new NewTopic(partionedTopicName, 6, (short) 1); return new NewTopic(partionedTopicName, 6, (short) 1);
} }
@Bean @Bean
public NewTopic topic3() { public NewTopic topic3() {
return new NewTopic(filteredTopicName, 1, (short) 1); return new NewTopic(filteredTopicName, 1, (short) 1);
} }
@Bean @Bean
public NewTopic topic4() { public NewTopic topic4() {
return new NewTopic(greetingTopicName, 1, (short) 1); return new NewTopic(greetingTopicName, 1, (short) 1);
} }
} }

View File

@ -1,8 +1,7 @@
package com.baeldung; package com.baeldung.reactorbus;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import reactor.Environment; import reactor.Environment;
import reactor.bus.EventBus; import reactor.bus.EventBus;
@ -10,13 +9,12 @@ import reactor.bus.EventBus;
public class Config { public class Config {
@Bean @Bean
Environment env() { public Environment env() {
return Environment.initializeIfEmpty().assignErrorJournal(); return Environment.initializeIfEmpty().assignErrorJournal();
} }
@Bean @Bean
EventBus createEventBus(Environment env) { public EventBus createEventBus(Environment env) {
return EventBus.create(env, Environment.THREAD_POOL); return EventBus.create(env, Environment.THREAD_POOL);
} }
} }

View File

@ -1,24 +1,16 @@
package com.baeldung; package com.baeldung.reactorbus;
import com.baeldung.reactorbus.consumer.NotificationConsumer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import com.baeldung.consumer.NotificationConsumer;
import reactor.bus.EventBus; import reactor.bus.EventBus;
import static reactor.bus.selector.Selectors.$; import static reactor.bus.selector.Selectors.$;
@Configuration @SpringBootApplication
@EnableAutoConfiguration public class NotificationApplication implements CommandLineRunner {
@ComponentScan
@Import(Config.class)
public class Application implements CommandLineRunner {
@Autowired @Autowired
private EventBus eventBus; private EventBus eventBus;
@ -32,7 +24,6 @@ public class Application implements CommandLineRunner {
} }
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(Application.class, args); SpringApplication.run(NotificationApplication.class, args);
} }
} }

View File

@ -1,10 +1,10 @@
package com.baeldung.consumer; package com.baeldung.reactorbus.consumer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baeldung.doman.NotificationData; import com.baeldung.reactorbus.domain.NotificationData;
import com.baeldung.service.NotificationService; import com.baeldung.reactorbus.service.NotificationService;
import reactor.bus.Event; import reactor.bus.Event;
import reactor.fn.Consumer; import reactor.fn.Consumer;

View File

@ -1,11 +1,11 @@
package com.baeldung.controller; package com.baeldung.reactorbus.controller;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.baeldung.doman.NotificationData; import com.baeldung.reactorbus.domain.NotificationData;
import reactor.bus.Event; import reactor.bus.Event;
import reactor.bus.EventBus; import reactor.bus.EventBus;

View File

@ -1,4 +1,4 @@
package com.baeldung.doman; package com.baeldung.reactorbus.domain;
public class NotificationData { public class NotificationData {

View File

@ -1,6 +1,6 @@
package com.baeldung.service; package com.baeldung.reactorbus.service;
import com.baeldung.doman.NotificationData; import com.baeldung.reactorbus.domain.NotificationData;
public interface NotificationService { public interface NotificationService {

View File

@ -1,9 +1,9 @@
package com.baeldung.service.impl; package com.baeldung.reactorbus.service.impl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.baeldung.doman.NotificationData; import com.baeldung.reactorbus.domain.NotificationData;
import com.baeldung.service.NotificationService; import com.baeldung.reactorbus.service.NotificationService;
@Service @Service
public class NotificationServiceimpl implements NotificationService { public class NotificationServiceimpl implements NotificationService {

View File

@ -1,14 +0,0 @@
package com.baeldung;
import org.junit.Test;
import org.springframework.web.client.RestTemplate;
public class DataLoaderLiveTest {
@Test
public void exampleTest() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getForObject("http://localhost:8080/startNotification/10", String.class);
}
}

View File

@ -1,14 +1,14 @@
package org.baeldung; package com.baeldung;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.Application; import com.baeldung.reactorbus.NotificationApplication;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = NotificationApplication.class)
public class SpringContextTest { public class SpringContextTest {
@Test @Test

View File

@ -0,0 +1,22 @@
package com.baeldung.reactorbus;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class NotificationApplicationIntegrationTest {
@LocalServerPort
private int port;
@Test
public void givenAppStarted_whenNotificationTasksSubmitted_thenProcessed() {
RestTemplate restTemplate = new RestTemplate();
restTemplate.getForObject("http://localhost:" + port + "/startNotification/10", String.class);
}
}