/*
** Module   : CheckPostCount.java
** Abstract : directive to check the post count of an event semaphore
**
** Copyright (c) 2009-2021, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 GES 20090224 Directive to check the post count of 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 check the post count of an event semaphore.
 */
public class CheckPostCount
extends Report
implements Testable
{
   /** Short name for the activity. */
   private static final String NAME = "CHECK-POST-COUNT";
   
   /** The event semaphore to utilize. */
   private EventSemaphore event = null;
   
   /** The number the post count must exceed. */
   private int expected = -1;
   
   /**
    * Constructor.
    *
    * @param    name
    *           Event semaphore name.
    * @param    event
    *           The event semaphore to use.
    * @param    expected
    *           The number the post count must exceed for the test to pass.
    */
   public CheckPostCount(String name, EventSemaphore event, int expected)
   {
      super(NAME, String.format("name = '%s'; expected = %d", name, expected));
      this.event    = event;
      this.expected = expected;
   }
   
   /**
    * Execute the directive of the test using the given terminal as the data
    * sink and/or source for the operation.
    */
   @Override
   public void execute()
   {
      int num = event.query();
      
      setDescription(String.format("%s; actual = %d;", getDescription(), num));
      
      setStatus((num > expected) ? Status.PASSED : Status.FAILED, null);
   }
}
