package de.jeyp91.tippliga;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.assertEquals;

public class TippligaSQLConnectorTest {

    TippligaSQLConnector tl;

    @Before
    public void setup() {
        tl = new TippligaSQLConnector();
    }

    @Test
    public void getTeamsBySeasonAndLeagueTest() {
        ArrayList<TLWTeam> teams = tl.getTeams("2020", "1");

        assertEquals(84, teams.size());

        assertEquals(2020, teams.get(0).getSeason());
        assertEquals(1, teams.get(0).getLeague());
        assertEquals(1, teams.get(0).getTeamId());
        assertEquals("Bayern München", teams.get(0).getTeamName());
        assertEquals("Bayern", teams.get(0).getTeamNameShort());
        assertEquals("FC Bayern Muenchen.png", teams.get(0).getTeamSymbol());
        assertEquals("", teams.get(0).getGroupId());
        assertEquals(0, teams.get(0).getMatchday());
    }

    @Test
    public void getTeamsByIdTest() {
        ArrayList<TLWTeam> teams = tl.getTeams("1");

        assertEquals(2021, teams.get(0).getSeason());
        assertEquals(1, teams.get(0).getLeague());
        assertEquals(1, teams.get(0).getTeamId());
        assertEquals("Bayern München", teams.get(0).getTeamName());
        assertEquals("Bayern", teams.get(0).getTeamNameShort());
        assertEquals("FC Bayern Muenchen.png", teams.get(0).getTeamSymbol());
        assertEquals("", teams.get(0).getGroupId());
        assertEquals(0, teams.get(0).getMatchday());
    }

    @Test
    public void getMatchesBySeasonAndLeague() {
        ArrayList<TLWMatch> matches = tl.getMatches("2020", "1");

        assertEquals(468, matches.size());

        assertEquals((Integer) 2020, matches.get(0).getSeason());
        assertEquals((Integer) 1, matches.get(0).getLeague());
        assertEquals((Integer) 1, matches.get(0).getMatchday());
        assertEquals("", matches.get(0).getGroupId());
        assertEquals((Integer) 1, matches.get(0).getMatchNo());
        assertEquals("2019-07-26 20:30:00", matches.get(0).getMatchDateTime());
        assertEquals((Integer) 8, matches.get(0).getTeamIdHome());
        assertEquals((Integer) 15, matches.get(0).getTeamIdGuest());
        assertEquals((Integer) 2, matches.get(0).getGoalsHome());
        assertEquals((Integer) 1, matches.get(0).getGoalsGuest());
    }
}
