<commit_before>/*******************************************************************************
 * Copyright (c) 2012 - 2015 Signal Iduna Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Signal Iduna Corporation - initial API and implementation
 * akquinet AG
 *******************************************************************************/

package org.testeditor.fixture.core.interaction;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

import org.apache.log4j.Logger;
import org.testeditor.fixture.core.exceptions.ContinueTestException;
import org.testeditor.fixture.core.exceptions.StopTestException;

import fitnesse.slim.fixtureInteraction.DefaultInteraction;

/**
 * Interaction for real-time test logging.<br />
 * 
 * FitNesse provides the option of user-specific interaction. We use this hook
 * to provide a test logging outside the default FitNesse logging. The
 * Test-Editor is using this logging while executing any tests.
 */
public class TestEditorLoggingInteraction extends DefaultInteraction {
	private static final Logger LOGGER = Logger.getLogger(TestEditorLoggingInteraction.class.getName());

	private static final String WAIT_PROPERTY = "waits.after.teststep";

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object methodInvoke(Method method, Object instance, Object... convertedArgs) throws IllegalAccessException {

		Object result = null;

		String logMessage = createLogMessage(method, convertedArgs);

		try {

			// pre invoke
			preInvoke(method, instance, convertedArgs);

			// execute test step
			result = super.methodInvoke(method, instance, convertedArgs);

			// post invoke
			postInvoke(method, instance, convertedArgs);

			// wait after test step
			String waitsAfterTeststep = System.getProperty(WAIT_PROPERTY);
			if (waitsAfterTeststep != null) {
				try {
					int seconds = Integer.parseInt(waitsAfterTeststep);
					if (seconds > 0) {
						// property was set and is > 0, so wait
						waitTime(seconds);
						LOGGER.debug("Wait " + waitsAfterTeststep + " seconds");
					}
				} catch (NumberFormatException e) {
					LOGGER.error("Wrong value for " + WAIT_PROPERTY + ": " + waitsAfterTeststep);
				}
			}

			// analyze result
			if (result == null || !(result instanceof Boolean) || (Boolean) result) {
				LOGGER.debug(logMessage);
			} else {
				// only boolean results with "false" are logged on error level
				LOGGER.error(logMessage);
			}
		} catch (InvocationTargetException e) {
			if (e.getTargetException() instanceof StopTestException) {
				LOGGER.error(logMessage + e.getTargetException().getMessage());
				handleTearDown(instance);
				throw (StopTestException) e.getTargetException();
			} else if (e.getCause() instanceof StopTestException) {
				LOGGER.error(logMessage + e.getCause().getMessage());
				handleTearDown(instance);
				throw (StopTestException) e.getCause();
			} else if (e.getTargetException() instanceof ContinueTestException) {
				throw (ContinueTestException) e.getTargetException();
			} else if (e.getCause() instanceof ContinueTestException) {
				throw (ContinueTestException) e.getCause();
			} else {
				LOGGER.error(logMessage + e.getTargetException().getMessage());
				LOGGER.error(Arrays.toString(e.getTargetException().getStackTrace()));
				handleTearDown(instance);
				throw new StopTestException("An unexpected error occurred: " + e.getTargetException().getMessage());
			}
		} catch (Exception e) {
			LOGGER.error(logMessage + e.getMessage());
			LOGGER.error(Arrays.toString(e.getStackTrace()));
			handleTearDown(instance);
			if (e instanceof StopTestException) {
				throw (StopTestException) e;
			} else if (e instanceof ContinueTestException) {
				throw (ContinueTestException) e;
			} else {
				throw new StopTestException("An unexpected error occurred: " + e.getMessage());
			}
		}

		return result;
	}
<commit_msg>[TE-123]: Adding some logging info<commit_after>/*******************************************************************************
 * Copyright (c) 2012 - 2015 Signal Iduna Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Signal Iduna Corporation - initial API and implementation
 * akquinet AG
 *******************************************************************************/

package org.testeditor.fixture.core.interaction;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

import org.apache.log4j.Logger;
import org.testeditor.fixture.core.exceptions.ContinueTestException;
import org.testeditor.fixture.core.exceptions.StopTestException;

import fitnesse.slim.fixtureInteraction.DefaultInteraction;

/**
 * Interaction for real-time test logging.<br />
 * 
 * FitNesse provides the option of user-specific interaction. We use this hook
 * to provide a test logging outside the default FitNesse logging. The
 * Test-Editor is using this logging while executing any tests.
 */
public class TestEditorLoggingInteraction extends DefaultInteraction {
	private static final Logger LOGGER = Logger.getLogger(TestEditorLoggingInteraction.class.getName());

	private static final String WAIT_PROPERTY = "waits.after.teststep";

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Object methodInvoke(Method method, Object instance, Object... convertedArgs) throws IllegalAccessException {

		Object result = null;

		String logMessage = createLogMessage(method, convertedArgs);

		try {

			// pre invoke
			preInvoke(method, instance, convertedArgs);

			// execute test step
			result = super.methodInvoke(method, instance, convertedArgs);

			// post invoke
			postInvoke(method, instance, convertedArgs);

			// wait after test step
			String waitsAfterTeststep = System.getProperty(WAIT_PROPERTY);
			if (waitsAfterTeststep != null) {
				try {
					int seconds = Integer.parseInt(waitsAfterTeststep);
					if (seconds > 0) {
						// property was set and is > 0, so wait
						waitTime(seconds);
						LOGGER.debug("Wait " + waitsAfterTeststep + " seconds");
					}
				} catch (NumberFormatException e) {
					LOGGER.error("Wrong value for " + WAIT_PROPERTY + ": " + waitsAfterTeststep);
				}
			}

			// analyze result
			if (result == null || !(result instanceof Boolean) || (Boolean) result) {
				LOGGER.debug(logMessage);
			} else {
				// only boolean results with "false" are logged on error level
				LOGGER.error(logMessage);
			}
		} catch (InvocationTargetException e) {
			if (e.getTargetException() instanceof StopTestException) {
				LOGGER.error(logMessage + e.getTargetException().getMessage());
				handleTearDown(instance);
				throw (StopTestException) e.getTargetException();
			} else if (e.getCause() instanceof StopTestException) {
				LOGGER.error(logMessage + e.getCause().getMessage());
				handleTearDown(instance);
				throw (StopTestException) e.getCause();
			} else if (e.getTargetException() instanceof ContinueTestException) {
				throw (ContinueTestException) e.getTargetException();
			} else if (e.getCause() instanceof ContinueTestException) {
				throw (ContinueTestException) e.getCause();
			} else {
				LOGGER.error(logMessage + e.getTargetException().getMessage());
				LOGGER.error(Arrays.toString(e.getTargetException().getStackTrace()));
				handleTearDown(instance);
				throw new StopTestException("An unexpected error occurred: " + e.getTargetException().getMessage());
			}
		} catch (Exception e) {
			LOGGER.error(logMessage + e.getMessage(), e);
			handleTearDown(instance);
			if (e instanceof StopTestException) {
				throw (StopTestException) e;
			} else if (e instanceof ContinueTestException) {
				throw (ContinueTestException) e;
			} else {
				throw new StopTestException("An unexpected error occurred: " + e.getMessage());
			}
		}

		return result;
	}

{'fraction_non_alphanumeric': 0.13964454116793618, 'fraction_numerical': 0.003989844033369605, 'mean_word_length': 4.364461738002594, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2566090', 'n_tokens_mistral': 2586, 'n_tokens_neox': 2223, 'n_words': 604}