package atmsdriver.model;

import java.io.FileWriter;
import java.io.PrintWriter;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import junit.framework.TestCase;

/**
 *
 * @author jdalbey
 */
public class LoadSadDotsTest extends TestCase {

    public LoadSadDotsTest(String testName) {
        super(testName);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        PrintWriter writer = null;
        try {
            writer = new PrintWriter(new FileWriter("test/atmsdriver/model/lds_loadhighways_sample.txt"));
            
            writer.println("lds_id	line 	drop sch lineinfo	system_key	sch_seq glo_seq		count	freeway	Dir	ca_pm	lds_name");
            writer.println("1205146	50	3	13	13	1123005873	24148	1357650		19	5	N	29.79	NEWPORT");
            writer.println("1201190	46	6	36	36	1123006209	26472	1357644		20	405	S	4.03	JEFFREY 2");
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
        Path path = FileSystems.getDefault().getPath("test/atmsdriver/model", "lds_loadhighways_sample.txt");
        Files.delete(path);
    }

    /**
     * Test of toXML method, of class Network.
     */
    public void testLoadHighways() {
        System.out.println("toXML");
        Highways highways = new Highways(
                "config/vds_data/highways_fullmap.txt",
                "localhost", 8080);
        
         // Test for correct number of highways
        ArrayList<Highway> result = highways.highways;
        assertEquals(2, result.size());
        
        // Test 5 N was loaded
        Highway fiftyfiveN = result.get(0);
        assertEquals(new Integer(5), fiftyfiveN.routeNumber);
        
        ArrayList<Station> stations = fiftyfiveN.stations;
        Station sad = stations.get(0);
        System.out.println(""+sad.toCondensedFormat(true));
        assertEquals(22, sad.loops.size());

        // Test 405 S was loaded
        Highway fourohfiveS = result.get(1);
        assertEquals(new Integer(405), fourohfiveS.routeNumber);
        stations = fourohfiveS.stations;
        Station happy = stations.get(0);
        System.out.println(""+happy.toCondensedFormat(true));
        assertEquals(9, happy.loops.size());
    }
}
