package hello.controllers;

import static org.hamcrest.core.StringContains.containsString;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;

import hello.Application;
import hello.models.Greeting;
import hello.services.GreetingService;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@AutoConfigureMockMvc
public class GreetingControllerTest {

	@Autowired
	private MockMvc mvc;

	@Autowired
	private GreetingService greetingService;

	@Before
	public void setUp() {
		greetingService.save(new Greeting("Hello, %s!"));
	}

	@Test
	public void getGreeting() throws Exception {
		mvc.perform(MockMvcRequestBuilders.get("/greeting/1").accept(MediaType.TEXT_HTML)).andExpect(status().isOk())
		.andExpect(content().string(containsString("Hello, World!"))).andExpect(view().name("greeting"));
	}

	@Test
	public void getJsonGreeting() throws Exception {
		mvc.perform(MockMvcRequestBuilders.get("/greeting/1").accept(MediaType.APPLICATION_JSON))
		.andExpect(status().isNotAcceptable());
	}

	@Test
	public void getGreetingName() throws Exception {
		mvc.perform(MockMvcRequestBuilders.get("/greeting/1?name=Rob").accept(MediaType.TEXT_HTML))
				.andExpect(status().isOk()).andExpect(content().string(containsString("Hello, Rob!")))
				.andExpect(view().name("greeting"));
	}

	@Test
	public void getJsonGreetingName() throws Exception {
		mvc.perform(MockMvcRequestBuilders.get("/greeting/1?name=Rob").accept(MediaType.APPLICATION_JSON))
		.andExpect(status().isNotAcceptable());
	}

}

@@ -1533,32 +1533,37 @@
 ).name(%22greeting
+/show
 %22));%0A%09%7D%0A%0A%09@Test%0A
@@ -1901,18 +1901,16 @@
 _HTML))%0A
-%09%09
 %09%09.andEx
@@ -1990,18 +1990,16 @@
 ob!%22)))%0A
-%09%09
 %09%09.andEx
@@ -2024,16 +2024,21 @@
 greeting
+/show
 %22));%0A%09%7D%0A

Fix tests now views have changed.