/*
** Module   : PostEventSem.java
** Abstract : directive to post an event semaphore
**
** Copyright (c) 2009-2021, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 GES 20090224 Directive to post an event semaphore.
** 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.util.*;
import com.goldencode.harness.*;

/**
 * Directive to post an event semaphore.
 */
public class PostEventSem
extends Report
implements Testable
{
   /** Short name for the activity. */
   private static final String NAME = "POST-EVENT-SEM";
   
   /** The event semaphore to utilize. */
   private final EventSemaphore event;
   
   /** Flag to force the post to reset the semaphore to "set" state. */
   private final boolean reset;
   
   /**
    * Constructor.
    *
    * @param    name
    *           Event semaphore name.
    * @param    event
    *           The event semaphore to use.
    * @param    reset
    *           <code>true</code> to auto-reset the semaphore AFTER releasing
    *           all waiting threads.
    */
   public PostEventSem(String name, EventSemaphore event, boolean reset)
   {
      super(NAME, String.format("name = '%s'; reset = %b;", name, reset));
      this.event = event;
      this.reset = reset;
   }
   
   /**
    * Execute the directive of the test using the given terminal as the data
    * sink and/or source for the operation.
    */
   @Override
   public void execute()
   {
      event.post(reset);
      setStatus(Status.PASSED, null);
   }
}
