1
2
3
4
5
6
7
8
9
10 package nl.tudelft.simulation.dsol.simulators;
11
12 import java.rmi.RemoteException;
13
14 import junit.framework.Assert;
15 import junit.framework.TestCase;
16 import nl.tudelft.simulation.dsol.SimRuntimeException;
17 import nl.tudelft.simulation.dsol.simulators.SimulatorInterface;
18
19 /***
20 * The SimulatorTest test the basic behavior of the simulator <br>
21 * (c) copyright 2003 <a href="http://www.simulation.tudelft.nl">Delft
22 * University of Technology </a>, the Netherlands. <br>
23 * See for project information <a
24 * href="http://www.simulation.tudelft.nl">www.simulation.tudelft.nl </a> <br>
25 * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
26 * License (GPL) </a>, no warranty <br>
27 *
28 * @version 2.0 21.09.2003 <br>
29 * @author <a href="http://www.tbm.tudelft.nl/webstaf/peterja/index.htm">Peter
30 * Jacobs </a>, <a
31 * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
32 * Verbraeck </a>
33 */
34 public class SimulatorTest extends TestCase
35 {
36 /*** TEST_METHOD refers to the name of the test method */
37 public static final String TEST_METHOD = "test";
38
39 /*** simulator is the target to test */
40 protected SimulatorInterface simulator;
41
42 /***
43 * constructs a new SimulatorTest
44 *
45 * @param target is the simulator which to test
46 */
47 public SimulatorTest(final SimulatorInterface target)
48 {
49 this(TEST_METHOD, target);
50 }
51
52 /***
53 * constructs a new SimulatorTest
54 *
55 * @param arg0 the name of the test method
56 * @param target is the simulator which to test
57 */
58 public SimulatorTest(final String arg0, final SimulatorInterface target)
59 {
60 super(arg0);
61 this.simulator = target;
62 }
63
64 /***
65 * test the DEVS Simulator
66 */
67 public void test()
68 {
69 try
70 {
71 this.simulator.start();
72 Assert.fail("Simulator not initialized");
73 } catch (Exception exception)
74 {
75 Assert.assertTrue(exception.getClass().equals(
76 SimRuntimeException.class));
77 }
78 try
79 {
80 this.simulator.stop();
81 Assert.fail("Simulator not running");
82 } catch (Exception exception)
83 {
84 Assert.assertTrue(exception.getClass().equals(
85 SimRuntimeException.class));
86 }
87 try
88 {
89 this.simulator.step();
90 Assert.fail("Simulator not initialized");
91 } catch (Exception exception)
92 {
93 Assert.assertTrue(exception.getClass().equals(
94 SimRuntimeException.class));
95 }
96 try
97 {
98 Assert.assertFalse(this.simulator.isRunning());
99 } catch (Exception exception)
100 {
101 Assert.assertTrue(exception.getClass()
102 .equals(RemoteException.class));
103 }
104 try
105 {
106 Assert.assertNull(this.simulator.getReplication());
107 Assert.assertTrue(new Double(this.simulator.getSimulatorTime())
108 .isNaN());
109 this.simulator.initialize(null);
110 } catch (Exception exception)
111 {
112
113 Assert.assertTrue(exception instanceof IllegalArgumentException);
114 }
115 }
116 }