Changeset 60 in tmcsimulator-scriptbuilder for trunk/test/scriptbuilder/structures
- Timestamp:
- 08/14/2017 03:44:12 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/scriptbuilder/structures/SimulationScriptTest.java
r56 r60 5 5 import java.nio.file.Files; 6 6 import java.util.ArrayList; 7 import java.util.Observable; 8 import java.util.Observer; 7 9 import java.util.logging.Level; 8 10 import java.util.logging.Logger; 11 import static junit.framework.Assert.assertFalse; 12 import static junit.framework.Assert.assertTrue; 13 import static junit.framework.Assert.fail; 9 14 import junit.framework.TestCase; 15 import org.apache.commons.io.FileUtils; 16 import scriptbuilder.structures.events.ATMSEvaluationEvent; 17 import scriptbuilder.structures.events.AudioEvent; 18 import scriptbuilder.structures.events.CHPRadioEvent; 19 import scriptbuilder.structures.events.TMTRadioEvent; 10 20 11 21 /** … … 13 23 * @author Bryan McGuffin 14 24 */ 15 public class SimulationScriptTest extends TestCase 25 public class SimulationScriptTest extends TestCase implements Observer 16 26 { 17 27 28 private boolean updateFlag = false; 29 18 30 public SimulationScriptTest(String testName) 19 31 { … … 28 40 System.out.println("update"); 29 41 SimulationScript instance = new SimulationScript(); 42 43 updateFlag = false; 44 assertFalse(updateFlag); 45 46 instance.addObserver(this); 30 47 instance.update(); 31 // TODO review the generated test code and remove the default call to fail. 32 fail("The test case is a prototype."); 48 assertTrue(updateFlag); 33 49 } 34 50 … … 39 55 { 40 56 System.out.println("broadcastEvent"); 41 ScriptIncident.SliceChangedEvent e = null; 42 SimulationScript instance = new SimulationScript(); 43 instance.broadcastEvent(e); 44 // TODO review the generated test code and remove the default call to fail. 45 fail("The test case is a prototype."); 57 ScriptIncident.SliceChangedEvent ev = new ScriptIncident.SliceChangedEvent(null); 58 SimulationScript instance = new SimulationScript(); 59 60 updateFlag = false; 61 assertFalse(updateFlag); 62 63 instance.addObserver(this); 64 instance.broadcastEvent(ev); 65 assertTrue(updateFlag); 46 66 } 47 67 … … 52 72 { 53 73 System.out.println("broadcastEvent"); 54 ScriptIncident.IncidentFocusedEvent e = null; 55 SimulationScript instance = new SimulationScript(); 56 instance.broadcastEvent(e); 57 // TODO review the generated test code and remove the default call to fail. 58 fail("The test case is a prototype."); 74 ScriptIncident.IncidentFocusedEvent ev = new ScriptIncident.IncidentFocusedEvent(null); 75 SimulationScript instance = new SimulationScript(); 76 77 updateFlag = false; 78 assertFalse(updateFlag); 79 80 instance.addObserver(this); 81 instance.broadcastEvent(ev); 82 assertTrue(updateFlag); 59 83 } 60 84 … … 65 89 { 66 90 System.out.println("loadScriptFromFile"); 67 File f = null; 68 SimulationScript instance = new SimulationScript(); 69 instance.loadScriptFromFile(f); 70 // TODO review the generated test code and remove the default call to fail. 71 fail("The test case is a prototype."); 91 File inFile = new File("test/scriptbuilder/structures/test_input_file.xml"); 92 SimulationScript instance = new SimulationScript(); 93 assertEquals(0, instance.incidentCount()); 94 95 instance.loadScriptFromFile(inFile); 96 assertEquals(6, instance.incidentCount()); 72 97 } 73 98 … … 77 102 public void testSaveScriptToFile() 78 103 { 104 //This is basically identical to the integration test for saving and loading 79 105 System.out.println("saveScriptToFile"); 80 File f = null; 81 SimulationScript instance = new SimulationScript(); 82 instance.saveScriptToFile(f); 83 // TODO review the generated test code and remove the default call to fail. 84 fail("The test case is a prototype."); 106 try 107 { 108 File inFile = new File("test/scriptbuilder/structures/test_input_file.xml"); 109 assertTrue(inFile.exists()); 110 111 File outFile = new File("test/scriptbuilder/structures/test_output_file.xml"); 112 if (outFile.exists()) 113 { 114 outFile.delete(); 115 } 116 assertFalse(outFile.exists()); 117 118 outFile.createNewFile(); 119 120 assertTrue(outFile.exists()); 121 122 SimulationScript script = new SimulationScript(); 123 124 //Read in from test_input_file.xml 125 script.loadScriptFromFile(inFile); 126 127 //Save to test_output_file.xml 128 script.saveScriptToFile(outFile); 129 130 assertTrue(inFile.exists()); 131 assertTrue(outFile.exists()); 132 133 //Check to see if the two files are identical 134 boolean result = FileUtils.contentEquals(inFile, outFile); 135 136 assertTrue(result); 137 //If so, data model does in fact read in all data and write it back in the correct format 138 } 139 catch (IOException ex) 140 { 141 fail("There was an IO exception. Check file names and locations."); 142 } 85 143 } 86 144 … … 109 167 catch (IOException ex) 110 168 { 111 Logger.getLogger(SimulationScriptTest.class.getName()).log(Level.SEVERE, null, ex);169 fail("There was an IO exception. Check file names and locations."); 112 170 } 113 171 } … … 120 178 System.out.println("allSlices"); 121 179 SimulationScript instance = new SimulationScript(); 122 ArrayList<TimeSlice> expResult = null; 180 181 instance.incidents.set(0, new ScriptIncident(121, null, null, instance)); 182 183 instance.incidents.set(1, new ScriptIncident(101, null, null, instance)); 184 185 ScriptEvent ev1_101 = new AudioEvent(); 186 187 ScriptEvent ev2_101 = new CHPRadioEvent(); 188 189 ScriptEvent ev1_121 = new TMTRadioEvent(); 190 191 ScriptEvent ev2_121 = new ATMSEvaluationEvent(); 192 193 instance.incidents.get(1).addNewEvent(ev1_101, 25);//Fourth 194 instance.incidents.get(1).addNewEvent(ev2_101, 0);//Earliest; higher index. Second 195 196 instance.incidents.get(0).addNewEvent(ev1_121, 0);//Earliest; lowest index. First 197 instance.incidents.get(0).addNewEvent(ev2_121, 10);//Third 198 123 199 ArrayList<TimeSlice> result = instance.allSlices(); 124 assertEquals(expResult, result); 125 // TODO review the generated test code and remove the default call to fail. 126 fail("The test case is a prototype."); 200 assertEquals(4, result.size()); 201 assertEquals(ev1_121, result.get(0).events.get(0)); 202 assertEquals(ev2_101, result.get(1).events.get(0)); 203 assertEquals(ev2_121, result.get(2).events.get(0)); 204 assertEquals(ev1_101, result.get(3).events.get(0)); 205 127 206 } 128 207 … … 134 213 System.out.println("absoluteLength"); 135 214 SimulationScript instance = new SimulationScript(); 136 int expResult = 0;137 215 int result = instance.absoluteLength(); 138 assertEquals(expResult, result); 139 // TODO review the generated test code and remove the default call to fail. 140 fail("The test case is a prototype."); 216 assertEquals(0, result); 217 218 instance.incidents.set(0, new ScriptIncident(101, null, null, instance)); 219 instance.incidents.get(0).updateLength(); 220 assertEquals(0, instance.incidents.get(0).offset); 221 assertEquals(0, instance.incidents.get(0).length); 222 result = instance.absoluteLength(); 223 assertEquals(0, result); 224 225 instance.incidents.get(0).addNewEvent(new AudioEvent(), 0); 226 instance.incidents.get(0).updateLength(); 227 assertEquals(0, instance.incidents.get(0).offset); 228 assertEquals(1, instance.incidents.get(0).length); 229 result = instance.absoluteLength(); 230 assertEquals(1, result); 231 232 instance.incidents.get(0).setOffset(10); 233 instance.incidents.get(0).updateLength(); 234 assertEquals(10, instance.incidents.get(0).offset); 235 assertEquals(1, instance.incidents.get(0).length); 236 result = instance.absoluteLength(); 237 assertEquals(11, result); 238 239 ((ScriptEvent) instance.incidents.get(0).slices.get(0).events.get(0)).length = 45; 240 instance.incidents.get(0).updateLength(); 241 assertEquals(10, instance.incidents.get(0).offset); 242 assertEquals(45, instance.incidents.get(0).length); 243 result = instance.absoluteLength(); 244 assertEquals(55, result); 245 } 246 247 @Override 248 public void update(Observable o, Object arg) 249 { 250 updateFlag = true; 251 } 252 253 /** 254 * Test of incidentCount method, of class SimulationScript. 255 */ 256 public void testIncidentCount() 257 { 258 System.out.println("incidentCount"); 259 SimulationScript instance = new SimulationScript(); 260 int result = instance.incidentCount(); 261 assertEquals(0, result); 262 instance.incidents.set(0, new ScriptIncident(101, null, null, instance)); 263 result = instance.incidentCount(); 264 assertEquals(1, result); 265 141 266 } 142 267
Note: See TracChangeset
for help on using the changeset viewer.
