Skip to content

Instantly share code, notes, and snippets.

@making
Created July 30, 2014 15:40
Show Gist options
  • Save making/ec27245846affa454b45 to your computer and use it in GitHub Desktop.
Save making/ec27245846affa454b45 to your computer and use it in GitHub Desktop.
package com.example;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.IntegrationTest;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = App.class)
@WebAppConfiguration
@IntegrationTest("server.port:0")
public class AppTest {
@Value("${local.server.port}")
int port;
RestTemplate restTemplate = new TestRestTemplate();
@Test
public void testHome() {
ResponseEntity<String> response = restTemplate.getForEntity(
"http://localhost:" + port, String.class);
assertThat(response.getStatusCode(), is(HttpStatus.OK));
assertThat(response.getBody(), is("Hello World!"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment