Search in sources :

Example 1 with ScriptRequest

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)));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) Test(org.junit.Test)

Example 2 with ScriptRequest

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 + "'");
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) File(java.io.File) Test(org.junit.Test)

Example 3 with ScriptRequest

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);
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) Test(org.junit.Test)

Example 4 with 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;
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest)

Example 5 with 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;
    }
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) IOException(java.io.IOException) URL(java.net.URL)

Aggregations

ScriptRequest (org.eclipse.scanning.api.script.ScriptRequest)8 Test (org.junit.Test)5 File (java.io.File)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)1 ScanningException (org.eclipse.scanning.api.scan.ScanningException)1 IScriptFiles (uk.ac.diamond.daq.mapping.api.IScriptFiles)1 ScriptFiles (uk.ac.diamond.daq.mapping.impl.ScriptFiles)1 FrameCollectingScannable (uk.ac.diamond.daq.scanning.FrameCollectingScannable)1 FrameRequestDocument (uk.ac.gda.api.acquisition.parameters.FrameRequestDocument)1