2014-11-19 05:29:54 +08:00
|
|
|
/*
|
2016-02-25 20:09:42 +08:00
|
|
|
* Copyright 2012-2016 the original author or authors.
|
2014-11-19 05:29:54 +08:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
2015-09-06 12:36:18 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2014-11-19 05:29:54 +08:00
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
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 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;
|
2015-10-20 03:23:14 +08:00
|
|
|
|
2013-08-03 01:12:17 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2016-04-05 12:25:01 +08:00
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
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;
|
2016-03-02 07:54:51 +08:00
|
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
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
|
|
|
|
2016-02-07 06:53:10 +08:00
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
2014-11-04 09:20:40 +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
|
|
|
/**
|
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
|
|
|
*/
|
2016-03-02 07:54:51 +08:00
|
|
|
@RunWith(SpringRunner.class)
|
2016-04-05 12:25:01 +08:00
|
|
|
@SpringBootTest
|
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)
|
2014-11-07 12:55:04 +08:00
|
|
|
@TestPropertySource(properties = { "spring.jmx.enabled:true",
|
|
|
|
"spring.datasource.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 {
|
2016-02-07 06:53:10 +08:00
|
|
|
assertThat(ManagementFactory.getPlatformMBeanServer()
|
|
|
|
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null))
|
|
|
|
.hasSize(1);
|
2014-11-03 21:28:26 +08:00
|
|
|
}
|
|
|
|
|
2013-04-24 17:02:07 +08:00
|
|
|
}
|