Archived
0

добален тест H2db

This commit is contained in:
2018-09-06 12:42:16 +03:00
parent bd37bc8615
commit bd72950db5
5 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
package mc.core.h2db;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:springTest.xml"})
public class TestH2Database {
@Autowired
private JdbcTemplate jdbcTemplate;
@PostConstruct
public void init() throws IOException {
jdbcTemplate.execute(IOUtils.resourceToString("/sqls/create_tables.sql", StandardCharsets.UTF_8));
}
@Test
public void testConnect() {
final String sql = "SELECT 1";
jdbcTemplate.execute(sql);
}
@Test
public void testExistsTable() {
jdbcTemplate.execute("SELECT COUNT(*) FROM players");
}
}

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.h2.Driver" />
<property name="url" value="jdbc:h2:mem:test;DB_CLOSE_DELAY=-1" />
<property name="username" value="sa" />
<property name="password" value="" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
</beans>

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS players (
id INT AUTO_INCREMENT,
uuid VARCHAR(36) NOT NULL,
name VARCHAR(16) NOT NULL,
location_x DOUBLE NOT NULL,
location_y DOUBLE NOT NULL,
location_z DOUBLE NOT NULL,
location_yaw FLOAT NOT NULL,
location_pitch FLOAT NOT NULL,
location_world varchar(64) NOT NULL
);