aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/tests/ApiTests.java
blob: e67c23f2ff8190e5a4a20b3267863132938bccfa (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
package com.juick.tests;

import com.juick.Message;
import com.juick.User;
import com.juick.server.UserQueries;
import com.juick.server.MessagesQueries;
import junit.framework.Assert;
import org.apache.commons.dbcp2.BasicDataSource;
import org.junit.Before;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

/**
 * Created by vt on 14.01.2016.
 */
public class ApiTests {
    JdbcTemplate jdbc;
    @Before
    public void setupConnection() {
        Properties conf = new Properties();
        try {
            conf.load(new FileInputStream("/etc/juick/api.conf"));
            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", ""));
            jdbc = new JdbcTemplate(dataSource);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void userTests() {
        User user = UserQueries.getUserByUID(jdbc, 3694);
        Assert.assertEquals("it should be me", "vt", user.UName);
    }
    
    @Test void messageTests() {
        Message msg = MessagesQueries.getMessage(jdbc, 2817722);
        User ugnich = msg.User;
        Assert.assertEquals("ugnich", ugnich.UName);
        Assert.assertEquals("Microsoft", msg.Tags.get(0));
    }
}