package seng302.DataInput;

import org.junit.Before;
import org.junit.Test;
import seng302.Model.Regatta;

import static org.junit.Assert.*;

/**
 * Created by jjg64 on 19/04/17.
 */
public class RegattaXMLTest {
    RegattaXMLReader regattaXMLReader;

    @Before
    public void findFile() {
        try {
            regattaXMLReader = new RegattaXMLReader("mockXML/regattaTest.xml", false);
        } catch (Exception e) {
            fail("Cannot find mockXML/regattaXML/regattaTest.xml in the resources folder");
        }
    }

    @Test
    public void makeRegattaTest() {
        try {
            regattaXMLReader = new RegattaXMLReader("mockXML/regattaTest.xml");
            assertNotEquals(regattaXMLReader.getRegatta(), null);
        } catch (Exception e) {
            fail("Did not make a Regatta object");
        }
    }

    @Test
    public void correctValuesTest() {
        try {
            regattaXMLReader = new RegattaXMLReader("mockXML/regattaTest.xml");
            Regatta regatta = regattaXMLReader.getRegatta();
            assertEquals(regatta.getRegattaID(), 3);
            assertEquals(regatta.getRegattaName(), "New Zealand Test");
            assertEquals(regatta.getCourseName(), "North Head");
            assertEquals(regatta.getCentralLatitude(), -36.82791529, 0.00000001);
            assertEquals(regatta.getCentralLongitude(), 174.81218919, 0.00000001);
            assertEquals(regatta.getCentralAltitude(), 0.00, 0.00000001);
            assertEquals(regatta.getUtcOffset(), 12.0, 0.001);
            assertEquals(regatta.getMagneticVariation(), 14.1, 0.001);
        } catch (Exception e) {
            fail("Did not have the correct values");
        }
    }
}
