Skip to content

Commit c97c0b2

Browse files
onobcolegz
authored andcommitted
Add tests to illustrate the bug
1 parent f3b9896 commit c97c0b2

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

spring-cloud-function-context/src/test/java/org/springframework/cloud/function/context/catalog/SimpleFunctionRegistryTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import org.junit.jupiter.api.BeforeEach;
4242
import org.junit.jupiter.api.Disabled;
4343
import org.junit.jupiter.api.Test;
44+
import org.junit.jupiter.params.ParameterizedTest;
45+
import org.junit.jupiter.params.provider.ValueSource;
4446
import org.reactivestreams.Publisher;
4547
import reactor.core.publisher.Flux;
4648
import reactor.core.publisher.Mono;
@@ -79,6 +81,7 @@
7981
/**
8082
* @author Oleg Zhurakousky
8183
* @author Soby Chacko
84+
* @author Chris Bono
8285
*/
8386
public class SimpleFunctionRegistryTests {
8487

@@ -190,6 +193,20 @@ public void testSCF640() {
190193
assertThat(result).isEqualTo("{\"HELLO\":\"WORLD\"}");
191194
}
192195

196+
// TODO: Once bug is fixed this test (last entry) will fully pass and this COMMENT should be removed
197+
@ParameterizedTest
198+
@ValueSource(strings = {"[hello", "hello]", "[hello]"})
199+
void textContentTypeWithValueWrappedBracketsIsOk(String inputMessagePayloadValue) {
200+
var catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter, new JacksonMapper(new ObjectMapper()));
201+
catalog.register(new FunctionRegistration<>(new Echo(), "echo").type(Echo.class));
202+
FunctionInvocationWrapper lookedUpFunction = catalog.lookup("echo");
203+
var inputMessage = MessageBuilder.withPayload(inputMessagePayloadValue)
204+
.setHeader("contentType", "text/plain")
205+
.build();
206+
var functionResult = lookedUpFunction.apply(inputMessage);
207+
assertThat(functionResult).isEqualTo(inputMessagePayloadValue);
208+
}
209+
193210
@SuppressWarnings("unchecked")
194211
@Test
195212
public void testSCF762() {

spring-cloud-function-web/src/test/java/org/springframework/cloud/function/web/mvc/HttpGetIntegrationTests.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717
package org.springframework.cloud.function.web.mvc;
1818

1919
import java.net.URI;
20+
import java.net.URISyntaxException;
2021
import java.time.Duration;
2122
import java.util.ArrayList;
2223
import java.util.Arrays;
@@ -30,6 +31,8 @@
3031
import org.junit.jupiter.api.BeforeEach;
3132
import org.junit.jupiter.api.Disabled;
3233
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.ValueSource;
3336
import reactor.core.publisher.Flux;
3437

3538
import org.springframework.beans.factory.annotation.Autowired;
@@ -56,6 +59,7 @@
5659

5760
/**
5861
* @author Dave Syer
62+
* @author Chris Bono
5963
*/
6064
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=servlet")
6165
@ContextConfiguration(classes = { RestApplication.class, ApplicationConfiguration.class })
@@ -124,6 +128,18 @@ public void word() throws Exception {
124128
assertThat(result.getBody()).isEqualTo("foo");
125129
}
126130

131+
// TODO: Once bug is fixed this test (last entry) will fully pass and this COMMENT should be removed
132+
@ParameterizedTest
133+
@ValueSource(strings = {"[hello", "hello]", "[hello]"})
134+
void textContentTypeWithValueWrappedBracketsIsOk(String inputMessagePayloadValue) throws URISyntaxException {
135+
ResponseEntity<String> postForEntity = this.rest
136+
.exchange(RequestEntity.post(new URI("/echo"))
137+
.contentType(MediaType.TEXT_PLAIN)
138+
.body(inputMessagePayloadValue), String.class);
139+
assertThat(postForEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
140+
assertThat(postForEntity.getBody()).isEqualTo(inputMessagePayloadValue);
141+
}
142+
127143
@Test
128144
public void foos() throws Exception {
129145
ResponseEntity<String> result = this.rest
@@ -301,6 +317,11 @@ public Supplier<String> word() {
301317
return () -> "foo";
302318
}
303319

320+
@Bean
321+
public Function<String, String> echo() {
322+
return (input) -> input;
323+
}
324+
304325
@Bean
305326
public Supplier<Flux<Foo>> foos() {
306327
return () -> Flux.just(new Foo("foo"), new Foo("bar"));

0 commit comments

Comments
 (0)