aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-01-15 12:56:11 +0300
committerGravatar Vitaly Takmazov2016-01-15 12:56:11 +0300
commitd44d5be975b5196d7aa961e8fd3012f389626380 (patch)
tree8eb4cd6be8e9b1356c91c157f9d7a68e289cf0ff
parent690b3ea447a7a2434ecf1d210e5f5ef89ce27f04 (diff)
spring-jdbc WIP
-rw-r--r--src/test/java/com/juick/tests/JsonTests.java22
1 files changed, 8 insertions, 14 deletions
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<Integer> mids = MessagesQueries.getMyFeed(sql, 3694, 2799786);
+ List<Integer> mids = MessagesQueries.getMyFeed(jdbc, 3694, 2799786);
MessageSerializer messageSerializer = new MessageSerializer();
if (mids != null && !mids.isEmpty()) {
- List<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
+ List<com.juick.Message> msgs = MessagesQueries.getMessages(jdbc, mids);
if (msgs != null && !msgs.isEmpty()) {
String json = messageSerializer.serializeList(msgs);
try {