spring-boot/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTes...

48 lines
1.5 KiB
Java
Raw Normal View History

package sample.data.jpa;
2013-04-24 17:02:07 +08:00
import org.junit.Before;
2013-04-24 17:02:07 +08:00
import org.junit.Test;
2013-10-03 03:07:04 +08:00
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
2013-10-03 03:07:04 +08:00
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
2013-04-24 17:02:07 +08:00
2014-01-22 06:37:18 +08:00
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
2013-04-24 17:02:07 +08:00
/**
* Integration test to run the application.
2014-07-03 05:43:43 +08:00
*
* @author Oliver Gierke
2013-04-24 17:02:07 +08:00
*/
2013-10-03 03:07:04 +08:00
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = SampleDataJpaApplication.class)
2013-10-03 03:07:04 +08:00
@WebAppConfiguration
2013-11-16 15:42:40 +08:00
@ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
2013-10-03 03:07:04 +08:00
public class SampleDataJpaApplicationTests {
2013-04-24 17:02:07 +08:00
@Autowired
private WebApplicationContext context;
2013-04-24 17:02:07 +08:00
private MockMvc mvc;
2013-04-24 17:02:07 +08:00
@Before
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
2013-04-24 17:02:07 +08:00
}
@Test
public void testHome() throws Exception {
this.mvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string("Bath"));
2013-04-24 17:02:07 +08:00
}
}