use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.
the class ScanRequestConverterTest method testScriptFilesIncludedCorrectly.
@Test
public void testScriptFilesIncludedCorrectly() throws Exception {
// Arrange
final String beforeScanScript = "/path/to/before.py";
final String afterScanScript = "/path/to/after.py";
final IScriptFiles scriptFiles = new ScriptFiles();
mappingBean.setScriptFiles(scriptFiles);
scriptFiles.setBeforeScanScript(beforeScanScript);
scriptFiles.setAfterScanScript(afterScanScript);
scriptFiles.setAlwaysRunAfterScript(true);
// Act - covert mapping bean to scan request
final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
// Assert
final ScriptRequest beforeScriptReq = scanRequest.getBeforeScript();
assertThat(beforeScriptReq, is(notNullValue()));
assertThat(beforeScriptReq.getLanguage(), is(SPEC_PASTICHE));
assertThat(beforeScriptReq.getFile(), is(equalTo(beforeScanScript)));
final ScriptRequest afterScriptReq = scanRequest.getAfterScript();
assertThat(afterScriptReq, is(notNullValue()));
assertThat(afterScriptReq.getLanguage(), is(SPEC_PASTICHE));
assertThat(afterScriptReq.getFile(), is(equalTo(afterScanScript)));
assertThat(scanRequest.isAlwaysRunAfterScript(), is(true));
// Act again - convert the scan request back to a mapping bean
scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
// Assert again
final IScriptFiles newScriptFiles = newMappingBean.getScriptFiles();
assertThat(newScriptFiles, is(notNullValue()));
assertThat(newScriptFiles.getBeforeScanScript(), is(equalTo(beforeScanScript)));
assertThat(newScriptFiles.getAfterScanScript(), is(equalTo(afterScanScript)));
}
use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.
the class GDAJythonScriptServiceTest method testExecuteLocateScript.
@Test
public void testExecuteLocateScript() throws Exception {
File testFile = File.createTempFile("test", ".py", null);
testFile.deleteOnExit();
String testFilePath = testFile.getAbsolutePath();
when(mockCommandRunner.locateScript("test.py")).thenReturn(testFilePath);
ScriptRequest scriptRequest = new ScriptRequest("test.py", SPEC_PASTICHE);
scriptService.execute(scriptRequest);
verify(mockCommandRunner).evaluateCommand("run '" + testFilePath + "'");
}
use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.
the class GDAJythonScriptServiceTest method testExecuteUnsupportedScriptLanguage.
@Test(expected = UnsupportedLanguageException.class)
public void testExecuteUnsupportedScriptLanguage() throws Exception {
ScriptRequest scriptRequest = new ScriptRequest("/tmp/noSuchFile.py", GROOVY);
scriptService.execute(scriptRequest);
}
use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.
the class ScanRequestConverter method createScriptRequest.
private ScriptRequest createScriptRequest(String scriptFile) {
if (scriptFile == null || scriptFile.isEmpty()) {
return null;
}
final ScriptRequest scriptRequest = new ScriptRequest();
scriptRequest.setLanguage(ScriptLanguage.SPEC_PASTICHE);
scriptRequest.setFile(scriptFile);
return scriptRequest;
}
use of org.eclipse.scanning.api.script.ScriptRequest in project gda-core by openGDA.
the class DiffractionCalibrationMergeRequestHandler method generateScriptRequest.
private ScriptRequest generateScriptRequest(DiffractionCalibrationMergeRequest request) {
URL calibrationFile = request.getValue().iterator().next();
String scriptBody = generateScript(calibrationFile);
try {
var scriptfile = createFile(createScriptName(calibrationFile));
writeScript(scriptBody, scriptfile);
return new ScriptRequest(scriptfile.getAbsolutePath());
} catch (IOException e) {
logger.error("Diffraction configuration directory not correctly configured", e);
return null;
}
}
Aggregations