добален тест H2db
This commit is contained in:
16
h2_playermanager/build.gradle
Normal file
16
h2_playermanager/build.gradle
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
version '1.0-SNAPSHOT'
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
/* Core */
|
||||||
|
compile_excludeCopy project(':core')
|
||||||
|
|
||||||
|
/* Spring */
|
||||||
|
compile (group: 'org.springframework', name: 'spring-jdbc', version: spring_version) {
|
||||||
|
exclude group: 'commons-logging'
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Database */
|
||||||
|
compile (group: 'com.h2database', name: 'h2', version: '1.4.196')
|
||||||
|
|
||||||
|
testCompile (group: 'org.springframework', name: 'spring-test', version: spring_version)
|
||||||
|
}
|
||||||
@@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
21
h2_playermanager/src/test/resources/springTest.xml
Normal file
21
h2_playermanager/src/test/resources/springTest.xml
Normal 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>
|
||||||
11
h2_playermanager/src/test/resources/sqls/create_tables.sql
Normal file
11
h2_playermanager/src/test/resources/sqls/create_tables.sql
Normal 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
|
||||||
|
);
|
||||||
@@ -2,6 +2,7 @@ rootProject.name = 'mc-server'
|
|||||||
|
|
||||||
include('core') // Core
|
include('core') // Core
|
||||||
include('flat_world')
|
include('flat_world')
|
||||||
|
include('h2_playermanager')
|
||||||
include('vanilla_commands')
|
include('vanilla_commands')
|
||||||
include('proto_1.12.2') // Protocol 1.12.2
|
include('proto_1.12.2') // Protocol 1.12.2
|
||||||
include('proto_1.12.2_netty') // Protocol 1.12.2 (Netty impl.)
|
include('proto_1.12.2_netty') // Protocol 1.12.2 (Netty impl.)
|
||||||
|
|||||||
Reference in New Issue
Block a user