|
25 | 25 | import java.util.Map; |
26 | 26 |
|
27 | 27 | import javax.sql.DataSource; |
| 28 | + |
28 | 29 | import org.h2.tools.Server; |
29 | 30 | import org.junit.jupiter.api.AfterEach; |
30 | 31 | import org.junit.jupiter.api.BeforeEach; |
|
40 | 41 | import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; |
41 | 42 | import org.springframework.util.SocketUtils; |
42 | 43 |
|
43 | | - |
44 | 44 | import static org.assertj.core.api.Assertions.assertThat; |
45 | 45 |
|
46 | 46 | /** |
@@ -71,8 +71,8 @@ public class BatchJobApplicationTests { |
71 | 71 | private File outputFile; |
72 | 72 |
|
73 | 73 | @BeforeEach |
74 | | - public void setup() { |
75 | | - outputFile = new File("./result.txt"); |
| 74 | + public void setup() throws Exception { |
| 75 | + outputFile = new File("result.txt"); |
76 | 76 | initH2TCPServer(); |
77 | 77 | } |
78 | 78 |
|
@@ -130,29 +130,26 @@ public void testFileReaderFileWriter() throws Exception { |
130 | 130 | validateFileResult(); |
131 | 131 | } |
132 | 132 |
|
133 | | - public Server initH2TCPServer() { |
134 | | - Server server = null; |
135 | | - try { |
136 | | - if (defaultServer == null) { |
137 | | - server = Server.createTcpServer("-ifNotExists", "-tcp", |
138 | | - "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort)) |
139 | | - .start(); |
140 | | - defaultServer = server; |
141 | | - DriverManagerDataSource dataSource = new DriverManagerDataSource(); |
142 | | - dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME); |
143 | | - dataSource.setUrl(DATASOURCE_URL); |
144 | | - dataSource.setUsername(DATASOURCE_USER_NAME); |
145 | | - dataSource.setPassword(DATASOURCE_USER_PASSWORD); |
146 | | - ClassPathResource setupResource = new ClassPathResource( |
147 | | - "schema-h2.sql"); |
148 | | - ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator( |
149 | | - setupResource); |
150 | | - resourceDatabasePopulator.execute(dataSource); |
151 | | - } |
152 | | - } |
153 | | - catch (SQLException e) { |
154 | | - throw new IllegalStateException(e); |
| 133 | + public Server initH2TCPServer() throws SQLException { |
| 134 | + Server server; |
| 135 | + |
| 136 | + if (defaultServer == null) { |
| 137 | + server = Server.createTcpServer("-ifNotExists", "-tcp", |
| 138 | + "-tcpAllowOthers", "-tcpPort", String.valueOf(randomPort)) |
| 139 | + .start(); |
| 140 | + defaultServer = server; |
| 141 | + DriverManagerDataSource dataSource = new DriverManagerDataSource(); |
| 142 | + dataSource.setDriverClassName(DATASOURCE_DRIVER_CLASS_NAME); |
| 143 | + dataSource.setUrl(DATASOURCE_URL); |
| 144 | + dataSource.setUsername(DATASOURCE_USER_NAME); |
| 145 | + dataSource.setPassword(DATASOURCE_USER_PASSWORD); |
| 146 | + ClassPathResource setupResource = new ClassPathResource( |
| 147 | + "schema-h2.sql"); |
| 148 | + ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator( |
| 149 | + setupResource); |
| 150 | + resourceDatabasePopulator.execute(dataSource); |
155 | 151 | } |
| 152 | + |
156 | 153 | return defaultServer; |
157 | 154 | } |
158 | 155 |
|
|
0 commit comments