aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/tests/JsonTests.java
blob: c99432a613a18ce57b465d9761f9f212fc4b0e15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.juick.tests;

import com.juick.json.MessageSerializer;
import com.juick.server.MessagesQueries;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

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.Properties;

public class JsonTests {

    Connection sql;

    @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="
                    + 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() {
        ArrayList<Integer> mids = MessagesQueries.getMyFeed(sql, 3694, 2799786);
        MessageSerializer messageSerializer = new MessageSerializer();
        if (mids != null && !mids.isEmpty()) {
            ArrayList<com.juick.Message> msgs = MessagesQueries.getMessages(sql, mids);
            if (msgs != null && !msgs.isEmpty()) {
                String json = messageSerializer.serializeList(msgs);
                try {
                    String data = new String(Files.readAllBytes(Paths.get("original.json")), "UTF-8");
                    Assert.assertEquals("json should match", data, json);
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }
    }
}