From d44d5be975b5196d7aa961e8fd3012f389626380 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 15 Jan 2016 12:56:11 +0300 Subject: spring-jdbc WIP --- src/test/java/com/juick/tests/JsonTests.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/com/juick/tests/JsonTests.java b/src/test/java/com/juick/tests/JsonTests.java index 35854171..99d9ca46 100644 --- a/src/test/java/com/juick/tests/JsonTests.java +++ b/src/test/java/com/juick/tests/JsonTests.java @@ -10,41 +10,35 @@ import java.io.FileInputStream; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.ArrayList; import java.util.List; import java.util.Properties; +import org.apache.commons.dbcp2.BasicDataSource; +import org.springframework.jdbc.core.JdbcTemplate; public class JsonTests { - Connection sql; - + JdbcTemplate jdbc; @Before public void setupConnection() { Properties conf = new Properties(); try { conf.load(new FileInputStream("/etc/juick/api.conf")); - Class.forName("com.mysql.jdbc.Driver"); - sql = DriverManager.getConnection("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName("com.mysql.jdbc.Driver"); + dataSource.setUrl("jdbc:mysql://localhost/juick?autoReconnect=true&user=" + conf.getProperty("mysql_username", "") + "&password=" + conf.getProperty("mysql_password", "")); } catch (IOException e) { e.printStackTrace(); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } catch (SQLException e) { - e.printStackTrace(); } } @Test public void CompareSerializers() { - List mids = MessagesQueries.getMyFeed(sql, 3694, 2799786); + List mids = MessagesQueries.getMyFeed(jdbc, 3694, 2799786); MessageSerializer messageSerializer = new MessageSerializer(); if (mids != null && !mids.isEmpty()) { - List msgs = MessagesQueries.getMessages(sql, mids); + List msgs = MessagesQueries.getMessages(jdbc, mids); if (msgs != null && !msgs.isEmpty()) { String json = messageSerializer.serializeList(msgs); try { -- cgit v1.2.3