/*
** Module   : SftpRm.java
** Abstract : directive to remove files on the remote system
**
** Copyright (c) 2009-2021, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 GES 20090126 Directive to remove files on the remote system.
** 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.
*/

/*
** 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.test;

import com.goldencode.harness.*;
import com.goldencode.harness.transport.*;

/**
 * Directive to remove files on the remote system.
 */
public class SftpRm
extends Report
implements Testable
{
   /** Short name for the activity. */
   private static final String NAME = "SFTP-RM";
   
   /** Format specification for creating a description of this step. */
   private static final String SPEC = "filespec = '%s';";
   
   /** Helper shared by all steps that are part of the same SFTP session. */
   private final SFTPSession sftp;
   
   /** The file specification to remove. */
   private final String filespec;
   
   /**
    * Constructor.
    *
    * @param    sftp
    *           Helper shared by all steps that are part of the same SFTP
    *           session.
    * @param    filespec
    *           The file specification to remove. May include wildcards. 
    */
   public SftpRm(SFTPSession sftp, String filespec)
   {
      super(NAME, String.format(SPEC, filespec));
      this.sftp     = sftp;
      this.filespec = filespec;
   }
   
   /**
    * Execute the directive of the test using the given terminal as the data
    * sink and/or source for the operation.
    */
   @Override
   public void execute()
   {
      sftp.rm(filespec);
      setStatus(Status.PASSED, null);
   }
}
