Class Scene.Builder

java.lang.Object
jp.co.moneyforward.autotest.framework.action.Scene.Builder
All Implemented Interfaces:
WithOid
Enclosing interface:
Scene

public static class Scene.Builder extends Object implements WithOid
A builder for Scene class.
See Also:
  • Constructor Details

    • Builder

      public Builder(String defaultVariableName)

      Creates an instance of this class.

      Note that defaultVariableName is only used by this Builder, not directly by the Scene built by this object.

      Parameters:
      defaultVariableName - A name of field used when use add methods without explicit input/output target field names.
    • Builder

      public Builder()
      Creates an instance of this class. If you add an act to this object without explicitly specifying variable name with which the act interacts, a NullPointerException will be thrown.
  • Method Details

    • name

      public Scene.Builder name(String name)
      Sets a name of a scene built by this builder object.
      Parameters:
      name - A name of a scene.
      Returns:
      This object.
    • with

      public final Scene.Builder with(UnaryOperator<Scene.Builder> op)

      // @formatter:off A "syntax-sugar" method to group a sequence of method calls to this Builder object.

      That is, you can do:

      new SceneBuilder.with(b -> b.add(...)
                      .add(...)
                      .add(...))
                      .build();
      

      Note that the operator op is supposed to return this object.

      // @formatter:on

      Parameters:
      op - A unary operator that groups operator on this object.
      Returns:
      This object returned by op.
    • add

      public final <T,R> Scene.Builder add(Act<T,R> act)
      Adds an Act to this builder. defaultFieldName is used for both input and output. Note that in case T and R are different, the field will have a different type after leafAct execution from the value before it is executed.
      Type Parameters:
      T - Type of input parameter field.
      R - Type of output parameter field.
      Parameters:
      act - An act object to be added to this builder.
      Returns:
      This object.
    • act

      public final <T,R> Scene.Builder act(Act<T,R> act)

      Synonym of add(Act).

      Prefer this over Builder#add(Act) as usage of this method results in more readable code in general. This method is also useful for languages that run on JVM, but doesn't have method overloading.

      Parameters:
      act - An act to be added.
      Returns:
      This object
    • add

      public final <T,R> Scene.Builder add(String outputVariableName, Act<T,R> act)
      Adds an act to this builder. The output of an act goes to a variable specified by outputVariableName in the scene's variable store.
      Type Parameters:
      T - Input type of act.
      R - Output type of act.
      Parameters:
      outputVariableName - A variable name act's output goes to.
      act - An Act to be added.
      Returns:
      This object
    • add

      public final <T,R> Scene.Builder add(String outputVariableName, Act<T,R> act, String inputVariableName)
      Adds an act to this object so that it takes input from inputVariableName and writes output to outputVariableName.
      Type Parameters:
      T - An input value type
      R - An output value type
      Parameters:
      outputVariableName - A string to specify an output variable.
      act - An Act to be added to this object.
      inputVariableName - A string to specify an input variable.
      Returns:
      This object
    • assertion

      public final <R> Scene.Builder assertion(Function<R, com.github.valid8j.pcond.fluent.Statement<R>> assertion)
      Adds a function assertion to this builder object.
      Type Parameters:
      R - Type of value to be checked by assertion.
      Parameters:
      assertion - An assertion to be added to this object.
      Returns:
      This object.
    • assertions

      public final <R> Scene.Builder assertions(Function<R, com.github.valid8j.pcond.fluent.Statement<R>>... assertions)
      Adds assertions to this builder object.
      Type Parameters:
      R - Type of the value to be verified.
      Parameters:
      assertions - Functions that generates statements to be added.
      Returns:
      This object.
    • assertions

      public final <R> Scene.Builder assertions(String variableName, Function<R, com.github.valid8j.pcond.fluent.Statement<R>>... assertions)

      Returns an AssertionAct object that verifies a variable in a currently ongoing scene call's variable store. The variable in the store is specified by inputFieldName. This method is implemented as:

      this.addCall(assertionCall(variableName, new Value<>(), singletonList(assertionAct), variableName)), where Value is a trivial act which just copies its input variable to an output variable.

      Type Parameters:
      R - Type of the variable specified by inputVariableName.
      Parameters:
      variableName - A name of an input variable to be verified.
      assertions - An assertion function
      Returns:
      This object
    • add

      public final Scene.Builder add(Scene scene)

      Adds a given scene to this builder object. A call to the scene will be created (a SceneCall object), and it will be a child of the scene that this builder builds.

      The child call will use the working variable store of the parent scene (i.e., a scene built by this builder) as its input variable store. With this mechanism, the child can reference the values of the

      Parameters:
      scene - A scene to be added.
      Returns:
      This object,
    • scene

      public final Scene.Builder scene(Scene scene)

      Synonym of add(Scene).

      Prefer this over Builder#add(Scene) as usage of this method results in more readable code in general. This method is also useful for languages that run on JVM, but doesn't have method overloading.

      Parameters:
      scene - A scene to be added.
      Returns:
      This object
    • retry

      public final Scene.Builder retry(Call call, int times, Class<? extends Throwable> onException, int interval)

      Adds a call that retries a given call. The call retries given times on a failure designated by a class onException. An interval between tries will be interval seconds.

      Note that times means number of "RE"-tries. If you give 1, it will be retried once after interval seconds, if the first try fails.

      Parameters:
      call - A call to be retried
      times - Number of retries at maximum.
      onException - An exception class on which retries should be attempted.
      interval - Interval between tries.
      Returns:
      A call that retries a given call.
    • retry

      public final Scene.Builder retry(Call call, int times, Class<? extends Throwable> onException)
      This method is implemented as a shorthand for this.retry(call, times, onException, 5).
      Parameters:
      call - A call to be retried
      times - How many times call should be retried until it succeeds.
      Returns:
      This object
    • retry

      public final Scene.Builder retry(Call call, int times)
      This method is implemented as a shorthand for this.retry(call, times, AssertionFailedError.class).
      Parameters:
      call - A call to be retried
      times - How many times call should be retried until it succeeds.
      Returns:
      This object
    • retry

      public final Scene.Builder retry(Scene scene)
      Adds a scene that retries a given scene twice. Note that, scene is attempted three times in total.
      Parameters:
      scene - A scene to be added and retried on a failure.
      Returns:
      This object
    • retry

      public final Scene.Builder retry(Call call)
      This method is implemented as a shorthand for this.retry(call, 2).
      Parameters:
      call - A call object to be added.
      Returns:
      This object.
    • addCall

      public Scene.Builder addCall(Call call)

      Adds a call to this object as a child. You need to ensure that requirements of call are satisfied in the context it will be run by yourself.

      For instance, if the call is a SceneCall, the variable store from which it reads needs to be prepared beforehand by one of preceding calls.

      Parameters:
      call - A Call object to be added.
      Returns:
      This object.
    • build

      public Scene build()
      Builds a Scene object.
      Returns:
      A Scene object.
    • end

      public Scene end()
      A synonym of build(). Use this with Scene.begin().
      Returns:
      A new scene object
      See Also:
    • oid

      public String oid()
      Returns an object identifier of this object.
      Specified by:
      oid in interface WithOid
      Returns:
      An object identifier of this object.