# FWDEngineDescriptor.java

    /*
    ** Module   : FWDEngineDescriptor.java
    ** Abstract : Test engine descriptor.
    **
    ** Copyright (c) 2023-2025, Golden Code Development Corporation.
    **
    ** -#- -I- --Date-- ---------------------------------Description---------------------------------
    ** 001 VVT 20230318 Created initial version.
    ** 002 VVT 20230428 Fixed error propagation (See #3827-350) and source formatting.
    **                  Tags support added to FWD engine (FWD extension). Console is switched
    **                  to program mode for the period legacy code is running. See #3827-435.
    ** 003 VVT 20240325 Unused import statement removed.
    ** 004 VVT 20240408 Minor style fixes. See #8406-70.
    ** 005 EVL 20250203 Changed method name to get console helper to ConsoleHelper.getConsoleHelper().
    */
    /*
    ** This program is free software: you can redistribute it and/or modify
    ** it under the terms of the GNU Affero General Public License as
    ** published by the Free Software Foundation, either version 3 of the
    ** License, or (at your option) any later version.
    **
    ** This program is distributed in the hope that it will be useful,
    ** but WITHOUT ANY WARRANTY; without even the implied warranty of
    ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ** GNU Affero General Public License for more details.
    **
    ** You may find a copy of the GNU Affero GPL version 3 at the following
    ** location: https://www.gnu.org/licenses/agpl-3.0.en.html
    **
    ** Additional terms under GNU Affero GPL version 3 section 7:
    **
    **   Under Section 7 of the GNU Affero GPL version 3, the following additional
    **   terms apply to the works covered under the License.  These additional terms
    **   are non-permissive additional terms allowed under Section 7 of the GNU
    **   Affero GPL version 3 and may not be removed by you.
    **
    **   0. Attribution Requirement.
    **
    **     You must preserve all legal notices or author attributions in the covered
    **     work or Appropriate Legal Notices displayed by works containing the covered
    **     work.  You may not remove from the covered work any author or developer
    **     credit already included within the covered work.
    **
    **   1. No License To Use Trademarks.
    **
    **     This license does not grant any license or rights to use the trademarks
    **     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
    **     of Golden Code Development Corporation. You are not authorized to use the
    **     name Golden Code, FWD, or the names of any author or contributor, for
    **     publicity purposes without written authorization.
    **
    **   2. No Misrepresentation of Affiliation.
    **
    **     You may not represent yourself as Golden Code Development Corporation or FWD.
    **
    **     You may not represent yourself for publicity purposes as associated with
    **     Golden Code Development Corporation, FWD, or any author or contributor to
    **     the covered work, without written authorization.
    **
    **   3. No Misrepresentation of Source or Origin.
    **
    **     You may not represent the covered work as solely your work.  All modified
    **     versions of the covered work must be marked in a reasonable way to make it
    **     clear that the modified work is not originating from Golden Code Development
    **     Corporation or FWD.  All modified versions must contain the notices of
    **     attribution required in this license.
    */
    package com.goldencode.p2j.testengine;

    import java.util.*;

    import org.junit.platform.commons.*;
    import org.junit.platform.engine.*;
    import org.opentest4j.*;

    import com.goldencode.p2j.ui.client.chui.driver.console.*;
    import com.goldencode.p2j.util.*;

    /**
     * Test engine descriptor. Provides this engine unique ID and same thread execution mode.
     */
    public class FWDEngineDescriptor
    extends AbstractBranchTestDescriptor
    {
       /**
        * Switch between the shell and program terminal modes in ChUI.
        */
       private final static ConsoleHelper consoleHelper = ConsoleHelper.getConsoleHelper();

       /**
        * Default constructor for de-serialization only,
        * must never be used by applications.
        */
       public FWDEngineDescriptor()
       {
          this(null);
       }

       /**
        * The constructor.
        *
        * @param uniqueId the {@code UniqueId} for the described {@code TestEngine};
        *        never {@code null}
        */
       public FWDEngineDescriptor(final UniqueId uniqueId)
       {
          super(uniqueId, "FWD Test", Collections.emptySet());
       }

       /**
        * Clean up the supplied {@code context} after execution.
        * <p>
        * Reset the test class instance.
        *
        * @param context
        *        the context to execute in
        *
        * @see   #prepare
        */
       @Override
       public void cleanUp(FWDEngineExecutionContext context)
       throws ErrorConditionException,
              AssertionFailedError
       {
          super.cleanUp(context);

          // Assure we are in the program shell mode while FWD is not active
          consoleHelper.suspend();
       }

       /**
        * Get the preferred of
        * {@linkplain org.junit.platform.engine.support.hierarchical.Node.ExecutionMode execution mode} for
        * parallel execution of this node.
        *
        * @return the preferred execution mode of this node; never {@code null}
        *
        * @see    org.junit.platform.engine.support.hierarchical.Node.ExecutionMode
        */
       @Override
       public ExecutionMode getExecutionMode()
       {
          // No concurrent execution is planned yet
          return ExecutionMode.SAME_THREAD;
       }

       /**
        * Prepare the supplied {@code context} prior to execution.
        * <p>
        * Create test class instance.
        *
        * @see #cleanUp
        */
       @Override
       public FWDEngineExecutionContext prepare(FWDEngineExecutionContext context)
       throws ErrorConditionException,
              AssertionFailedError
       {
          // Assure we are in the program terminal mode while FWD is active
          consoleHelper.resume();

          return super.prepare(context);
       }

       /**
        * Remove this non-root descriptor from its parent and remove all the
        * children from this descriptor.
        * <p>
        * If this method is invoked on a {@linkplain #isRoot root} descriptor,
        * this method must throw a {@link org.junit.platform.commons.JUnitException JUnitException}
        * explaining that a root cannot be removed from the
        * hierarchy.
        */
       @Override
       public void removeFromHierarchy()
       {
          throw new JUnitException("cannot remove the root of a hierarchy");
       }

    }