57 lines
1.9 KiB
Java
57 lines
1.9 KiB
Java
package com.yam.app.integration;
|
|
|
|
import static org.springframework.test.web.servlet.setup.SharedHttpSessionConfigurer.sharedHttpSession;
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import javax.sql.DataSource;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.context.annotation.Profile;
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
|
import org.springframework.test.context.ActiveProfiles;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|
import org.springframework.web.context.WebApplicationContext;
|
|
|
|
@SpringBootTest
|
|
@AutoConfigureMockMvc
|
|
@ActiveProfiles("test")
|
|
abstract class AbstractIntegrationTests {
|
|
|
|
@Autowired
|
|
protected MockMvc mockMvc;
|
|
@Autowired
|
|
protected ObjectMapper objectMapper;
|
|
|
|
@Autowired
|
|
private WebApplicationContext wac;
|
|
|
|
@BeforeEach
|
|
void setUp() {
|
|
mockMvc = MockMvcBuilders
|
|
.webAppContextSetup(wac)
|
|
.apply(sharedHttpSession())
|
|
.build();
|
|
}
|
|
|
|
@Configuration
|
|
public static class TestConfiguration {
|
|
|
|
@Bean
|
|
@Profile("test")
|
|
public DataSource dataSource() {
|
|
return new EmbeddedDatabaseBuilder()
|
|
.setType(EmbeddedDatabaseType.H2)
|
|
.setName("testdb;mode=MySQL")
|
|
.addScript("classpath:sql/ddl.sql")
|
|
.addScript("classpath:sql/dml.sql")
|
|
.build();
|
|
}
|
|
}
|
|
}
|