package tmcsim.cadsimulator.viewer.model;

import java.util.Observable;
import java.util.Observer;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import junit.framework.TestCase;
import tmcsim.cadsimulator.viewer.DVDInfoPanel;
import java.util.Iterator;
import tmcsim.cadsimulator.videocontrol.DVDStatusUpdate;
import tmcsim.common.CADEnums;

/**
 *
 * @author jdalbey
 */
public class CADSimulatorModelTest extends TestCase implements Observer
{

    private CADSimulatorModel model;
    private String currentTest;

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

    public void setUp()
    {
        model = new CADSimulatorModel();
        model.addObserver(this);
    }

    /**
     * Test of connectClient method, of class CADSimulatorStatus.
     */
    public void testConnectClient()
    {
        currentTest = "connectClient";
        model.connectClient();
    }

    /**
     * Test of disconnectClient method, of class CADSimulatorStatus.
     */
    public void testDisconnectClient()
    {
        currentTest = "doNothing";
        model.connectClient();
        model.connectClient();
        currentTest = "disconnectClient";
        model.disconnectClient();
    }

    /**
     * Test of setSimManagerStatus method, of class CADSimulatorStatus.
     */
    public void testSetSimManagerStatus()
    {
        currentTest = "setSimManagerStatus";
        model.setSimManagerStatus(false);
    }

    /**
     * Test of setTime method, of class CADSimulatorStatus.
     */
    public void testSetTime()
    {
        currentTest = "setTime";
        long seconds = 0L;
        model.setTime(seconds);
    }

    /**
     * Test of setScriptStatus method, of class CADSimulatorStatus.
     */
    public void testSetScriptStatus()
    {
        currentTest = "setScriptStatus";
        CADEnums.SCRIPT_STATUS newStatus = CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING;
        model.setScriptStatus(newStatus);
    }

    public void testSetParamicsStatus()
    {
        currentTest = "setParamicsStatus";
        CADEnums.PARAMICS_STATUS newStatus = CADEnums.PARAMICS_STATUS.CONNECTED;
        model.setParamicsStatus(newStatus);
    }

    public void testLoadNetwork()
    {
        currentTest = "loadNetwork";
        model.setParamicsNetworkLoaded("ABC");
    }
    
    public void testDVDupdate()
    {
        currentTest = "dvdUpdate";
        model.updateDVDStatus(new DVDStatusUpdate("1", false, new Throwable()));
    }

    @Override
    public void update(Observable obs, Object obj)
    {
        CADSimulatorStatus stat = null;
        CADMediaStatus ms = null;
        if (obs instanceof CADSimulatorStatus)
        {
            stat = (CADSimulatorStatus) obs;
        }
        if (obs instanceof CADMediaStatus)
        {
            ms = (CADMediaStatus) obs;
        }
        System.out.println(currentTest);
        switch (currentTest)
        {
            case "connectClient":
                assertEquals(1, stat.getNumClients());
                break;
            case "disconnectClient":
                assertEquals(1, stat.getNumClients());
                break;
            case "setSimManagerStatus":
                assertFalse(stat.isSimManagerConnected());
                break;
            case "setTime":
                assertEquals("0:00:00", stat.getCurrentTime());
                break;
            case "setScriptStatus":
                CADEnums.SCRIPT_STATUS expResult = CADEnums.SCRIPT_STATUS.SCRIPT_RUNNING;
                CADEnums.SCRIPT_STATUS result = stat.getScriptStatus();
                assertEquals(expResult, result);
                break;
            case "setParamicsStatus":
                CADEnums.PARAMICS_STATUS expect = CADEnums.PARAMICS_STATUS.CONNECTED;
                assertEquals(expect, stat.getParamicsStatus());
                break;
            case "loadNetwork":
                String id = stat.getParmicsNetworkID();
                assertEquals("ABC", id);
                break;
            case "dvdUpdate":
                Iterator<DVDInfoPanel> iter = ms.getDVDlist();
                assertTrue(iter.hasNext());
            case "doNothing":
                break;
        }
    }
}
