Search in sources :

Example 81 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method rxJava2SingleTestBean.

@Test
public void rxJava2SingleTestBean() throws Exception {
    String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
    ResolvableType type = forClassWithGenerics(io.reactivex.Single.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    io.reactivex.Single<TestBean> single = resolveValue(param, body);
    assertEquals(new TestBean("f1", "b1"), single.blockingGet());
}
Also used : ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 82 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method map.

@Test
public void map() throws Exception {
    String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
    Map<String, String> map = new HashMap<>();
    map.put("foo", "f1");
    map.put("bar", "b1");
    ResolvableType type = forClassWithGenerics(Map.class, String.class, String.class);
    MethodParameter param = this.testMethod.arg(type);
    Map<String, String> actual = resolveValue(param, body);
    assertEquals(map, actual);
}
Also used : HashMap(java.util.HashMap) ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 83 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method rxJava2ObservableTestBean.

@Test
public void rxJava2ObservableTestBean() throws Exception {
    String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
    ResolvableType type = forClassWithGenerics(io.reactivex.Observable.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    io.reactivex.Observable<?> observable = resolveValue(param, body);
    assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")), observable.toList().blockingGet());
}
Also used : ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 84 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method flowableTestBean.

@Test
public void flowableTestBean() throws Exception {
    String body = "[{\"bar\":\"b1\",\"foo\":\"f1\"},{\"bar\":\"b2\",\"foo\":\"f2\"}]";
    ResolvableType type = forClassWithGenerics(Flowable.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    Flowable<?> flowable = resolveValue(param, body);
    assertEquals(Arrays.asList(new TestBean("f1", "b1"), new TestBean("f2", "b2")), flowable.toList().blockingGet());
}
Also used : ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 85 with ResolvableType

use of org.springframework.core.ResolvableType in project spring-framework by spring-projects.

the class MessageReaderArgumentResolverTests method rxJava2MaybeTestBean.

@Test
public void rxJava2MaybeTestBean() throws Exception {
    String body = "{\"bar\":\"b1\",\"foo\":\"f1\"}";
    ResolvableType type = forClassWithGenerics(Maybe.class, TestBean.class);
    MethodParameter param = this.testMethod.arg(type);
    Maybe<TestBean> maybe = resolveValue(param, body);
    assertEquals(new TestBean("f1", "b1"), maybe.blockingGet());
}
Also used : ResolvableType(org.springframework.core.ResolvableType) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Aggregations

ResolvableType (org.springframework.core.ResolvableType)96 Test (org.junit.Test)66 MethodParameter (org.springframework.core.MethodParameter)20 DataBuffer (org.springframework.core.io.buffer.DataBuffer)15 ServerWebExchange (org.springframework.web.server.ServerWebExchange)14 List (java.util.List)11 MediaType (org.springframework.http.MediaType)10 Flux (reactor.core.publisher.Flux)10 Mono (reactor.core.publisher.Mono)10 Map (java.util.Map)9 Assert (org.springframework.util.Assert)7 Collections (java.util.Collections)6 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)6 ArrayList (java.util.ArrayList)5 ReactiveAdapter (org.springframework.core.ReactiveAdapter)5 Pojo (org.springframework.http.codec.Pojo)5 ServerWebInputException (org.springframework.web.server.ServerWebInputException)5 Publisher (org.reactivestreams.Publisher)4 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)4 Single (rx.Single)4