package org.reprap.devices; import org.reprap.comms.Communicator; import org.reprap.comms.port.TestPort; import org.reprap.comms.port.testhandlers.TestDevice; import org.reprap.comms.port.testhandlers.TestStepper; import org.reprap.comms.snap.SNAPAddress; import org.reprap.comms.snap.SNAPCommunicator; import org.testng.Assert; /** * * @testng.configuration groups = "comms,all,all-offline" * */ public class StepperTest { TestPort port; GenericStepperMotor motor; Communicator communicator; /** * @testng.configuration beforeSuite = "true" */ public void setUp() throws Exception { port = new TestPort(); port.addDevice(new TestStepper(), new SNAPAddress(2)); Communicator communicator = new SNAPCommunicator(port, new SNAPAddress(0)); motor = new GenericStepperMotor(communicator, new SNAPAddress(2), 200); } /** * @testng.configuration afterSuite = "true" */ public void tearDown() { motor.dispose(); //communicator.dispose(); port.close(); } /** * @testng.test groups = "comms,all,all-offline" * timeOut="1000" */ public void testStepperBasic() throws Exception { int version = motor.getVersion(); Assert.assertEquals(version, TestDevice.version); } /** * A test that drops the first received packet to check * that the request will time out and be re-sent * @testng.test groups = "comms,all,all-offline" * timeOut="5000" */ public void testTimeouts() throws Exception { port.dropNextIncomingPacket(); int version = motor.getVersion(); Assert.assertEquals(version, TestDevice.version); } }