Package gda.jython

Class MockJythonServerFacade

java.lang.Object
gda.jython.MockJythonServerFacade
All Implemented Interfaces:
AliasedCommandProvider, IAuthorisationHolder, IBatonStateProvider, ICommandAborter, ICommandRunner, ICurrentScanController, ICurrentScanInformationHolder, IDefaultScannableProvider, IJythonNamespace, IJythonServerNotifer, IScanDataPointProvider, IScanStatusHolder, IScriptController, ITerminalPrinter, JSFObserver, gda.observable.IObservable

Mock implementation of interfaces usually provided by JythonServerFacade to be used when running tests outside of gda This implementation is used if you set the property JythonServerFacade.dummy to true
  • Constructor Details

    • MockJythonServerFacade

      public MockJythonServerFacade()
  • Method Details

    • getTerminalOutput

      public String getTerminalOutput()
    • setTerminalOutput

      public void setTerminalOutput(String terminalOutput)
    • runCommand

      public void runCommand(String command)
      Description copied from interface: ICommandRunner
      Executes the Jython command in a new thread.

      Non-blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Specified by:
      runCommand in interface ICommandRunner
      Parameters:
      command - to run
    • requestFinishEarly

      public void requestFinishEarly()
      Description copied from interface: ICurrentScanController
      Call requestFinishEarly() on the current scan.
      Specified by:
      requestFinishEarly in interface ICurrentScanController
    • isFinishEarlyRequested

      public boolean isFinishEarlyRequested()
      Specified by:
      isFinishEarlyRequested in interface ICurrentScanController
      Returns:
      true if a request for the current scan to finish early has been made (probably via a gui).
    • print

      public void print(String text)
      Specified by:
      print in interface ITerminalPrinter
      Parameters:
      text -
    • setScanStatus

      public void setScanStatus(JythonStatus newStatus)
    • getScanStatus

      public JythonStatus getScanStatus()
      Specified by:
      getScanStatus in interface IScanStatusHolder
      Returns:
      status of Jython scan e.g. JythonStatus.IDLE
    • isScanRunning

      public boolean isScanRunning()
      Specified by:
      isScanRunning in interface IScanStatusHolder
      Returns:
      true if a scan is running, false otherwise
    • pauseCurrentScan

      public void pauseCurrentScan()
      Specified by:
      pauseCurrentScan in interface ICurrentScanController
    • restartCurrentScan

      public void restartCurrentScan()
      Specified by:
      restartCurrentScan in interface ICurrentScanController
    • resumeCurrentScan

      public void resumeCurrentScan()
      Specified by:
      resumeCurrentScan in interface ICurrentScanController
    • getFromJythonNamespace

      public Object getFromJythonNamespace(String objectName)
      Description copied from interface: IJythonNamespace
      Get a copy of an object from the Jython interpreter. Note that the retrieved object will have to be cast by the local code. As the object will be passed over CORBA, this method should only be used on native types or classes containing only native types.
      Specified by:
      getFromJythonNamespace in interface IJythonNamespace
      Parameters:
      objectName -
      Returns:
      Object
    • placeInJythonNamespace

      public void placeInJythonNamespace(String objectName, Object obj)
      Description copied from interface: IJythonNamespace
      Pass a copy of an object to the Jython interpreter. This object must be relatively simple otherwise it will not be passed over CORBA successfully. So the object must be a native type (or only contain native types) and must not have any object references inside.
      Specified by:
      placeInJythonNamespace in interface IJythonNamespace
      Parameters:
      objectName -
      obj -
    • getAuthorisationLevel

      public int getAuthorisationLevel()
      Description copied from interface: IAuthorisationHolder
      Returns the current authorisation level (this value could be dynamic if a baton is in use)
      Specified by:
      getAuthorisationLevel in interface IAuthorisationHolder
      Returns:
      the authorisationLevel at this moment in time
    • getAuthorisationLevelAtRegistration

      public int getAuthorisationLevelAtRegistration()
      Specified by:
      getAuthorisationLevelAtRegistration in interface IAuthorisationHolder
      Returns:
      the authorisation level ignoring any current baton status
    • setAuthorisationLevel

      public void setAuthorisationLevel(int authorisationLevel)
      Allows tests to change authorisation level returned by getAuthorisationLevel
      Parameters:
      authorisationLevel -
    • addIScanDataPointObserver

      public void addIScanDataPointObserver(IScanDataPointObserver anObserver)
      Description copied from interface: IScanDataPointProvider
      Add an object to this objects's list of IObservers.
      Specified by:
      addIScanDataPointObserver in interface IScanDataPointProvider
      Parameters:
      anObserver - object that implement IObserver and wishes to be notified by this object
    • deleteIScanDataPointObserver

      public void deleteIScanDataPointObserver(IScanDataPointObserver anObserver)
      Description copied from interface: IScanDataPointProvider
      Delete an object from this objects's list of IObservers.
      Specified by:
      deleteIScanDataPointObserver in interface IScanDataPointProvider
      Parameters:
      anObserver - object that implement IObserver and wishes to be notified by this object
    • getLastScanDataPoint

      public IScanDataPoint getLastScanDataPoint()
      Specified by:
      getLastScanDataPoint in interface IScanDataPointProvider
    • setScriptStatus

      public void setScriptStatus(JythonStatus newStatus)
      Specified by:
      setScriptStatus in interface IScriptController
      Parameters:
      newStatus - see values in Jython e.g. JYTHON.IDLE
    • getScriptStatus

      public JythonStatus getScriptStatus()
      Specified by:
      getScriptStatus in interface IScriptController
      Returns:
      status see values in Jython e.g. JYTHON.IDLE
    • setScriptName

      public void setScriptName(String scriptName)
    • getScriptName

      public Optional<String> getScriptName()
      Description copied from interface: IScriptController
      Returns the name of the currently running script, if present
      Specified by:
      getScriptName in interface IScriptController
      Returns:
      name of current script
    • abortCommands

      public void abortCommands()
      Specified by:
      abortCommands in interface ICommandAborter
      See Also:
    • beamlineHalt

      public void beamlineHalt()
      Specified by:
      beamlineHalt in interface ICommandAborter
      See Also:
    • pauseCurrentScript

      public void pauseCurrentScript()
      Specified by:
      pauseCurrentScript in interface IScriptController
      See Also:
    • resumeCurrentScript

      public void resumeCurrentScript()
      Specified by:
      resumeCurrentScript in interface IScriptController
      See Also:
    • update

      public void update(Object dataSource, Object data)
      Specified by:
      update in interface IBatonStateProvider
      Parameters:
      dataSource -
      data -
    • addBatonChangedObserver

      public void addBatonChangedObserver(gda.observable.IObserver anObserver)
      Specified by:
      addBatonChangedObserver in interface IBatonStateProvider
      Parameters:
      anObserver -
    • amIBatonHolder

      public boolean amIBatonHolder()
      Description copied from interface: IBatonStateProvider
      Checks if the caller is the holder of the baton
      Specified by:
      amIBatonHolder in interface IBatonStateProvider
      Returns:
      true if the caller holds the baton false otherwise
      See Also:
    • assignBaton

      public void assignBaton(int receiverIndex, int holderIndex)
      Specified by:
      assignBaton in interface IBatonStateProvider
      Parameters:
      receiverIndex -
      holderIndex -
      See Also:
    • deleteBatonChangedObserver

      public void deleteBatonChangedObserver(gda.observable.IObserver anObserver)
      Specified by:
      deleteBatonChangedObserver in interface IBatonStateProvider
      Parameters:
      anObserver -
    • getBatonHolder

      public ClientDetails getBatonHolder()
      Description copied from interface: IBatonStateProvider
      Returns the baton holder from the list of known clients connected, even if the baton holder is this client.
      Specified by:
      getBatonHolder in interface IBatonStateProvider
      Returns:
      ClientDetails
    • getOtherClientInformation

      public ClientDetails[] getOtherClientInformation()
      Specified by:
      getOtherClientInformation in interface IBatonStateProvider
      Returns:
      ClientDetails[]
      See Also:
    • isBatonHeld

      public boolean isBatonHeld()
      Description copied from interface: IBatonStateProvider
      This checks if the baton is held, at all, by any client. It does not check it the caller is the baton holder.
      Specified by:
      isBatonHeld in interface IBatonStateProvider
      Returns:
      true if the baton is held by any client, false otherwise
      See Also:
    • returnBaton

      public void returnBaton()
      Specified by:
      returnBaton in interface IBatonStateProvider
      See Also:
    • addIObserver

      public void addIObserver(gda.observable.IObserver anIObserver)
      Specified by:
      addIObserver in interface gda.observable.IObservable
    • deleteIObserver

      public void deleteIObserver(gda.observable.IObserver anIObserver)
      Specified by:
      deleteIObserver in interface gda.observable.IObservable
    • deleteIObservers

      public void deleteIObservers()
      Specified by:
      deleteIObservers in interface gda.observable.IObservable
    • evaluateCommand

      public String evaluateCommand(String command)
      Description copied from interface: ICommandRunner
      Runs a single line Jython command through the interpreter and returns the result in the form of a string. Note: this method waits until the command has finished so it can return the result. If the command takes a long time it will hang the thread which calls this method. So this method must be called in a separate thread from the main GUI thread, else the GUI will seize up until the command given to this method has returned. For an example of the, see the gda.jython.JythonTerminal class.

      Blocking, Not interruptible, Not script locked.
      See ICommandRunner for the other options.
      Specified by:
      evaluateCommand in interface ICommandRunner
      Parameters:
      command - to run
      Returns:
      the string representation of the result
    • setEvaluateCommandResult

      public void setEvaluateCommandResult(String evaluateCommandResult)
    • changeVisitID

      public void changeVisitID(String visitID)
      Description copied from interface: IBatonStateProvider
      Switches the visit this client will collect data as when it holds the baton.
      Specified by:
      changeVisitID in interface IBatonStateProvider
      Parameters:
      visitID -
    • revertToOriginalUser

      public void revertToOriginalUser()
      Description copied from interface: IBatonStateProvider
      Reverts to the original user this client was initially logged in as.
      Specified by:
      revertToOriginalUser in interface IBatonStateProvider
      See Also:
    • getAliasedCommands

      public Collection<String> getAliasedCommands()
      Description copied from interface: AliasedCommandProvider
      Returns the list of alias in the GDA command server
      Specified by:
      getAliasedCommands in interface AliasedCommandProvider
      Returns:
      the aliased commands
    • getAliasedVarargCommands

      public Collection<String> getAliasedVarargCommands()
      Description copied from interface: AliasedCommandProvider
      Returns the list of variable argument alias in the GDA command server
      Specified by:
      getAliasedVarargCommands in interface AliasedCommandProvider
      Returns:
      the list of variable argument alias
    • hasAlias

      public boolean hasAlias(String command)
      Description copied from interface: AliasedCommandProvider
      Checks if the the given command is aliased (either vararg or not)
      Specified by:
      hasAlias in interface AliasedCommandProvider
      Parameters:
      command - the string to check
      Returns:
      whether the command is aliased or not
    • getMyDetails

      public ClientDetails getMyDetails()
      Description copied from interface: IBatonStateProvider
      Returns the current ClientDetails for this client. What is returned will change depending on the baton status and if the user has been switched using the switchUser method.

      The authorisationLevel returned takes into account any alternate user, but not whether the baton is held. For this, call getAuthorisationLevel().

      Specified by:
      getMyDetails in interface IBatonStateProvider
      Returns:
      ClientDetails
    • requestBaton

      public boolean requestBaton()
      Specified by:
      requestBaton in interface IBatonStateProvider
      Returns:
      boolean
      See Also:
    • sendMessage

      public void sendMessage(String message)
      Description copied from interface: IBatonStateProvider
      Broadcast a message to other users on this beamline. Such messages will be displayed in a special viewer.
      Specified by:
      sendMessage in interface IBatonStateProvider
      Parameters:
      message -
    • getMessageHistory

      public List<UserMessage> getMessageHistory()
      Description copied from interface: IBatonStateProvider
      Returns previous messages sent during this visit.
      Specified by:
      getMessageHistory in interface IBatonStateProvider
    • switchUser

      public boolean switchUser(String username, String password)
      Specified by:
      switchUser in interface IBatonStateProvider
      Parameters:
      username -
      password -
      Returns:
      true if switch successful
      See Also:
    • getAllNamesForObject

      public Set<String> getAllNamesForObject(Object obj) throws DeviceException
      Description copied from interface: IJythonNamespace
      Returns all names for an Object in the Jython namespace
      Specified by:
      getAllNamesForObject in interface IJythonNamespace
      Parameters:
      obj -
      Returns:
      All names that refer to the Object in the Jython namespace
      Throws:
      DeviceException
    • getAllNamesForType

      public <F extends Findable> Set<String> getAllNamesForType(Class<F> clazz)
      Description copied from interface: IJythonNamespace
      As a Collection, this should be able to be passed over any serialisation method and is therefore available to client code. We may have e.g. Scannables written entirely in Jython that we may not be able to pass across, meaning the similar method LocalJython#getAllObjectsOfType is limited to server side.
      Specified by:
      getAllNamesForType in interface IJythonNamespace
      Parameters:
      clazz - a Class extending Findable
      Returns:
      a set of all names of all objects of a type in the Jython namespace.
    • runScript

      public CommandThreadEvent runScript(File script)
      Description copied from interface: ICommandRunner
      Runs the Jython script, and changes the ScriptStatus as is goes.

      Non-blocking, Interruptible, Script locked.
      See ICommandRunner for the other options.
      Specified by:
      runScript in interface ICommandRunner
      Parameters:
      script - to run
      Returns:
      status
    • runScript

      public CommandThreadEvent runScript(String scriptContents)
      Description copied from interface: ICommandRunner
      Runs the jython command string, and changes the ScriptStatus as is goes.

      Non-blocking, Interruptible, Script locked.
      See ICommandRunner for the other options.
      Specified by:
      runScript in interface ICommandRunner
      Parameters:
      scriptContents - to run
      Returns:
      status
    • runsource

      public boolean runsource(String command)
      Description copied from interface: ICommandRunner
      Similar to ICommandRunner.runCommand(java.lang.String), except that a boolean is returned if the command was complete or if additional lines of a multi-line command are required. Used only by the JythonTerminal to determine which prompt to display. Note: this method waits until the command has finished so it can return the result. If the command takes a long time it will hang the thread which calls this method. So this method must be called in a separate thread from the main GUI thread, else the GUI will seize up until the command given to this method has returned.

      Blocking, Interruptible, Not script locked.
      See ICommandRunner for the other options.
      Specified by:
      runsource in interface ICommandRunner
      Parameters:
      command - to run
      Returns:
      true if command was incomplete and more is required (eg "if True:"), false otherwise (including on error)
      See Also:
    • locateScript

      public String locateScript(String scriptToRun)
      Description copied from interface: ICommandRunner
      Find a script with given name in the GDA's script project folders.
      Specified by:
      locateScript in interface ICommandRunner
      Parameters:
      scriptToRun - The name of a Jython script file.
      Returns:
      A path to the script in one of the project folders. The first file with matching name will be returned, or null if no file could be located.
    • addScanEventObserver

      public void addScanEventObserver(gda.observable.IObserver anObserver)
      Description copied from interface: IScanDataPointProvider
      Register an object to receive ScanEvent messages to be notified of progress, but not data during scans.
      Specified by:
      addScanEventObserver in interface IScanDataPointProvider
      Parameters:
      anObserver -
    • deleteScanEventObserver

      public void deleteScanEventObserver(gda.observable.IObserver anObserver)
      Description copied from interface: IScanDataPointProvider
      Delete an object from this objects's list of IObservers which receive ScanEvent messages
      Specified by:
      deleteScanEventObserver in interface IScanDataPointProvider
      Parameters:
      anObserver -
    • notifyServer

      public void notifyServer(Object source, Object data)
      Description copied from interface: IJythonServerNotifer
      This method passes information from a scan to the local facade objects. These in turn pass the data to the local version of the GUI panel which created the scan.
      Specified by:
      notifyServer in interface IJythonServerNotifer
      Parameters:
      source - The serialized scan object which has created the data.
      data - A vector carrying the latest data collected by the scan
    • setCurrentScan

      public void setCurrentScan(Scan newScan)
      This should be used by tests to tell this class the current scan. In the real system the JythonServer would know what the current scan is and so would be able to provide information about it. In this mock, the unit tests need to tell this MockJythonServer what the current scan is.
      Specified by:
      setCurrentScan in interface ICurrentScanInformationHolder
      Parameters:
      newScan -
    • getCurrentScanInformation

      public ScanInformation getCurrentScanInformation()
      Description copied from interface: ICurrentScanInformationHolder
      Return some information about the currently running scan
      Specified by:
      getCurrentScanInformation in interface ICurrentScanInformationHolder
      Returns:
      ScanInformation
    • getDefaultScannables

      public Vector<Scannable> getDefaultScannables()
      Description copied from interface: IDefaultScannableProvider
      Returns a collection of scannable objects which must be called in every scan. Used by scans to construct the list of objects whose positions are reported at every node of a scan.

      This returns a collection of object references of all the objects in the Jython namepsace listed in the DefaultScannablesList object named "scannablesList" in the configuration information.

      As this method returns object references, this method must only be called by objects local to this object. This method must never be available remotely.

      Specified by:
      getDefaultScannables in interface IDefaultScannableProvider
      Returns:
      Collection
    • setScanObserver

      public void setScanObserver(String scanObserver)
    • executeCommand

      public void executeCommand(String command)
      Description copied from interface: ICommandRunner
      Executes the Jython command in a new thread.

      Blocking, Interruptible, Not script locked and throws ScriptExecutionException
      Specified by:
      executeCommand in interface ICommandRunner
      Parameters:
      command -