@@ -0,0 +1,3122 @@
+/*%0A * Copyright 2012-2017 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage sample.data.jpa;%0A%0Aimport java.lang.management.ManagementFactory;%0Aimport java.util.Set;%0A%0Aimport javax.management.MBeanServer;%0Aimport javax.management.ObjectInstance;%0Aimport javax.management.Query;%0Aimport javax.management.ObjectName;%0A%0Aimport static org.hamcrest.Matchers.*;%0A%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0A%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport org.springframework.boot.test.context.SpringBootTest;%0Aimport org.springframework.test.annotation.DirtiesContext;%0Aimport org.springframework.test.annotation.DirtiesContext.ClassMode;%0Aimport org.springframework.test.context.ActiveProfiles;%0Aimport org.springframework.test.context.TestPropertySource;%0Aimport org.springframework.test.context.junit4.SpringRunner;%0Aimport org.springframework.test.web.servlet.MockMvc;%0Aimport org.springframework.test.web.servlet.setup.MockMvcBuilders;%0Aimport org.springframework.web.context.WebApplicationContext;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;%0A%0A/**%0A * Integration test to run the application.%0A *%0A * @author Oliver Gierke%0A * @author Dave Syer%0A */%0A@RunWith(SpringRunner.class)%0A@SpringBootTest%0A// Enable JMX so we can test the MBeans (you can't do this in a properties file)%0A@TestPropertySource(properties = %7B %22spring.jmx.enabled:true%22,%0A%09%09%22spring.datasource.jmx-enabled:true%22 %7D)%0A@ActiveProfiles(%22scratch%22)%0A// See fix in https://stackoverflow.com/questions/41301557/the-object-is-already-closed-in-integration-test%0A@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)%0A// Separate profile for web tests to avoid clashing databases%0Apublic class SampleDataJpaApplicationTests %7B%0A%0A%09@Autowired%0A%09private WebApplicationContext context;%0A%0A%09private MockMvc mvc;%0A%0A%09@Before%0A%09public void setUp() %7B%0A%09%09this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();%0A%09%7D%0A%0A%09@Test%0A%09public void testHome() throws Exception %7B%0A%0A%09%09this.mvc.perform(get(%22/%22)).andExpect(status().isOk())%0A%09%09%09%09.andExpect(content().string(%22Bath%22));%0A%09%7D%0A%0A%09/*%0A%09 * @Test%0A%09 * public void testJmx() throws Exception %7B%0A%09 *%09%09assertThat(ManagementFactory.getPlatformMBeanServer()%0A%09 *%09%09%09.queryMBeans(new ObjectName(%22jpa.sample:type=HikariDataSource,*%22), null))%0A%09 *%09%09%09.hasSize(1);%0A%09 * %7D%0A%09 */%0A%7D%0A

Create SampleDataJpaApplicationTests.java