diff --git a/h2_playermanager/build.gradle b/h2_playermanager/build.gradle new file mode 100644 index 0000000..727fc10 --- /dev/null +++ b/h2_playermanager/build.gradle @@ -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) +} \ No newline at end of file diff --git a/h2_playermanager/src/test/java/mc/core/h2db/TestH2Database.java b/h2_playermanager/src/test/java/mc/core/h2db/TestH2Database.java new file mode 100644 index 0000000..69b6b12 --- /dev/null +++ b/h2_playermanager/src/test/java/mc/core/h2db/TestH2Database.java @@ -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"); + } + + +} diff --git a/h2_playermanager/src/test/resources/springTest.xml b/h2_playermanager/src/test/resources/springTest.xml new file mode 100644 index 0000000..8cebaaf --- /dev/null +++ b/h2_playermanager/src/test/resources/springTest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/h2_playermanager/src/test/resources/sqls/create_tables.sql b/h2_playermanager/src/test/resources/sqls/create_tables.sql new file mode 100644 index 0000000..a7d2209 --- /dev/null +++ b/h2_playermanager/src/test/resources/sqls/create_tables.sql @@ -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 +); \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 52ad5e4..f9dbb2c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,7 @@ rootProject.name = 'mc-server' include('core') // Core include('flat_world') +include('h2_playermanager') include('vanilla_commands') include('proto_1.12.2') // Protocol 1.12.2 include('proto_1.12.2_netty') // Protocol 1.12.2 (Netty impl.)