<commit_before>package com.github.wkennedy.controllers;

import com.github.wkennedy.dto.Person;
import com.github.wkennedy.services.SimpleService;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.FluxExchangeResult;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Flux;

import java.net.URISyntaxException;
import java.time.Duration;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@AutoConfigureWebTestClient
//@WebFluxTest
//@Ignore
public class SimpleReactiveControllerTest {

    private WebTestClient webTestClient;

    @Autowired
    private SimpleService simpleService;

    @Before
    public void before() {
//        this.webTestClient = WebTestClient.bindToServer().baseUrl("http://127.0.0.1:8080").build();
        this.webTestClient = WebTestClient.bindToController(new SimpleReactiveController(simpleService)).build();
    }

    @Test
    public void getReactPersons() throws Exception {
        Flux<Person> personFlux = webTestClient
                .get().uri("/react/persons")
                .accept(MediaType.APPLICATION_JSON) // text/event-stream or application/stream+json
                .exchange().expectStatus().is2xxSuccessful()
                .expectBody(Person.class).returnResult().getResponseBody().cast(Person.class);

        personFlux.delaySubscription(Duration.ofSeconds(2)).toStream().forEach(System.out::println);
    }

    @Test
    @Ignore
    public void getStreamingPersons() throws URISyntaxException {
        FluxExchangeResult<Person> personResult = webTestClient.get().uri("/react/persons/delay/300").accept(MediaType.APPLICATION_STREAM_JSON)
                .exchange().expectStatus().is2xxSuccessful()
                .expectHeader().contentType(MediaType.parseMediaType("application/stream+json;charset=UTF-8"))
                .expectBody(Person.class).returnResult();

        personResult.getResponseBody().toStream().forEach(person -> System.out.println("WebTestClient: " + person.toString()));<commit_msg>Updated formatting<commit_after>package com.github.wkennedy.controllers;

import com.github.wkennedy.dto.Person;
import com.github.wkennedy.services.SimpleService;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.FluxExchangeResult;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Flux;

import java.net.URISyntaxException;
import java.time.Duration;

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@AutoConfigureWebTestClient
@WebFluxTest
public class SimpleReactiveControllerTest {

    private WebTestClient webTestClient;

    @Autowired
    private SimpleService simpleService;

    @Before
    public void before() {
//        this.webTestClient = WebTestClient.bindToServer().baseUrl("http://127.0.0.1:8080").build();
        this.webTestClient = WebTestClient.bindToController(new SimpleReactiveController(simpleService)).build();
    }

    @Test
    public void getReactPersons() throws Exception {
        Flux<Person> personFlux = webTestClient
                .get().uri("/react/persons")
                .accept(MediaType.APPLICATION_JSON) // text/event-stream or application/stream+json
                .exchange().expectStatus().is2xxSuccessful()
                .expectBody(Person.class).returnResult().getResponseBody().cast(Person.class);

        personFlux.delaySubscription(Duration.ofSeconds(2)).toStream().forEach(System.out::println);
    }

    @Test
    @Ignore
    public void getStreamingPersons() throws URISyntaxException {
        FluxExchangeResult<Person> personResult = webTestClient.get().uri("/react/persons/delay/300")
                .accept(MediaType.APPLICATION_STREAM_JSON) //application/stream+json
                .exchange().expectStatus().is2xxSuccessful()
                .expectHeader().contentType(MediaType.parseMediaType("application/stream+json;charset=UTF-8"))
                .expectBody(Person.class).returnResult();

        personResult.getResponseBody().toStream()
                .forEach(person -> System.out.println("WebTestClient: " + person.toString()));
{'fraction_non_alphanumeric': 0.1151597817614965, 'fraction_numerical': 0.007014809041309431, 'mean_word_length': 4.324688796680498, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3962368', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1407, 'n_words': 188}