package hello.controllers;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.core.StringContains.containsString;
import static org.junit.Assert.assertThat;

import java.net.MalformedURLException;
import java.net.URL;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import hello.configuration.Application;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class GreetingControllerIntegrationTest {

	@LocalServerPort
	private int port;

	private URL greeting;

	@Autowired
	private TestRestTemplate template;

	@Before
	public void setUp() throws MalformedURLException {
		this.greeting = new URL("http://localhost:" + port + "/greeting");
	}

	@Test
	public void getGreeting() {
		ResponseEntity<String> response = template.getForEntity(greeting.toString(), String.class);
		assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));
		assertThat(response.getBody(), containsString("Hello, World!"));
	}

}

@@ -1010,16 +1010,43 @@
 reeting;
+%0A%09private URL greetingName;
 %0A%0A%09@Auto
@@ -1155,32 +1155,21 @@
 %7B%0A%09%09
-this.greeting = new URL(
+String url = 
 %22htt
@@ -1204,16 +1204,97 @@
 reeting%22
+;%0A%09%09this.greeting = new URL(url);%0A%09%09this.greetingName = new URL(url + %22?name=Rob%22
 );%0A%09%7D%0A%0A%09
@@ -1557,10 +1557,280 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09public void getGreetingName() %7B%0A%09%09ResponseEntity%3CString%3E response = template.getForEntity(greetingName.toString(), String.class);%0A%09%09assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));%0A%09%09assertThat(response.getBody(), containsString(%22Hello, Rob!%22));%0A%09%7D%0A
 %7D%0A

Add an integration test with name parameter.