/*
** Module   : SessionSettings.java
** Abstract : configuration to establish a remote session 
**
** Copyright (c) 2008-2021, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 GES 20081218 Stores configuration to establish a remote session.
** 002 CA  20210827 Refactored to allow other test types, beside terminal (which can be executed from the same 
**                  test suite).  Added SOAP and REST web service tests.
** 003 CA  20210902 The executor must be thread-local.
*/

/*
** 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 should have received a copy of the GNU Affero General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.goldencode.harness;

/**
 * Stores configuration required for the test's sessions.
 */
public abstract class SessionSettings
{
   /** List of field names for which an editing prompt should be forced. */
   public String prompts = null;
   
   /** The executor for this type of tests, unique instance per thread. */
   protected ThreadLocal<TestExecutor> executor = new ThreadLocal<>();
   
   /**
    * Default constructor.
    */
   public SessionSettings()
   {
   }
   
   /**
    * Copy constructor.
    *
    * @param    original
    *           Instance from which to copy.
    */
   public SessionSettings(SessionSettings original)
   {
      this.prompts     = original.prompts;
   }

   /**
    * Get text representation of the configurations for this session - each pair represents the configuration
    * name and its value.
    * 
    * @return   See above.
    */
   public abstract String[][] getConfigs();
   
   /**
    * Duplicate this configuration.
    * 
    * @return   See above.
    */
   public abstract SessionSettings duplicate();
   
   /**
    * Create the {@link #executor} for this session and thread.
    * 
    * @param    rc
    *           Object in which to store the details of non-testing failures.
    *           
    * @return   The {@link #executor}.
    */
   public final TestExecutor getExecutor(FailureNotification rc)
   {
      TestExecutor instance = executor.get();
      if (instance == null)
      {
         instance = buildExecutor(rc);
         executor.set(instance);
      }
      
      return instance;
   }
   
   /**
    * Build a new executor.
    * 
    * @param    rc
    *           Object in which to store the details of non-testing failures.
    *           
    * @return   The {@link #executor}.
    */
   protected TestExecutor buildExecutor(FailureNotification rc)
   {
      return new TestExecutor();
   }
}
