package de.jeyp91.openligadb;

import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class OpenLigaDBConnectorTest {

    @Test
    public void APITestGetMatchDataOfMatchdayBundesliga() {
        OpenLigaDBConnector openLigaDBConnector = new OpenLigaDBConnector();
        ArrayList<OpenLigaDBMatch> matches = openLigaDBConnector.getMatchDataOfMatchday(2020, "bl1", 1);

        assertEquals(9, matches.size());

        OpenLigaDBMatch match;

        match = matches.get(0);
        assertEquals((Integer) 55277, match.getMatchId());
        assertEquals((Integer) 40, match.getTeamIdHome());
        assertEquals((Integer) 54, match.getTeamIdGuest());
        assertEquals((Integer) 2020, match.getSeason());
        assertEquals("2019-08-16T20:30:00", match.getMatchDateTime());
        assertEquals((Integer) 1, match.getMatchday());
        assertEquals((Integer) 2, match.getGoalsHome());
        assertEquals((Integer) 2, match.getGoalsGuest());
        assertTrue(match.getMatchIsFinished());

        match = matches.get(1);
        assertEquals((Integer) 55278, match.getMatchId());
        assertEquals((Integer) 7, match.getTeamIdHome());
        assertEquals((Integer) 95, match.getTeamIdGuest());
        assertEquals((Integer) 2020, match.getSeason());
        assertEquals("2019-08-17T15:30:00", match.getMatchDateTime());
        assertEquals((Integer) 1, match.getMatchday());
        assertEquals((Integer) 5, match.getGoalsHome());
        assertEquals((Integer) 1, match.getGoalsGuest());
        assertTrue(match.getMatchIsFinished());
    }

    @Test
    public void APITestGetMatchDataOfMatchdayDFBPokal() {
        OpenLigaDBConnector openLigaDBConnector = new OpenLigaDBConnector();
        ArrayList<OpenLigaDBMatch> matches = openLigaDBConnector.getMatchDataOfMatchday(2020, "dfb2019", 1);

        assert matches.size() == 32;

        OpenLigaDBMatch match = matches.get(0);
        assertEquals((Integer) 54926, match.getMatchId());
        assertEquals((Integer) 563, match.getTeamIdHome());
        assertEquals((Integer) 7, match.getTeamIdGuest());
        assertEquals((Integer) 2020, match.getSeason());
        assertEquals("2019-08-09T20:45:00", match.getMatchDateTime());
        assertEquals((Integer) 1, match.getMatchday());
        assertEquals((Integer) 0, match.getGoalsHome());
        assertEquals((Integer) 2, match.getGoalsGuest());
        assertTrue(match.getMatchIsFinished());
    }

    @Test
    public void APITestGetMatchDataOfSingleMatch() {
        OpenLigaDBConnector openLigaDBConnector = new OpenLigaDBConnector();
        OpenLigaDBMatch match = openLigaDBConnector.getMatchDataOfSingleMatch(55583);
        assertEquals((Integer) 55583, match.getMatchId());
        assertEquals((Integer) 16, match.getTeamIdHome());
        assertEquals((Integer) 55, match.getTeamIdGuest());
        assertEquals((Integer) 2020, match.getSeason());
        assertEquals("2019-07-26T20:30:00", match.getMatchDateTime());
        assertEquals((Integer) 1, match.getMatchday());
        assertEquals((Integer) 2, match.getGoalsHome());
        assertEquals((Integer) 1, match.getGoalsGuest());
        assertTrue(match.getMatchIsFinished());
    }
}
