package de.springbootbuch.reactive.filmstore;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
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 static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.MOCK;
import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
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.test.StepVerifier;

/**
 * Part of springbootbuch.de.
 * 
 * @author Michael J. Simons
 * @author @rotnroll666
 */
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = MOCK)
@AutoConfigureWebTestClient
public class FilmRestControllerTest {
	
	@Autowired
	private WebTestClient client;
	
	@Test
	public void filmApiShouldWork() {
		FluxExchangeResult<Film> result = client.get()
			.uri("/api/films")
			.accept(TEXT_EVENT_STREAM)
			.exchange()
			.expectStatus().isOk()
			.expectHeader().contentType(TEXT_EVENT_STREAM)
			.returnResult(Film.class);
		
		StepVerifier.create(result.getResponseBody())				
			.consumeNextWith(film -> 
				assertThat(film.getTitle(), 
					is("ACADEMY DINOSAUR"))
			)
			.expectNextCount(9)
			.expectComplete()
			.verify();
	}
}

@@ -751,24 +751,132 @@
 TestClient;%0A
+import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;%0A
 import react
@@ -897,16 +897,16 @@
 rifier;%0A
-
 %0A/**%0A * 
@@ -934,17 +934,16 @@
 h.de.%0A *
- 
 %0A * @aut
@@ -1126,18 +1126,17 @@
 rTest %7B%0A
-%09
 %0A
+
 %09@Autowi
@@ -1170,18 +1170,17 @@
 client;%0A
-%09
 %0A
+
 %09@Test%0A%09
@@ -1255,16 +1255,69 @@
 = client
+%0A%09%09%09.filter(basicAuthentication(%22spring%22,%22boot%22))%0A%09%09%09
 .get()%0A%09
@@ -1488,18 +1488,16 @@
 class);%0A
-%09%09
 %0A%09%09StepV
@@ -1536,20 +1536,16 @@
 eBody())
-%09%09%09%09
 %0A%09%09%09.con
@@ -1564,17 +1564,16 @@
 (film -%3E
- 
 %0A%09%09%09%09ass
@@ -1596,17 +1596,16 @@
 Title(),
- 
 %0A%09%09%09%09%09is

Fix failing tests