package com.juick.tests; import com.juick.Message; import com.juick.User; import com.juick.server.MessagesQueries; import com.juick.server.UserQueries; import junit.framework.Assert; import org.junit.Before; import org.junit.Test; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DriverManagerDataSource; 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")); DriverManagerDataSource dataSource = new DriverManagerDataSource(); 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.getUName()); } @Test public void messageTests() { Message msg = MessagesQueries.getMessage(jdbc, 2817722); User ugnich = msg.getUser(); Assert.assertEquals("ugnich", ugnich.getUName()); org.junit.Assert.assertEquals("ugnich", MessagesQueries.getMessageAuthor(jdbc, 281772).getUName()); Assert.assertEquals("Microsoft", msg.Tags.get(0)); Message reply = MessagesQueries.getReply(jdbc, 2817722, 8); User linda = reply.getUser(); Assert.assertEquals("Linda-chan", linda.getUName()); } }