use of com.axway.ats.log.autodb.logqueue.LifeCycleState in project ats-framework by Axway.
the class AbstractLoggingEvent method checkIfCanBeProcessed.
/**
* Check if this event can be processed if the processor
* is in the given state
*
* @param state the current appender state
* @throws IncorrectProcessorStateException if the state is incorrect
* @throws IncorrectScenarioTypeException if the scenario type is incorrect
*/
public void checkIfCanBeProcessed(EventProcessorState state) throws IncorrectProcessorStateException, IncorrectScenarioTypeException {
LifeCycleState expectedState = getExpectedLifeCycleState(state.getLifeCycleState());
LifeCycleState actualState = state.getLifeCycleState();
if ((expectedState != null)) {
if (expectedState == LifeCycleState.ATLEAST_RUN_STARTED) {
if (actualState == LifeCycleState.INITIALIZED) {
throw new IncorrectProcessorStateException("Cannot execute event " + this.getClass().getSimpleName() + " at this time as run is not yet started", expectedState, actualState);
}
} else if (expectedState == LifeCycleState.ATLEAST_TESTCASE_STARTED) {
if (actualState != LifeCycleState.ATLEAST_TESTCASE_STARTED && actualState != LifeCycleState.TEST_CASE_STARTED) {
throw new IncorrectProcessorStateException("Cannot execute event " + this.getClass().getSimpleName() + " at this time as testcase is not yet started", expectedState, actualState);
}
} else if (expectedState == LifeCycleState.ATLEAST_SUITE_STARTED) {
if (actualState == LifeCycleState.INITIALIZED || actualState == LifeCycleState.ATLEAST_RUN_STARTED || actualState == LifeCycleState.RUN_STARTED) {
throw new IncorrectProcessorStateException("Cannot execute event " + this.getClass().getSimpleName() + " at this time as suite is not yet started", expectedState, actualState);
}
} else // strict expectations about the state
if (expectedState != actualState) {
throw new IncorrectProcessorStateException("Cannot execute event " + this.getClass().getSimpleName() + " at this time", expectedState, actualState);
}
}
}
Aggregations