Unignored messaging tests
This commit is contained in:
@@ -20,22 +20,20 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
|
||||
import org.springframework.cloud.stream.messaging.Source;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
class MessagePoller {
|
||||
class MessageSender {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MessagePoller.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(MessageSender.class);
|
||||
|
||||
private final EmitterProcessor<String> emitterProcessor;
|
||||
|
||||
MessagePoller(EmitterProcessor<String> emitterProcessor) {
|
||||
MessageSender(EmitterProcessor<String> emitterProcessor) {
|
||||
this.emitterProcessor = emitterProcessor;
|
||||
}
|
||||
|
||||
public void poll() {
|
||||
public void emit() {
|
||||
log.info("Emitting the message");
|
||||
this.emitterProcessor.onNext("{\"id\":\"99\",\"temperature\":\"123.45\"}");
|
||||
}
|
||||
@@ -19,6 +19,7 @@ package com.example.fraud;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,8 +32,8 @@ class MessagingConfiguration {
|
||||
return EmitterProcessor.create();
|
||||
}
|
||||
|
||||
@Bean(name = "sensor-data")
|
||||
Supplier<String> sensorData() {
|
||||
return () -> "{\"id\":\"99\",\"temperature\":\"123.45\"}";
|
||||
@Bean(name = "sensor_data")
|
||||
Supplier<Flux<String>> sensorData(EmitterProcessor<String> processor) {
|
||||
return () -> processor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,27 +27,24 @@ import java.util.function.Function;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.stream.annotation.StreamListener;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("my_output")
|
||||
class MyProcessorListener implements Function<byte[], byte[]> {
|
||||
class MyProcessor implements Function<byte[], byte[]> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MyProcessorListener.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(MyProcessor.class);
|
||||
|
||||
private final byte[] expectedInput;
|
||||
|
||||
private final byte[] expectedOutput;
|
||||
|
||||
MyProcessorListener() {
|
||||
MyProcessor() {
|
||||
this.expectedInput = forFile("/contracts/messaging/input.pdf");
|
||||
this.expectedOutput = forFile("/contracts/messaging/output.pdf");
|
||||
}
|
||||
|
||||
private byte[] forFile(String relative) {
|
||||
URL resource = MyProcessorListener.class.getResource(relative);
|
||||
URL resource = MyProcessor.class.getResource(relative);
|
||||
try {
|
||||
return Files.readAllBytes(new File(resource.toURI()).toPath());
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
spring.cloud.function.definition=my_output;sensor-data
|
||||
spring.cloud.stream.bindings.sensor-data-out-0.contentType=application/json
|
||||
spring.cloud.function.definition=my_output;sensor_data
|
||||
spring.cloud.stream.bindings.sensor_data-out-0.destination=sensor_data
|
||||
spring.cloud.stream.bindings.my_output-in-0.contentType=application/octet-stream
|
||||
spring.cloud.stream.bindings.my_output-in-0.destination=bytes_input
|
||||
spring.cloud.stream.bindings.my_output-out-0.contentType=application/octet-stream
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.web.context.WebApplicationContext;
|
||||
public abstract class MessagingBase {
|
||||
|
||||
@Autowired
|
||||
MessagePoller poller;
|
||||
MessageSender poller;
|
||||
|
||||
@Autowired
|
||||
WebApplicationContext context;
|
||||
@@ -53,7 +53,7 @@ public abstract class MessagingBase {
|
||||
}
|
||||
|
||||
public void createSensorData() {
|
||||
poller.poll();
|
||||
poller.emit();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -19,7 +19,6 @@ package contracts
|
||||
org.springframework.cloud.contract.spec.Contract.make {
|
||||
// Human readable description
|
||||
description 'Should produce valid sensor data'
|
||||
ignored()
|
||||
// Label by means of which the output message can be triggered
|
||||
label 'sensor1'
|
||||
// input to the contract
|
||||
@@ -30,7 +29,7 @@ org.springframework.cloud.contract.spec.Contract.make {
|
||||
// output message of the contract
|
||||
outputMessage {
|
||||
// destination to which the output message will be sent
|
||||
sentTo 'sensor-data'
|
||||
sentTo 'sensor_data'
|
||||
headers {
|
||||
header('contentType': 'application/json')
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.springframework.cloud.contract.spec.Contract
|
||||
|
||||
Contract.make {
|
||||
label("positive")
|
||||
ignored()
|
||||
input {
|
||||
messageFrom("bytes_input")
|
||||
messageBody(fileAsBytes("input.pdf"))
|
||||
|
||||
Reference in New Issue
Block a user