Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2005-2022 Xceptance Software Technologies GmbH
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.xceptance.xlt.engine.junit;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runner.Runner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import com.xceptance.xlt.api.data.DataSetProvider;
import com.xceptance.xlt.api.data.DataSetProviderException;
import com.xceptance.xlt.api.engine.DataSetIndex;
import com.xceptance.xlt.api.engine.Session;
import com.xceptance.xlt.api.tests.AbstractTestCase;
import com.xceptance.xlt.api.util.XltLogger;
import com.xceptance.xlt.api.util.XltProperties;
import com.xceptance.xlt.api.util.XltRandom;
import com.xceptance.xlt.engine.data.DataSetProviderFactory;
import com.xceptance.xlt.engine.util.XltTestRunner;
/**
* A JUnit {@link Runner} implementation for arbitrary test cases. This runner runs a certain test case possibly
* multiple times if there is a {@link DataSetProvider} with more than one data set (data-driven test). To use this
* runner, annotate your JUnit test class with this class using {@link RunWith}.
*/
public abstract class AbstractTestCaseRunner extends XltTestRunner
{
/**
* A specialization of {@link FrameworkMethod}, which replaces the default method name with the provided name and
* the test data set used.
*/
private static class ParameterizedFrameworkMethod extends FrameworkMethod
{
/**
* The test data set to use.
*/
private final Map dataSet;
/**
* The new method name.
*/
private final String name;
/**
* Constructor.
*
* @param method
* the test method
* @param testMethodName
* the name to show for the test method
* @param index
* the index of the test run
* @param dataSet
* the test data set
*/
public ParameterizedFrameworkMethod(final Method method, final String testMethodName, final int index,
final Map dataSet)
{
super(method);
this.dataSet = dataSet;
if (index == -1)
{
name = testMethodName;
}
else
{
name = String.format("%s[%d] - %s", testMethodName, index, dataSet);
}
}
/**
* {@inheritDoc}
*/
@Override
public String getName()
{
return name;
}
/**
* {@inheritDoc}
*/
@Override
public boolean equals(final Object obj)
{
return this == obj;
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
return System.identityHashCode(this);
}
}
/**
* An empty data set.
*/
private static final Map EMPTY_DATA_SET = Collections.emptyMap();
/**
* The current directory.
*/
protected static final File CURRENT_DIR = new File(".");
/**
* The data sets directory as specified in the XLT configuration. Maybe null if not configured.
*/
protected static final File DATA_SETS_DIR;
static
{
final String dataSetFileDirectoryName = XltProperties.getInstance().getProperty("com.xceptance.xlt.data.dataSets.dir", "");
if (dataSetFileDirectoryName.length() > 0)
{
final File dir = new File(dataSetFileDirectoryName);
DATA_SETS_DIR = dir.isDirectory() ? dir : null;
}
else
{
DATA_SETS_DIR = null;
}
}
/**
* The JUnit children of this runner.
*/
private final List methods = new ArrayList();
/**
* Constructor.
*
* @param testCaseClass
* the test case class
* @param testCaseName
* the name of the test
* @param defaultTestMethodName
* the name of the test method (maybe null)
* @param dataSetFileDirs
* the list of directories to search for data set files
*/
protected AbstractTestCaseRunner(final Class testCaseClass, final String testCaseName, final String defaultTestMethodName,
final List dataSetFileDirs)
throws Throwable
{
super(testCaseClass);
// get the short (package-less) test case name
final String shortTestCaseName = StringUtils.contains(testCaseName, '.') ? StringUtils.substringAfterLast(testCaseName, ".")
: testCaseName;
// get the data sets
final List