public class OperatorTestEnvironment extends DriverElementBase implements org.junit.rules.TestRule
@Rule
public OperatorTestEnvironment env = new OperatorTestEnvironment();
The above activates a configuration file asakusa-resources.xml on the current class-path,
and enables framework APIs (e.g. Report API) using the configuration.
Clients can also use alternative configuration files by specifying their paths:
@Rule
public OperatorTestEnvironment env = new OperatorTestEnvironment("com/example/testing.xml");
Additionally, clients can also put batch arguments or extra configuration items:
@Rule
public OperatorTestEnvironment env = new OperatorTestEnvironment(...);
@Test
public void sometest() {
env.configure("key", "value");
env.setBatchArg("date", "2011/03/31");
...
env.reload();
TheOperatorClass op = env.newInstance(TheOperatorClass.class);
<... test code>
}
| Constructor and Description |
|---|
OperatorTestEnvironment()
Creates a new instance with the default configuration file.
|
OperatorTestEnvironment(String configurationPath)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
after()
Invoked after ran test case.
|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
protected void |
before()
Invoked before running test case.
|
void |
configure(String key,
String value)
Adds a configuration item.
|
protected org.apache.hadoop.conf.Configuration |
createConfig()
Returns a new configuration object for
RuntimeResourceManager. |
protected Class<?> |
getCallerClass()
Returns the caller class.
|
org.apache.hadoop.conf.Configuration |
getConfiguration()
Returns the Configuration object for the current environment.
|
TestContext |
getTestContext()
Returns the
TestContext for the current environment. |
protected TestDataToolProvider |
getTestTools()
Returns the test tools.
|
<T> DataLoader<T> |
loader(Class<T> dataType,
Class<? extends DataFormat<? super T>> formatClass,
File file)
Returns a new data loader.
|
<T> DataLoader<T> |
loader(Class<T> dataType,
Class<? extends DataFormat<? super T>> formatClass,
String sourcePath)
Returns a new data loader.
|
<T> DataLoader<T> |
loader(Class<T> dataType,
DataModelSourceFactory factory)
Returns a new data loader.
|
<T> DataLoader<T> |
loader(Class<T> dataType,
Iterable<? extends T> objects)
Returns a new data loader.
|
<T> DataLoader<T> |
loader(Class<T> dataType,
Provider<? extends Source<? extends T>> provider)
Returns a new data loader.
|
<T> DataLoader<T> |
loader(Class<T> dataType,
String sourcePath)
Returns a new data loader.
|
<T> T |
newInstance(Class<T> operatorClass)
Returns an implementation of the given operator class.
|
<T extends DataModel<T>> |
newResult(Class<T> dataType)
Returns a new
MockResult. |
void |
reload()
Reloads the configuration file and activates changes.
|
void |
setBatchArg(String key,
String value)
Adds a batch argument.
|
toDataModelSinkFactory, toDataModelSourceFactory, toDataModelSourceFactory, toDataModelSourceFactory, toDataModelSourceFactory, toDataModelSourceFactory, toDataModelSourceFilter, toOutputUri, toUri, toVerifierFactorypublic OperatorTestEnvironment()
public OperatorTestEnvironment(String configurationPath)
configurationPath - the configuration file location (relative from the class-path)IllegalArgumentException - if the parameter is nullpublic org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRuleprotected Class<?> getCallerClass()
DriverElementBasegetCallerClass in class DriverElementBaseprotected TestDataToolProvider getTestTools()
DriverElementBasegetTestTools in class DriverElementBaseprotected void before()
public <T> T newInstance(Class<T> operatorClass)
T - the operator typeoperatorClass - the operator classIllegalArgumentException - if the method cannot detect its implementation, or cannot create an instancepublic void configure(String key, String value)
reload() to active this change before executing the test target.key - the configuration key namevalue - the configuration value, or null to unset the target configurationIllegalArgumentException - if key is nullreload()public void setBatchArg(String key, String value)
context API.
Please invoke reload() to active this change before executing the test target.key - the argument namevalue - the argument value, or null to unset the target argumentIllegalArgumentException - if key is nullreload()public void reload()
protected org.apache.hadoop.conf.Configuration createConfig()
RuntimeResourceManager.public TestContext getTestContext()
TestContext for the current environment.TestContext objectpublic org.apache.hadoop.conf.Configuration getConfiguration()
public <T extends DataModel<T>> MockResult<T> newResult(Class<T> dataType)
MockResult.
The returned object will create copies of the incoming objects.T - the data typedataType - the data typeMockResultpublic <T> DataLoader<T> loader(Class<T> dataType, String sourcePath)
T - the data typedataType - the data typesourcePath - the path to test data set (relative from the current test case class)public <T> DataLoader<T> loader(Class<T> dataType, Iterable<? extends T> objects)
T - the data typedataType - the data typeobjects - the test data objectspublic <T> DataLoader<T> loader(Class<T> dataType, Provider<? extends Source<? extends T>> provider)
T - the data typedataType - the data typeprovider - the test data set providerpublic <T> DataLoader<T> loader(Class<T> dataType, Class<? extends DataFormat<? super T>> formatClass, String sourcePath)
loader(Class, Class, File) instead.T - the data typedataType - the data typeformatClass - the data format classsourcePath - the input file path on the class pathpublic <T> DataLoader<T> loader(Class<T> dataType, Class<? extends DataFormat<? super T>> formatClass, File file)
T - the data typedataType - the data typeformatClass - the data format classfile - the input file path on the class pathpublic <T> DataLoader<T> loader(Class<T> dataType, DataModelSourceFactory factory)
T - the data typedataType - the data typefactory - factory which provides test data setprotected void after()
Copyright © 2011–2018 Asakusa Framework Team. All rights reserved.