コード例 #1
0
  @Test
  public void decode() {
    DataBuffer fooBuffer = stringBuffer("foo");
    DataBuffer barBuffer = stringBuffer("bar");
    Flux<DataBuffer> source = Flux.just(fooBuffer, barBuffer);
    Flux<ByteBuffer> output =
        this.decoder.decode(
            source,
            ResolvableType.forClassWithGenerics(Publisher.class, ByteBuffer.class),
            null,
            Collections.emptyMap());

    StepVerifier.create(output)
        .expectNext(ByteBuffer.wrap("foo".getBytes()), ByteBuffer.wrap("bar".getBytes()))
        .expectComplete()
        .verify();
  }
コード例 #2
0
  @Test
  public void render() throws Exception {
    Map<String, String> pojoData = new LinkedHashMap<>();
    pojoData.put("foo", "f");
    pojoData.put("bar", "b");
    this.model.addAttribute("pojoData", pojoData);
    this.view.setModelKeys(Collections.singleton("pojoData"));

    MockServerHttpRequest request = new MockServerHttpRequest(HttpMethod.GET, "/path");
    MockServerHttpResponse response = new MockServerHttpResponse();
    WebSessionManager manager = new DefaultWebSessionManager();
    ServerWebExchange exchange = new DefaultServerWebExchange(request, response, manager);

    this.view.render(this.model, MediaType.APPLICATION_JSON, exchange);

    StepVerifier.create(response.getBody())
        .consumeNextWith(
            buf ->
                assertEquals(
                    "{\"foo\":\"f\",\"bar\":\"b\"}",
                    DataBufferTestUtils.dumpString(buf, StandardCharsets.UTF_8)))
        .expectComplete()
        .verify();
  }