use of com.willwinder.universalgcodesender.pendantui.PendantConfigBean.StepSizeOption in project Universal-G-Code-Sender by winder.
the class PendantUITest method testStart.
@Test
public void testStart() throws Exception {
// This is what we're about to do...
/* 1. Send two gcode commands via a single http request "G91;G90"
* expect it to result in two separate calls to sendGcodeCommand, one for each gCode command
* and because we call substituteValues(), it'll also call updateSystemState
*/
mockBackend.updateSystemState(EasyMock.anyObject(SystemStateBean.class));
EasyMock.expect(EasyMock.expectLastCall()).once();
mockBackend.sendGcodeCommand("G91");
EasyMock.expect(EasyMock.expectLastCall()).once();
mockBackend.sendGcodeCommand("G90");
EasyMock.expect(EasyMock.expectLastCall()).once();
// 2. Commands
mockBackend.performHomingCycle();
EasyMock.expect(EasyMock.expectLastCall()).once();
mockBackend.killAlarmLock();
EasyMock.expect(EasyMock.expectLastCall()).once();
mockBackend.toggleCheckMode();
EasyMock.expect(EasyMock.expectLastCall()).once();
mockBackend.send();
EasyMock.expect(EasyMock.expectLastCall()).once();
// 3. Call some invalid commands which wont reach the backend.
// 4. Change the mode to sending and call pause/resume and cancel.
mockBackend.pauseResume();
EasyMock.expect(EasyMock.expectLastCall()).once();
mockBackend.cancel();
EasyMock.expect(EasyMock.expectLastCall()).once();
// 5. Adjust machine location.
mockBackend.adjustManualLocation(1, 2, 3, 4.0, 1.0, UnitUtils.Units.UNKNOWN);
EasyMock.expect(EasyMock.expectLastCall()).once();
// 6. Get system state
mockBackend.updateSystemState(EasyMock.anyObject(SystemStateBean.class));
EasyMock.expect(EasyMock.expectLastCall()).times(2);
// 7. Get settings
Settings settings = new Settings();
settings.getPendantConfig().getStepSizeList().add(new StepSizeOption("newStepSizeOptionValue", "newStepSizeOptionLabel", false));
EasyMock.expect(mockBackend.getSettings()).andReturn(settings).once();
// /////////////////////////
// Start mock and do it! //
// /////////////////////////
EasyMock.replay(mockBackend);
pendantUI.setPort(23123);
String url = pendantUI.start().get(0).getUrlString();
systemState.setControlState(ControlState.COMM_IDLE);
pendantUI.setSystemState(systemState);
// test resource handler
String indexPage = getResponse(url);
assertTrue(indexPage.contains("$(function()"));
// 1. Send a command
getResponse(url + "/sendGcode?gCode=G91%3BG90");
// 2. Send commands
getResponse(url + "/sendGcode?gCode=$H");
getResponse(url + "/sendGcode?gCode=$X");
getResponse(url + "/sendGcode?gCode=$C");
getResponse(url + "/sendGcode?gCode=SEND_FILE");
// 3. Call some invalid commands which wont reach the backend.
getResponse(url + "/sendGcode?gCode=PAUSE_RESUME_FILE");
getResponse(url + "/sendGcode?gCode=CANCEL_FILE");
// 4. Change the mode to sending and call pause/resume and cancel.
systemState.setControlState(ControlState.COMM_SENDING);
getResponse(url + "/sendGcode?gCode=PAUSE_RESUME_FILE");
getResponse(url + "/sendGcode?gCode=CANCEL_FILE");
// 5. Adjust machine location.
systemState.setControlState(ControlState.COMM_IDLE);
String adjustManualLocationResponse = getResponse(url + "/adjustManualLocation?dirX=1&dirY=2&dirZ=3&stepSize=4.0");
// 6. Get system state
SystemStateBean systemStateTest = new Gson().fromJson(getResponse(url + "/getSystemState"), SystemStateBean.class);
assertEquals(ControlState.COMM_IDLE, systemStateTest.getControlState());
systemState.setControlState(ControlState.COMM_SENDING);
systemStateTest = new Gson().fromJson(getResponse(url + "/getSystemState"), SystemStateBean.class);
assertEquals(ControlState.COMM_SENDING, systemStateTest.getControlState());
// 7. Get settings
String configResponse = getResponse(url + "/config");
assertTrue(configResponse.contains("shortCutButtonList"));
assertTrue(configResponse.contains("newStepSizeOptionValue"));
// Wrap up.
pendantUI.stop();
assertTrue(pendantUI.getServer().isStopped());
// Verify that all the EasyMock functions were called.
EasyMock.verify(mockBackend);
}
Aggregations