2013-12-31 16:40:21 +08:00
|
|
|
package sample.data.jpa;
|
2013-04-24 17:02:07 +08:00
|
|
|
|
2014-11-03 21:28:26 +08:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
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;
|
|
|
|
|
|
|
|
import java.lang.management.ManagementFactory;
|
|
|
|
|
|
|
|
import javax.management.ObjectName;
|
|
|
|
|
2013-08-03 01:12:17 +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;
|
2013-08-03 01:12:17 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2013-11-28 22:35:36 +08:00
|
|
|
import org.springframework.boot.test.SpringApplicationConfiguration;
|
2013-10-03 03:07:04 +08:00
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
2014-11-03 21:28:26 +08:00
|
|
|
import org.springframework.test.context.TestPropertySource;
|
2013-10-03 03:07:04 +08:00
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
import org.springframework.test.context.web.WebAppConfiguration;
|
2013-08-03 01:12:17 +08:00
|
|
|
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
|
|
|
|
|
|
|
/**
|
2013-08-03 01:12:17 +08:00
|
|
|
* Integration test to run the application.
|
2014-07-03 05:43:43 +08:00
|
|
|
*
|
2013-08-03 01:12:17 +08:00
|
|
|
* @author Oliver Gierke
|
2014-11-03 21:28:26 +08:00
|
|
|
* @author Dave Syer
|
2013-04-24 17:02:07 +08:00
|
|
|
*/
|
2013-10-03 03:07:04 +08:00
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
2013-11-28 22:35:36 +08:00
|
|
|
@SpringApplicationConfiguration(classes = SampleDataJpaApplication.class)
|
2013-10-03 03:07:04 +08:00
|
|
|
@WebAppConfiguration
|
2014-11-03 21:28:26 +08:00
|
|
|
// Enable JMX so we can test the MBeans (you can't do this in a properties file)
|
|
|
|
@TestPropertySource(properties="spring.jmx.enabled:true")
|
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
|
|
|
|
2013-08-03 01:12:17 +08:00
|
|
|
@Autowired
|
|
|
|
private WebApplicationContext context;
|
2013-04-24 17:02:07 +08:00
|
|
|
|
2013-08-03 01:12:17 +08:00
|
|
|
private MockMvc mvc;
|
2013-04-24 17:02:07 +08:00
|
|
|
|
2013-08-03 01:12:17 +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 {
|
|
|
|
|
2013-08-03 01:12:17 +08:00
|
|
|
this.mvc.perform(get("/")).andExpect(status().isOk())
|
|
|
|
.andExpect(content().string("Bath"));
|
2013-04-24 17:02:07 +08:00
|
|
|
}
|
2014-11-03 21:28:26 +08:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testJmx() throws Exception {
|
|
|
|
assertEquals(1, ManagementFactory.getPlatformMBeanServer().queryMBeans(
|
|
|
|
new ObjectName("jpa.sample:type=ConnectionPool,*"), null).size());
|
|
|
|
}
|
|
|
|
|
2013-04-24 17:02:07 +08:00
|
|
|
}
|