com.tibco.cep.runtime.service.tester.beunit

## Class BETestEngine

- java.lang.Object
- - com.tibco.cep.runtime.service.tester.beunit.BETestEngine

-     public class BETestEngine
      extends java.lang.Object

  Base Class for BEUnit Test Suite test cases.
  Since:
    5.4.0

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BETestEngine(java.lang.String propertyFile)` Creates a new `BETestEngine` and sets the engine properties based on the propertyFile provide.
    `BETestEngine(java.lang.String ear, java.lang.String tra, java.lang.String cdd, java.lang.String pu, java.lang.String agent)` Creates a new `BETestEngine` and sets the engine properties based on the parameters provided
    `BETestEngine(java.lang.String ear, java.lang.String tra, java.lang.String cdd, java.lang.String pu, java.lang.String agent, boolean apiMode)` Creates a new `BETestEngine` and sets the engine properties based on the parameters provided

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `assertConcept(Concept c, boolean executeRules)` Asserts a new concept into the current run's working memory
    `void` | `assertConcepts(java.util.List concepts, boolean executeRules)` Asserts all concepts into the current run's working memory
    `void` | `assertEvent(SimpleEvent event, boolean executeRules)` Asserts a new event into the current run's working memory
    `void` | `assertEvent(SimpleEvent event, boolean executeRules, java.lang.String preprocessorUri)` Asserts a new event into the current run's working memory
    `void` | `assertEvents(java.util.List events, boolean executeRules)` Asserts all events into the current run's working memory
    `void` | `assertScorecard(Concept sc, boolean executeRules)` Asserts a new scorecard into the current run's working memory
    `void` | `assertScorecards(java.util.List scorecards, boolean executeRules)` Asserts Scorecard into the current run's working memory
    `void` | `clearWorkingMemory()` Clear the working memory for the current tester rule session.
    `void` | `executeRules()` Execute the rules in the current rule session.
    `java.lang.Object` | `invokeCatalogFunction(java.lang.String functionFQName, java.lang.Object[] args)` Invoke a catalog function on the current tester `RuleSession`.
    `java.lang.Object` | `invokeDecisionTable(java.lang.String vrfURI, java.lang.Object[] args)` Invoke the default Decision Table for the virtual rule function on the current tester `RuleSession`.
    `java.lang.Object` | `invokeDecisionTable(java.lang.String vrfURI, java.lang.String tableURI, java.lang.Object[] args)` Invoke a specific Decision Table on the current tester `RuleSession`.
    `java.lang.Object` | `invokeRuleFunction(java.lang.String funcNameUri, java.lang.Object[] args)` Invoke a RuleFunction on the current tester `RuleSession`.
    `java.lang.Object` | `invokeRuleFunctionInSession(java.lang.String funcNameUri, java.lang.Object[] args)` Force the invocation of a RuleFunction in the current tester `RuleSession`.
    `void` | `resetSession()` Reset the current tester rule session to a start state.
    `void` | `resetSession(boolean resetTester)` Reset the current tester rule session to a start state.
    `void` | `shutdown()` Shut down the test engine and the current rule session
    `void` | `start()` Create a new `RuleServiceProvider` and start the rule session specified by the agent constructor parameter

- - ### Constructor Detail

    - #### BETestEngine

          public BETestEngine(java.lang.String propertyFile)

      Creates a new `BETestEngine` and sets the engine properties based on the propertyFile provide. These properties include:
      be.project.ear - the path to the project ear being tested
      be.project.cdd - the path to the .cdd file being used. This may be absolute or relative to the project ear
      be.project.puid - the processing unit ID
      be.project.agent - the agent name or agent key
      be.project.tra (optional) - the .tra file used to configure the engine
      Parameters:
        `propertyFile` -
      Throws:
        `java.io.IOException`
      Since:
        5.4

    - #### BETestEngine

          public BETestEngine(java.lang.String ear,
                              java.lang.String tra,
                              java.lang.String cdd,
                              java.lang.String pu,
                              java.lang.String agent)

      Creates a new `BETestEngine` and sets the engine properties based on the parameters provided
      Parameters:
        `ear` - - the path to the project ear being tested
        `tra` - (optional) - the .tra file used to configure the engine
        `cdd` - - the path to the .cdd file being used. This may be absolute or relative to the project ear
        `pu` - - the processing unit ID
        `agent` - (optional) - the agent name or agent key. If unspecified, the first agent found in the cluster configuration will be used
      Throws:
        `java.lang.Exception`
      Since:
        5.4

    - #### BETestEngine

          public BETestEngine(java.lang.String ear,
                              java.lang.String tra,
                              java.lang.String cdd,
                              java.lang.String pu,
                              java.lang.String agent,
                              boolean apiMode)

      Creates a new `BETestEngine` and sets the engine properties based on the parameters provided
      Parameters:
        `ear` - - the path to the project ear being tested
        `tra` - (optional) - the .tra file used to configure the engine
        `cdd` - - the path to the .cdd file being used. This may be absolute or relative to the project ear
        `pu` - - the processing unit ID
        `agent` - (optional) - the agent name or agent key. If unspecified, the first agent found in the cluster configuration will be used
        `apiMode` - - whether to run the test engine in API mode. In API mode, the channels in the project will not be started, and certain catalog functions will not be available. In many cases, this is the desired behavior while running unit tests, to prevent external side-effects. If set to false, the mode of the test engine will be determined by the specified CDD file.
      Throws:
        `java.lang.Exception`
      Since:
        5.4
      See Also:
        `RuleServiceProvider.MODE_API}`

  - ### Method Detail

    - #### assertConcept

          public void assertConcept(Concept c,
                                    boolean executeRules)
                             throws DuplicateExtIdException

      Asserts a new concept into the current run's working memory
      Parameters:
        `c` - - the Concept to insert
        `executeRules` - - if true, asserting the Concept will execute any related rules
      Throws:
        `DuplicateExtIdException` - - if the external ID of the object to assert already exists in the session.
      Since:
        5.4

    - #### assertScorecard

          public void assertScorecard(Concept sc,
                                      boolean executeRules)
                               throws DuplicateExtIdException

      Asserts a new scorecard into the current run's working memory
      Parameters:
        `sc-` - the Scorecard to insert
        `executeRules` - - if true, asserting the Concept will execute any related rules
      Throws:
        `DuplicateExtIdException`
      Since:
        5.4

    - #### assertConcepts

          public void assertConcepts(java.util.List concepts,
                                     boolean executeRules)

      Asserts all concepts into the current run's working memory
      Parameters:
        `concepts` - - a List of the Concepts to insert
        `executeRules` - - if true, asserting the Concepts will execute any related rules
      Since:
        5.4

    - #### assertScorecards

          public void assertScorecards(java.util.List scorecards,
                                       boolean executeRules)

      Asserts Scorecard into the current run's working memory
      Parameters:
        `scorecards` - - a List of the scorecards to insert
        `executeRules` - - if true, asserting the Concepts will execute any related rules
      Since:
        5.4

    - #### assertEvent

          public void assertEvent(SimpleEvent event,
                                  boolean executeRules,
                                  java.lang.String preprocessorUri)
                           throws DuplicateExtIdException

      Asserts a new event into the current run's working memory
      Parameters:
        `event` - - the Event to insert
        `executeRules` - - if true, asserting the Event will execute any related rules
        `preprocessorUri` - - if specified, the Rule Function will be called with the `event` to simulate a preprocessor. The specified preprocessorUri's arguments must match the SimpleEvent type
      Throws:
        `DuplicateExtIdException` - - if the external ID of the object to assert already exists in the session.
      Since:
        5.4

    - #### assertEvent

          public void assertEvent(SimpleEvent event,
                                  boolean executeRules)
                           throws DuplicateExtIdException

      Asserts a new event into the current run's working memory
      Parameters:
        `event` - - the Event to insert
        `executeRules` - - if true, asserting the Event will execute any related rules
      Throws:
        `DuplicateExtIdException` - - if the external ID of the object to assert already exists in the session.
      Since:
        5.4

    - #### assertEvents

          public void assertEvents(java.util.List events,
                                   boolean executeRules)

      Asserts all events into the current run's working memory
      Parameters:
        `events` - - a List of the Events to insert
        `executeRules` - - if true, asserting the Events will execute any related rules
      Since:
        5.4

    - #### clearWorkingMemory

          public void clearWorkingMemory()

      Clear the working memory for the current tester rule session.
      Since:
        5.4

    - #### executeRules

          public void executeRules()

      Execute the rules in the current rule session. This is typically used after asserting new Concepts or Events into working memory. An `Expecter` can then be used to inspect the results
      Since:
        5.4

    - #### invokeCatalogFunction

          public java.lang.Object invokeCatalogFunction(java.lang.String functionFQName,
                                                        java.lang.Object[] args)

      Invoke a catalog function on the current tester `RuleSession`.
      Parameters:
        `functionFQName` - the fully qualified Catalog function name to be invoked i.e. "System.debugOut"
        `args` - a variable argument specifying the input arguments
      Returns:
        the result of the Catalog function
      Since:
        5.4

    - #### invokeRuleFunction

          public java.lang.Object invokeRuleFunction(java.lang.String funcNameUri,
                                                     java.lang.Object[] args)

      Invoke a RuleFunction on the current tester `RuleSession`.
      Parameters:
        `functionURI` - the URI of the RuleFunction to be invoked
        `args` - an Object array specifies the input arguments
      Returns:
        the result of the RuleFunction
      Since:
        5.4

    - #### invokeRuleFunctionInSession

          public java.lang.Object invokeRuleFunctionInSession(java.lang.String funcNameUri,
                                                              java.lang.Object[] args)

      Force the invocation of a RuleFunction in the current tester `RuleSession`. Generally executing a Rule Function inside of a RuleSession is disallowed due to the side-effects that can occur. This method forces the Rule Function to be invoked, which can be useful to test specific business logic in the unit test.
      Parameters:
        `functionURI` - the URI of the RuleFunction to be invoked
        `args` - an Object array specifies the input arguments
      Returns:
        the result of the RuleFunction
      Since:
        5.6.1

    - #### invokeDecisionTable

          public java.lang.Object invokeDecisionTable(java.lang.String vrfURI,
                                                      java.lang.String tableURI,
                                                      java.lang.Object[] args)

      Invoke a specific Decision Table on the current tester `RuleSession`.
      Parameters:
        `vrfURI` - the URI of the virtual rule function
        `tableURI` - the URI of the Decision Table to be invoked
        `args` - an Object array specifies the input arguments
      Returns:
        Object - an int[] with the matching row numbers of the decision table
      Since:
        5.4

    - #### invokeDecisionTable

          public java.lang.Object invokeDecisionTable(java.lang.String vrfURI,
                                                      java.lang.Object[] args)

      Invoke the default Decision Table for the virtual rule function on the current tester `RuleSession`.
      Parameters:
        `vrfURI` - the URI of the virtual rule function
        `args` - an Object array specifies the input arguments
      Returns:
        Object - an int[] with the matching row numbers of the decision table
      Since:
        5.4

    - #### resetSession

          public void resetSession(boolean resetTester)

      Reset the current tester rule session to a start state. This will perform the following actions:
      - Clear the working memory
      - Reset all timers and clear any scheduled TimeEvents
      - Reset all counters (number of rules fired, number of asserted objects, etc.)
      Parameters:
        `resetTester` - if set to 'true', the reset will also clear the following tracked information:
        - Created entities
        - Modified entities
        - Rules fired
        - Retracted entities
        - Events sent
        The result is that any Expecter methods, such as expectRuleFired, will fail immediately after the call to resetSession. To maintain this information between unit tests, use resetSession(false)
      Throws:
        `java.lang.Exception`
      Since:
        6.0

    - #### resetSession

          public void resetSession()

      Reset the current tester rule session to a start state. This will perform the following actions:
      - Discard any existing Rete Network information (rules fired, modified concepts, sent events, etc.)
      - Clear the working memory
      - Reset all timers and clear any scheduled TimeEvents
      - Reset all counters (number of rules fired, number of asserted objects, etc.)
      This is fully equivalent to calling resetSession(true)
      Throws:
        `java.lang.Exception`
      Since:
        5.4

    - #### shutdown

          public void shutdown()

      Shut down the test engine and the current rule session
      Since:
        5.4

    - #### start

          public void start()

      Create a new `RuleServiceProvider` and start the rule session specified by the agent constructor parameter
      Since:
        5.4