Search in sources :

Example 21 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class MapBinderTests method bindToMapShouldBindToMapValue.

@Test
void bindToMapShouldBindToMapValue() {
    ResolvableType type = ResolvableType.fromClassWithGenerics(Map.class, ResolvableType.fromClass(String.class), STRING_INTEGER_MAP.getType());
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.bar.baz", "1");
    source.put("foo.bar.bin", "2");
    source.put("foo.far.baz", "3");
    source.put("foo.far.bin", "4");
    source.put("faf.far.bin", "x");
    this.sources.add(source);
    Map<String, Map<String, Integer>> result = this.binder.bind("foo", Bindable.<Map<String, Map<String, Integer>>>of(type)).get();
    assertThat(result).hasSize(2);
    assertThat(result.get("bar")).containsEntry("baz", 1).containsEntry("bin", 2);
    assertThat(result.get("far")).containsEntry("baz", 3).containsEntry("bin", 4);
}
Also used : MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) ResolvableType(cn.taketoday.core.ResolvableType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 22 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class MapBinderTests method bindToMapShouldBindNestedMapValue.

@Test
void bindToMapShouldBindNestedMapValue() {
    ResolvableType nestedType = ResolvableType.fromClassWithGenerics(Map.class, ResolvableType.fromClass(String.class), STRING_INTEGER_MAP.getType());
    ResolvableType type = ResolvableType.fromClassWithGenerics(Map.class, ResolvableType.fromClass(String.class), nestedType);
    MockConfigurationPropertySource source = new MockConfigurationPropertySource();
    source.put("foo.nested.bar.baz", "1");
    source.put("foo.nested.bar.bin", "2");
    source.put("foo.nested.far.baz", "3");
    source.put("foo.nested.far.bin", "4");
    source.put("faf.nested.far.bin", "x");
    this.sources.add(source);
    Bindable<Map<String, Map<String, Map<String, Integer>>>> target = Bindable.of(type);
    Map<String, Map<String, Map<String, Integer>>> result = this.binder.bind("foo", target).get();
    Map<String, Map<String, Integer>> nested = result.get("nested");
    assertThat(nested).hasSize(2);
    assertThat(nested.get("bar")).containsEntry("baz", 1).containsEntry("bin", 2);
    assertThat(nested.get("far")).containsEntry("baz", 3).containsEntry("bin", 4);
}
Also used : MockConfigurationPropertySource(cn.taketoday.context.properties.source.MockConfigurationPropertySource) ResolvableType(cn.taketoday.core.ResolvableType) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 23 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class BindableTests method ofTypeShouldSetType.

@Test
void ofTypeShouldSetType() {
    ResolvableType type = ResolvableType.fromClass(String.class);
    assertThat(Bindable.of(type).getType()).isEqualTo(type);
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 24 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2CborEncoderTests method canEncode.

@Test
public void canEncode() {
    ResolvableType pojoType = ResolvableType.fromClass(Pojo.class);
    assertThat(this.encoder.canEncode(pojoType, CBOR_MIME_TYPE)).isTrue();
    assertThat(this.encoder.canEncode(pojoType, null)).isTrue();
    // SPR-15464
    assertThat(this.encoder.canEncode(ResolvableType.NONE, null)).isTrue();
}
Also used : ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Example 25 with ResolvableType

use of cn.taketoday.core.ResolvableType in project today-infrastructure by TAKETODAY.

the class Jackson2CborEncoderTests method encodeStream.

@Test
public void encodeStream() {
    Pojo pojo1 = new Pojo("foo", "bar");
    Pojo pojo2 = new Pojo("foofoo", "barbar");
    Pojo pojo3 = new Pojo("foofoofoo", "barbarbar");
    Flux<Pojo> input = Flux.just(pojo1, pojo2, pojo3);
    ResolvableType type = ResolvableType.fromClass(Pojo.class);
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> encoder.encode(input, this.bufferFactory, type, CBOR_MIME_TYPE, null));
}
Also used : Pojo(cn.taketoday.http.codec.Pojo) ResolvableType(cn.taketoday.core.ResolvableType) Test(org.junit.jupiter.api.Test)

Aggregations

ResolvableType (cn.taketoday.core.ResolvableType)159 Test (org.junit.jupiter.api.Test)106 DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)30 Map (java.util.Map)24 Pojo (cn.taketoday.http.codec.Pojo)20 List (java.util.List)16 MediaType (cn.taketoday.http.MediaType)15 MockConfigurationPropertySource (cn.taketoday.context.properties.source.MockConfigurationPropertySource)14 Flux (reactor.core.publisher.Flux)12 Mono (reactor.core.publisher.Mono)10 Resource (cn.taketoday.core.io.Resource)8 Nullable (cn.taketoday.lang.Nullable)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 MultiValueMap (cn.taketoday.core.MultiValueMap)6 ReactiveHttpOutputMessage (cn.taketoday.http.ReactiveHttpOutputMessage)6 ServerSentEvent (cn.taketoday.http.codec.ServerSentEvent)6 MimeType (cn.taketoday.util.MimeType)6 Arrays (java.util.Arrays)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5