package sample.ui; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.IntegrationTest; import org.springframework.boot.test.RestTemplates; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; /** * Basic integration tests for demo application. * * @author Dave Syer */ @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes=SampleWebStaticApplication.class) @WebAppConfiguration @IntegrationTest @DirtiesContext public class SampleWebStaticApplicationTests { @Test public void testHome() throws Exception { ResponseEntity entity = RestTemplates.get().getForEntity( "http://localhost:8080", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), entity .getBody().contains("Static")); } @Test public void testCss() throws Exception { ResponseEntity<String> entity = RestTemplates.get().getForEntity( "http://localhost:8080/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class); assertEquals(HttpStatus.OK, entity.getStatusCode()); assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), MediaType.valueOf("text/css"), entity.getHeaders().getContentType()); } }