From 462013333ed9ab6244e8b46106e3cb566efdd0e0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Mon, 27 Jun 2016 16:39:15 +0300 Subject: embedded mariadb for tests --- src/test/java/com/juick/tests/ApiTests.java | 72 ++++------------------------- 1 file changed, 9 insertions(+), 63 deletions(-) (limited to 'src/test/java/com/juick/tests') diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java index 2bae183d..7ab04708 100644 --- a/src/test/java/com/juick/tests/ApiTests.java +++ b/src/test/java/com/juick/tests/ApiTests.java @@ -1,5 +1,7 @@ package com.juick.tests; +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DB; import com.juick.Message; import com.juick.Tag; import com.juick.User; @@ -23,71 +25,15 @@ import java.util.List; public class ApiTests { JdbcTemplate jdbc; @Before - public void setupConnection() { + public void setupConnection() throws ManagedProcessException { + DB db = DB.newEmbeddedDB(3306); + db.start(); + db.createDB("juick"); + db.source("schema.sql"); DriverManagerDataSource dataSource = new DriverManagerDataSource(); - dataSource.setDriverClassName("org.h2.Driver"); - dataSource.setUrl("jdbc:h2:~/test"); + dataSource.setDriverClassName("com.mysql.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://localhost/juick?autoReconnect=true&user=root"); jdbc = new JdbcTemplate(dataSource); - jdbc.execute("DROP ALL OBJECTS DELETE FILES"); - jdbc.execute("CREATE TABLE bl_users (user_id int(10) unsigned NOT NULL, " + - "bl_user_id int(10) unsigned NOT NULL, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP )"); - jdbc.execute("CREATE TABLE messages (" + - "message_id int(10) unsigned NOT NULL AUTO_INCREMENT," + - "user_id int(10) unsigned NOT NULL," + - "place_id int(10) unsigned DEFAULT NULL," + - "lat decimal(10,7) DEFAULT NULL," + - "lon decimal(10,7) DEFAULT NULL," + - "ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP," + - "replies smallint(5) unsigned NOT NULL DEFAULT 0," + - "maxreplyid smallint(5) unsigned NOT NULL DEFAULT 0," + - "privacy tinyint(4) NOT NULL DEFAULT '1'," + - "attach nchar(3) check (attach in ('jpg', 'mp4', 'png'))," + - "readonly tinyint(1) NOT NULL DEFAULT 0," + - "likes smallint(6) NOT NULL DEFAULT 0," + - "hidden tinyint(3) unsigned NOT NULL DEFAULT 0" + - ")"); - jdbc.execute("CREATE TABLE messages_tags (" + - "message_id int(10) unsigned NOT NULL," + - "tag_id int(10) unsigned NOT NULL" + - ")"); - jdbc.execute("CREATE TABLE users (" + - "id int(10) unsigned NOT NULL AUTO_INCREMENT," + - "nick char(64) NOT NULL," + - "passw char(32) NOT NULL," + - "banned tinyint(3) unsigned NOT NULL DEFAULT 0)"); - jdbc.execute("CREATE TABLE useroptions (" + - "user_id int(10) unsigned NOT NULL," + - "jnotify tinyint(1) NOT NULL DEFAULT 1," + - "subscr_active tinyint(1) NOT NULL DEFAULT 1)"); - jdbc.execute("CREATE TABLE subscr_users (" + - "user_id int(10) unsigned NOT NULL," + - "suser_id int(10) unsigned NOT NULL," + - "jid char(64) DEFAULT NULL," + - "active tinyint(1) NOT NULL DEFAULT 1," + - "ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)"); - jdbc.execute("CREATE TABLE subscr_messages (" + - "message_id int(10) unsigned NOT NULL," + - "suser_id int(10) unsigned NOT NULL)"); - jdbc.execute("CREATE TABLE messages_txt (" + - "message_id int(10) unsigned NOT NULL," + - "tags varchar(255)," + - "repliesby varchar(96)," + - "txt TEXT)"); - jdbc.execute("CREATE TABLE tags(" + - "tag_id int(10) unsigned NOT NULL AUTO_INCREMENT," + - "synonym_id int(10) unsigned DEFAULT NULL," + - "name char(48) NOT NULL," + - "top tinyint(1) unsigned NOT NULL DEFAULT 0," + - "stat_messages int(10) unsigned NOT NULL DEFAULT 0," + - "stat_users smallint(5) unsigned NOT NULL DEFAULT 0)"); - jdbc.execute("CREATE TABLE replies (" + - "message_id int(10) unsigned NOT NULL," + - "reply_id smallint(5) unsigned NOT NULL," + - "user_id int(10) unsigned NOT NULL," + - "replyto smallint(5) unsigned NOT NULL DEFAULT 0," + - "ts timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP," + - "attach nchar(3) check (attach in ('jpg', 'mp4', 'png'))," + - "txt text)"); } -- cgit v1.2.3