Migrate to JUnit 5
spring-cloud-function-context spring-cloud-function-context: fix spring-cloud-function-web spring-cloud-function-adapters spring-cloud-function-samples spring-cloud-function-deployer; spring-cloud-function-kotlin Resolves #535
This commit is contained in:
committed by
Oleg Zhurakousky
parent
6ea91a77a8
commit
dfa02750c1
@@ -18,7 +18,7 @@ package org.springframework.cloud.function.context;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuple3;
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.cloud.function.context;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
|
||||
@@ -21,9 +21,10 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
@@ -33,8 +34,6 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -46,7 +45,7 @@ public class SpringFunctionAdapterInitializerTests {
|
||||
|
||||
private AbstractSpringFunctionAdapterInitializer<Object> initializer;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
System.clearProperty("function.name");
|
||||
if (this.initializer != null) {
|
||||
@@ -54,11 +53,12 @@ public class SpringFunctionAdapterInitializerTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void nullSource() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(null) {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(null) {
|
||||
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +106,7 @@ public class SpringFunctionAdapterInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // related to boot 2.1 no bean override change
|
||||
@Disabled // related to boot 2.1 no bean override change
|
||||
public void functionRegistrar() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FunctionRegistrar.class) {
|
||||
|
||||
|
||||
@@ -24,8 +24,8 @@ import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
@@ -100,7 +100,7 @@ public class BeanFactoryAwareFunctionRegistryMultiInOutTests {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void testMultiInputBiFunction() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
BiFunction<Flux<String>, Flux<Integer>, Flux<String>> multiInputFunction =
|
||||
|
||||
@@ -28,9 +28,10 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
@@ -78,7 +79,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
return catalog;
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
System.clearProperty("spring.cloud.function.definition");
|
||||
}
|
||||
@@ -156,7 +157,7 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
* - the input wrapper must match the output wrapper (e.g., <Flux, Flux> or <Mono, Mono>)
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void testImperativeVoidInputFunction() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
|
||||
@@ -245,11 +246,13 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
* Further more, such flux will need to be triggered (e.g., subscribe(..) )
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Test(expected = ClassCastException.class)
|
||||
@Test
|
||||
public void testReactiveFunctionWithImperativeInputAndOutputFail() {
|
||||
FunctionCatalog catalog = this.configureCatalog();
|
||||
Function<String, String> reverse = catalog.lookup("reverseFlux");
|
||||
String result = reverse.apply("reverseFlux");
|
||||
Assertions.assertThrows(ClassCastException.class, () -> {
|
||||
String result = reverse.apply("reverseFlux");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.springframework.cloud.function.context.catalog;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
@@ -56,7 +56,7 @@ public class SimpleFunctionRegistryTests {
|
||||
|
||||
private ConversionService conversionService;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
List<MessageConverter> messageConverters = new ArrayList<>();
|
||||
JsonMapper jsonMapper = new GsonMapper(new Gson());
|
||||
@@ -121,7 +121,7 @@ public class SimpleFunctionRegistryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void testFunctionCompletelyImplicitComposition() {
|
||||
FunctionRegistration<Words> wordsRegistration = new FunctionRegistration<>(
|
||||
new Words(), "words").type(FunctionType.of(Words.class));
|
||||
|
||||
@@ -27,9 +27,9 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -88,7 +88,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
ContextFunctionCatalogAutoConfigurationTests.value = value.toString();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
@@ -119,7 +119,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
// do we really need this test and behavior? What does this even mean?
|
||||
public void ambiguousFunction() {
|
||||
create(AmbiguousConfiguration.class);
|
||||
@@ -137,7 +137,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void configurationFunction() {
|
||||
create(FunctionConfiguration.class);
|
||||
assertThat(this.context.getBean("foos")).isInstanceOf(Function.class);
|
||||
@@ -293,7 +293,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test//(expected = IllegalArgumentException.class)
|
||||
@Test
|
||||
public void monoToMonoNonVoidFunction() {
|
||||
create(MonoToMonoNonVoidConfiguration.class);
|
||||
assertThat(this.context.getBean("function")).isInstanceOf(Function.class);
|
||||
@@ -369,7 +369,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void singletonMessageFunction() {
|
||||
create(SingletonMessageConfiguration.class);
|
||||
assertThat(this.context.getBean("function")).isInstanceOf(Function.class);
|
||||
@@ -474,7 +474,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void simpleSupplier() {
|
||||
create(SimpleConfiguration.class);
|
||||
assertThat(this.context.getBean("supplier")).isInstanceOf(Supplier.class);
|
||||
@@ -493,7 +493,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void qualifiedBean() {
|
||||
create(QualifiedConfiguration.class);
|
||||
assertThat(this.context.getBean("function")).isInstanceOf(Function.class);
|
||||
@@ -517,7 +517,7 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void registrationBean() {
|
||||
create(RegistrationConfiguration.class);
|
||||
assertThat(this.context.getBean("function")).isInstanceOf(Function.class);
|
||||
|
||||
@@ -26,9 +26,10 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -61,7 +62,7 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
|
||||
private FunctionInspector inspector;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
@@ -102,7 +103,7 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
public void compose() {
|
||||
create(SimpleConfiguration.class);
|
||||
assertThat(this.context.getBean("function"))
|
||||
@@ -115,14 +116,16 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
// TODO: support for function composition
|
||||
}
|
||||
|
||||
@Test(expected = BeanCreationException.class)
|
||||
@Test
|
||||
public void missingType() {
|
||||
create(MissingTypeConfiguration.class);
|
||||
assertThat(this.context.getBean("function"))
|
||||
Assertions.assertThrows(BeanCreationException.class, () -> {
|
||||
create(MissingTypeConfiguration.class);
|
||||
assertThat(this.context.getBean("function"))
|
||||
.isInstanceOf(FunctionRegistration.class);
|
||||
assertThat((Function<?, ?>) this.catalog.lookup(Function.class, "function"))
|
||||
assertThat((Function<?, ?>) this.catalog.lookup(Function.class, "function"))
|
||||
.isInstanceOf(Function.class);
|
||||
// TODO: support for type inference from functional bean registrations
|
||||
// TODO: support for type inference from functional bean registrations
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@ package org.springframework.cloud.function.context.config;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -33,7 +34,6 @@ import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -44,7 +44,7 @@ public class RoutingFunctionTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void before() {
|
||||
System.clearProperty("spring.cloud.function.definition");
|
||||
System.clearProperty("spring.cloud.function.routing-expression");
|
||||
@@ -55,8 +55,7 @@ public class RoutingFunctionTests {
|
||||
context = new SpringApplicationBuilder(RoutingFunctionConfiguration.class).run(
|
||||
"--logging.level.org.springframework.cloud.function=DEBUG",
|
||||
"--spring.cloud.function.routing.enabled=true");
|
||||
FunctionCatalog catalog = context.getBean(FunctionCatalog.class);
|
||||
return catalog;
|
||||
return context.getBean(FunctionCatalog.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -82,7 +81,7 @@ public class RoutingFunctionTests {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test(expected = Exception.class)
|
||||
@Test
|
||||
public void testRoutingReactiveInputWithReactiveFunctionAndDefinitionMessageHeader() {
|
||||
FunctionCatalog functionCatalog = this.configureCatalog();
|
||||
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
|
||||
@@ -90,11 +89,11 @@ public class RoutingFunctionTests {
|
||||
Message<String> message = MessageBuilder.withPayload("hello")
|
||||
.setHeader(FunctionProperties.PREFIX + ".definition", "echoFlux").build();
|
||||
Flux resultFlux = (Flux) function.apply(Flux.just(message));
|
||||
resultFlux.subscribe();
|
||||
Assertions.assertThrows(Exception.class, resultFlux::subscribe);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test(expected = Exception.class)
|
||||
@Test
|
||||
public void testRoutingReactiveInputWithReactiveFunctionAndExpressionMessageHeader() {
|
||||
FunctionCatalog functionCatalog = this.configureCatalog();
|
||||
Function function = functionCatalog.lookup(RoutingFunction.FUNCTION_NAME);
|
||||
@@ -102,7 +101,7 @@ public class RoutingFunctionTests {
|
||||
Message<String> message = MessageBuilder.withPayload("hello")
|
||||
.setHeader(FunctionProperties.PREFIX + ".routing-expression", "'echoFlux'").build();
|
||||
Flux resultFlux = (Flux) function.apply(Flux.just(message));
|
||||
resultFlux.subscribe();
|
||||
Assertions.assertThrows(Exception.class, resultFlux::subscribe);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@@ -135,7 +134,7 @@ public class RoutingFunctionTests {
|
||||
// no function.definition header or function property
|
||||
try {
|
||||
function.apply(MessageBuilder.withPayload("hello").build());
|
||||
fail();
|
||||
Assertions.fail();
|
||||
}
|
||||
catch (Exception e) {
|
||||
//ignore
|
||||
@@ -144,7 +143,7 @@ public class RoutingFunctionTests {
|
||||
// non existing function
|
||||
try {
|
||||
function.apply(MessageBuilder.withPayload("hello").setHeader(FunctionProperties.PREFIX + ".definition", "blah").build());
|
||||
fail();
|
||||
Assertions.fail();
|
||||
}
|
||||
catch (Exception e) {
|
||||
//ignore
|
||||
@@ -176,7 +175,7 @@ public class RoutingFunctionTests {
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase() {
|
||||
return v -> v.toUpperCase();
|
||||
return String::toUpperCase;
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -18,14 +18,12 @@ package org.springframework.cloud.function.context.string;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -35,7 +33,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
// @checkstyle:off
|
||||
@FunctionalSpringBootTest(classes = Object.class, properties = "spring.main.sources=org.springframework.cloud.function.context.string.FunctionalStringSourceTests.TestConfiguration")
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -18,14 +18,12 @@ package org.springframework.cloud.function.context.test;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -33,7 +31,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@FunctionalSpringBootTest
|
||||
public class FunctionalTests {
|
||||
|
||||
|
||||
@@ -16,15 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.function.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.cloud.function.json.GsonMapper;
|
||||
import org.springframework.cloud.function.json.JacksonMapper;
|
||||
@@ -38,70 +36,68 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public class JsonMapperTests {
|
||||
|
||||
private JsonMapper mapper;
|
||||
|
||||
public JsonMapperTests(JsonMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
public static Stream<JsonMapper> params() {
|
||||
return Stream.of(new GsonMapper(new Gson()), new JacksonMapper(new ObjectMapper()));
|
||||
}
|
||||
|
||||
@Parameters
|
||||
public static List<Object[]> params() {
|
||||
return Arrays.asList(new Object[] { new GsonMapper(new Gson()) },
|
||||
new Object[] { new JacksonMapper(new ObjectMapper()) });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaArray() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void vanillaArray(JsonMapper mapper) {
|
||||
String json = "[{\"value\":\"foo\"},{\"value\":\"foo\"}]";
|
||||
List<Foo> list = this.mapper.fromJson(json,
|
||||
List<Foo> list = mapper.fromJson(json,
|
||||
ResolvableType.forClassWithGenerics(List.class, Foo.class).getType());
|
||||
assertThat(list).hasSize(2);
|
||||
assertThat(list.get(0).getValue()).isEqualTo("foo");
|
||||
assertThat(this.mapper.toString(list)).isEqualTo(json);
|
||||
assertThat(mapper.toString(list)).isEqualTo(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intArray() {
|
||||
List<Integer> list = this.mapper.fromJson("[123,456]",
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void intArray(JsonMapper mapper) {
|
||||
List<Integer> list = mapper.fromJson("[123,456]",
|
||||
ResolvableType.forClassWithGenerics(List.class, Integer.class).getType());
|
||||
assertThat(list).hasSize(2);
|
||||
assertThat(list.get(0)).isEqualTo(123);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyArray() {
|
||||
List<Foo> list = this.mapper.fromJson("[]",
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void emptyArray(JsonMapper mapper) {
|
||||
List<Foo> list = mapper.fromJson("[]",
|
||||
ResolvableType.forClassWithGenerics(List.class, Foo.class).getType());
|
||||
assertThat(list).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vanillaObject() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void vanillaObject(JsonMapper mapper) {
|
||||
String json = "{\"value\":\"foo\"}";
|
||||
Foo foo = this.mapper.fromJson(json, Foo.class);
|
||||
Foo foo = mapper.fromJson(json, Foo.class);
|
||||
assertThat(foo.getValue()).isEqualTo("foo");
|
||||
assertThat(this.mapper.toString(foo)).isEqualTo(json);
|
||||
assertThat(mapper.toString(foo)).isEqualTo(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringRepresentingJson() {
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void stringRepresentingJson(JsonMapper mapper) {
|
||||
String json = "{\"value\":\"foo\"}";
|
||||
byte[] bytes = this.mapper.toJson(json);
|
||||
byte[] bytes = mapper.toJson(json);
|
||||
assertThat(new String(bytes)).isEqualTo(json);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void intValue() {
|
||||
int foo = this.mapper.fromJson("123", Integer.class);
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void intValue(JsonMapper mapper) {
|
||||
int foo = mapper.fromJson("123", Integer.class);
|
||||
assertThat(foo).isEqualTo(123);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void empty() {
|
||||
Foo foo = this.mapper.fromJson("{}", Foo.class);
|
||||
@ParameterizedTest
|
||||
@MethodSource("params")
|
||||
public void empty(JsonMapper mapper) {
|
||||
Foo foo = mapper.fromJson("{}", Foo.class);
|
||||
assertThat(foo.getValue()).isNull();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user