package seng302.Model;
/**
 * Created by Gondr on 26/03/2017.
 */

import org.junit.Test;
import seng302.RaceXMLReader;

import java.util.List;

import static org.junit.Assert.*;

public class RaceXMLTest {
    RaceXMLReader raceXMLReader;

    @Test
    public void canFindFile() {
        try {
            RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false);
        } catch (Exception e) {
            fail("Cannot find raceXML/bermuda_AC35.xml in the resources folder");
        }
    }

    @Test
    public void canReadBoats() {
        try {
            RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false);
            raceXMLReader.readBoats();
            List<Boat> boats = raceXMLReader.getBoats();
            assertTrue(boats.size() == 6);
            //test boat 1
            assertEquals(boats.get(0).getName().getValue(), "ORACLE TEAM USA");
            assertTrue(boats.get(0).getVelocity() == 20);
            //test boat 2
            assertEquals(boats.get(1).getName().getValue(), "Land Rover BAR");
            assertTrue(boats.get(1).getVelocity() == 30);
            assertEquals(boats.get(1).getAbbrev(), "GBR");
            //test boat 3
            assertEquals(boats.get(2).getName().getValue(), "SoftBank Team Japan");
            assertTrue(boats.get(2).getVelocity() == 25);
            assertEquals(boats.get(2).getAbbrev(), "JPN");
            //test boat 4
            assertEquals(boats.get(3).getName().getValue(), "Groupama Team France");
            assertTrue(boats.get(3).getVelocity() == 20);
            assertEquals(boats.get(3).getAbbrev(), "FRA");
            //test boat 5
            assertEquals(boats.get(4).getName().getValue(), "Artemis Racing");
            assertTrue(boats.get(4).getVelocity() == 29);
            assertEquals(boats.get(4).getAbbrev(), "SWE");
            //test boat 6
            assertEquals(boats.get(5).getName().getValue(), "Emirates Team New Zealand");
            assertTrue(boats.get(5).getVelocity() == 62);
            assertEquals(boats.get(5).getAbbrev(), "NZL");
        } catch (Exception e) {
            fail("Boat Unreadable");
        }
    }

    @Test
    public void canReadLegs() {
        try {
            RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false);
            raceXMLReader.readLegs();
            assertTrue(raceXMLReader.getLegs().size() == 5);
        } catch (Exception e) {
            fail("Legs Unreadable");
        }
    }

    @Test
    public void canReadCourse() {
        try {
            RaceXMLReader raceXMLReader = new RaceXMLReader("raceXML/bermuda_AC35.xml", false);
            raceXMLReader.readCourse();
            assertTrue(raceXMLReader.getMapTopLeft() != null);
            assertTrue(raceXMLReader.getMapBottomRight() != null);
            assertTrue(raceXMLReader.getFinishPt1() != null);
            assertTrue(raceXMLReader.getFinishPt2() != null);
            assertTrue(raceXMLReader.getStartPt1() != null);
            assertTrue(raceXMLReader.getStartPt2() != null);
            assertTrue(raceXMLReader.getLeewardPt1() != null);
            assertTrue(raceXMLReader.getLeewardPt2() != null);
            assertTrue(raceXMLReader.getWindwardPt1() != null);
            assertTrue(raceXMLReader.getWindwardPt2() != null);
            assertTrue(raceXMLReader.getBoundary().size() == 11);
        } catch (Exception e) {
            e.printStackTrace();
            fail("Course Unreadable");
        }
    }

}