public static class ApiTestCommand.Options extends Object implements TestTargetFactory, TestWriterFactory, TestCaseWriterFactory
[option...] [apiDef]
where each option is one of the following:
-X
If specified, test cases are generated based on the examples specified in the apiDef.
Otherwise, by default, test cases are created by generating random request input values.
-t testType
Defines the test framework used to run API tests. Valid values are "junit", "testng", or "moco".
If omitted, the default is "junit".
Use "moco" to generate a JUnit test that sends requests to a Moco stub server.
To define the Moco server test configuration, use the -M option.
-e execType
Defines the request execution interface used to run API tests. Valid values are "restassured".
If omitted, the default is "restassured".
-n testName
Defines the name of the test class that is generated. This can be either a fully-qualified class name
or a simple class name. If omitted, the default is based on the title of the apiDef.
-p testPackage
Defines the package for the test class that is generated. This can be omitted if the testName
is a fully-qualified class name or if the package can be determined from the outDir.
-b baseClass
If defined, specifies a base class for the generated test class. This can be a fully-qualified class name
or a simple class name, if the baseClass belongs to the same package as the generated test class.
-f outFile
If defined, output is written to the specified outFile, relative to the given outDir.
If omitted, the default outFile is derived from the testName.
-o outDir
If -o is defined, output is written to the specified directory.
If omitted, the default outDir is the directory containing the apiDef or,
if reading from standard input, output is written to standard output.
-d resourceOutDir
If -d is defined, test resource output is written to the specified directory.
If omitted, the default resourceOutDir is the same as the outDir.
If -d is "no" or "false", no test resources are produced.
-u timeout
Defines the maximum time (in milliseconds) to complete an individual test method. A test failure occurs if a
method continues past this time limit. If omitted, no time limit is enforced.
-M mocoTestConfig
When the testType is "moco", specifies the Moco server test configuration file.
-P paths
If defined, tests are generated only for the specified API resource paths. paths must be a comma-separated list
of resource paths defined in the apiDef.
If omitted, tests are generated for all resource paths.
-S
If specified, a separate test file is generated for each of the API resource paths specified by the P option,
each containing tests for a single path. Otherwise, a single test file is generated containing tests for all paths.
-O operations
If defined, tests are generated only for the specified HTTP methods. operations must be a comma-separated list
of path operations defined in the apiDef.
If omitted, tests are generated for all operations.
-B server
If defined, specifies the base URI for the API server used by the generated tests.
The server expression has one of the following forms.
If omitted, the default is index=0.
- index=<integer>
From the servers array defined in the apiDef, use the URI of the given element.
- contains=<text>
From the servers array defined in the apiDef, use the URI of the first element with a description
containing the given text.
- uri=<uri>
Use the specified <uri>.
-V
If specified, generated HTTPS requests will connect to the API server without verifying the server
certificate. Otherwise, by default, the API server must present a trusted certificate.
-T contentType
Defines the content type of the OpenApi definition. The contentType must be one of "json", "yaml", or "yml".
If omitted, the default content type is derived from the apiDef name. If the apiDef is read from standard
input or does not have a recognized extension, the default content type is "json".
-c M[,R]
Defines how input modelling and request case resolution conditions are reported. Both M (for modelling conditions) and R (for
resolution conditions) must be one of "log", "fail", or "ignore".
If "log" is specified, conditions are reported using log messages.
If "fail" is specified, any condition will cause an exception. If "ignore" is specified, all conditions
are silently ignored. If R is omitted, the default is "log". If -c is omitted, the default is "log,log".
-R
If specified, tests will be generated assuming that the API will strictly enforce exclusion of "readOnly"
properties from request parameters. If omitted, no strict enforcement is assumed.
-r seed
If defined, use the given random number seed to generate request test case input values.
If omitted, the default random number seed is derived from the apiDef name.
-m maxTries
Defines the maximum attempts made to resolve a request test case input value before reporting failure.
If omitted, the default value is 10000.
-v
Prints the current command version identifier to standard output.
apiDef
An OpenAPI v3 API definition is read from the given apiDef file. If omitted, the API definition is
read from standard input. If no outFile is specified, output is written to a default file
derived from the apiDef or, if no apiDef is given, to standard output.
Modifier and Type | Class and Description |
---|---|
static class |
ApiTestCommand.Options.Builder |
static class |
ApiTestCommand.Options.ExecType |
static class |
ApiTestCommand.Options.TestType |
Constructor and Description |
---|
Options()
Creates a new Options object.
|
Options(String[] args)
Creates a new Options object.
|
Modifier and Type | Method and Description |
---|---|
static ApiTestCommand.Options.Builder |
builder()
Returns a new Options builder.
|
TestCaseWriter |
createTestCaseWriter()
Creates a new
TestCaseWriter instance. |
TestTarget |
createTestTarget()
Creates a new
TestTarget instance. |
TestWriter<?,?> |
createTestWriter(TestCaseWriter testCaseWriter)
Creates a new
TestWriter instance. |
File |
getApiDef()
Returns the Open API v3 API definition file
|
String |
getBaseClass()
Returns the base class for the test class that is generated.
|
String |
getContentType()
Returns the OpenApi definition file content type.
|
Long |
getDefaultRandomSeed()
Returns the default random number generator seed for request case resolution.
|
ApiTestCommand.Options.ExecType |
getExecType()
Returns the request execution interface used to run API tests.
|
int |
getMaxTries()
Returns the maximum attempts made to resolve a request test case input value before reporting failure..
|
File |
getMocoTestConfig()
Returns the Moco server test configuration file
|
ModelOptions |
getModelOptions()
Returns the input modelling options.
|
Set<String> |
getOperations()
Returns request path operations for which tests are generated.
|
File |
getOutDir()
Returns the output directory for command output.
|
File |
getOutFile()
Returns the output file for command output.
|
Set<String> |
getPaths()
Returns request paths for which tests are generated.
|
Long |
getRandomSeed()
Returns the random number generator seed for request case resolution.
|
ResolverContext |
getResolverContext()
Returns the request case resolution options.
|
File |
getResourceOutDir()
Returns the resource directory for command output.
|
ModelOptions.Source |
getSource()
Returns the source of API input definitions.
|
TestCaseWriter |
getTestCaseWriter()
Returns the
TestCaseWriter defined by these options. |
String |
getTestName()
Returns the name of the test class that is generated.
|
String |
getTestPackage()
Returns the package of the test class that is generated.
|
TestSource |
getTestSource(RequestTestDef testDef)
Returns the
TestSource defined by these options. |
TestTarget |
getTestTarget()
Returns the
TestTarget defined by these options. |
ApiTestCommand.Options.TestType |
getTestType()
Returns the test framework used to run API tests.
|
TestWriter<?,?> |
getTestWriter(TestCaseWriter testCaseWriter)
Returns the
TestWriter defined by these options. |
Long |
getTimeout()
Returns the test timeout (milliseconds).
|
File |
getWorkingDir()
Returns the current working directory used to complete relative path names.
|
protected void |
handleArgs(String[] args,
int i)
Handles the non-option arguments i, i+1, ...
|
protected int |
handleOption(String[] args,
int i)
Handles the i'th option and return the index of the next argument.
|
boolean |
hasResources()
Returns true if test output resources are produced.
|
boolean |
isByPath()
Returns true if generating a separate test file for each request path.
|
boolean |
isServerTrusted()
Returns if generated HTTPS requests will connect to the API server without verifying the server certificate.
|
protected void |
printUsage()
Prints usage information to standard error.
|
void |
setApiDef(File apiDef)
Changes the Open API v3 API definition file
|
void |
setBaseClass(String baseClass)
Changes the base class for the test class that is generated.
|
void |
setByPath(boolean byPath)
Returns true if generating a separate test file for each request path.
|
void |
setConditionNotifiers(String notifierList)
Changes condition notifiers for input modelling and request case resolution conditions.
|
void |
setContentType(String option)
Changes the OpenApi definition file content type.
|
void |
setExecType(ApiTestCommand.Options.ExecType execType)
Changes the request execution interface used to run API tests.
|
void |
setExecType(String execType)
Changes the request execution interface used to run API tests.
|
void |
setMaxTries(int maxTries)
Changes the maximum attempts made to resolve a request test case input value before reporting failure..
|
void |
setMocoTestConfig(File mocoTestConfig)
Changes the Moco server test configuration file
|
void |
setModelOptions(ModelOptions modelOptions)
Changes the input modelling options.
|
void |
setOnModellingCondition(String notifier)
Changes the input modelling condition notifier.
|
void |
setOnResolverCondition(String notifier)
Changes the request case resolution condition notifier.
|
void |
setOperations(Iterable<String> operations)
Changes request path operations for which tests are generated.
|
void |
setOutDir(File outDir)
Changes the output directory for command output.
|
void |
setOutFile(File outFile)
Changes the output file for command output.
|
void |
setPaths(Iterable<String> paths)
Changes request paths for which tests are generated.
|
void |
setRandomSeed(Long seed)
Changes the random number generator seed for request case resolution.
|
void |
setReadOnlyEnforced(boolean enforced)
Changes if "readOnly" properties are strictly enforced.
|
void |
setResolverContext(ResolverContext resolverContext)
Changes the request case resolution options.
|
void |
setResourceOutDir(File resourceOutDir)
Changes the resource directory for command output.
|
void |
setServerTrusted(boolean trusted)
Changes if generated HTTPS requests will connect to the API server without verifying the server certificate.
|
void |
setServerUri(String serverExpr)
Changes the expression that identifies the API server URI used by generated tests.
|
void |
setShowVersion(boolean showVersion)
Changes if the current version should be shown.
|
void |
setSource(ModelOptions.Source source)
Changes the source of API input definitions.
|
void |
setSource(String source)
Changes the source of API input definitions.
|
void |
setTestName(String testName)
Changes the name of the test class that is generated.
|
void |
setTestPackage(String testPackage)
Changes the package of the test class that is generated.
|
void |
setTestType(ApiTestCommand.Options.TestType testType)
Changes the test framework used to run API tests.
|
void |
setTestType(String testType)
Changes the test framework used to run API tests.
|
void |
setTimeout(Long millis)
Changes the test timeout (milliseconds).
|
void |
setWorkingDir(File workingDir)
Changes the current working directory used to complete relative path names.
|
boolean |
showVersion()
Returns if the current version should be shown.
|
protected void |
throwHelpException()
Throws a HelpException after printing usage information to standard error.
|
String |
toString() |
public Options()
public Options(String[] args)
protected int handleOption(String[] args, int i)
protected void handleArgs(String[] args, int i)
protected void throwHelpException()
protected void printUsage()
public void setTestType(ApiTestCommand.Options.TestType testType)
public void setTestType(String testType)
public ApiTestCommand.Options.TestType getTestType()
public void setExecType(ApiTestCommand.Options.ExecType execType)
public void setExecType(String execType)
public ApiTestCommand.Options.ExecType getExecType()
public void setSource(ModelOptions.Source source)
public void setSource(String source)
public ModelOptions.Source getSource()
public void setTestName(String testName)
public String getTestName()
public void setTestPackage(String testPackage)
public String getTestPackage()
public void setBaseClass(String baseClass)
public String getBaseClass()
public void setOutDir(File outDir)
public File getOutDir()
public void setResourceOutDir(File resourceOutDir)
public File getResourceOutDir()
public boolean hasResources()
public void setOutFile(File outFile)
public File getOutFile()
public void setTimeout(Long millis)
public Long getTimeout()
public void setMocoTestConfig(File mocoTestConfig)
public File getMocoTestConfig()
public void setPaths(Iterable<String> paths)
public void setByPath(boolean byPath)
public boolean isByPath()
public void setOperations(Iterable<String> operations)
public Set<String> getOperations()
public void setServerUri(String serverExpr) throws Exception
Exception
public void setServerTrusted(boolean trusted)
public boolean isServerTrusted()
public void setContentType(String option)
public String getContentType()
public void setModelOptions(ModelOptions modelOptions)
public ModelOptions getModelOptions()
public void setResolverContext(ResolverContext resolverContext)
public ResolverContext getResolverContext()
public void setRandomSeed(Long seed)
public Long getRandomSeed()
public Long getDefaultRandomSeed()
public void setMaxTries(int maxTries)
public int getMaxTries()
public void setConditionNotifiers(String notifierList)
public void setOnModellingCondition(String notifier)
public void setOnResolverCondition(String notifier)
public void setReadOnlyEnforced(boolean enforced)
public void setApiDef(File apiDef)
public File getApiDef()
public void setWorkingDir(File workingDir)
public File getWorkingDir()
public void setShowVersion(boolean showVersion)
public boolean showVersion()
public TestSource getTestSource(RequestTestDef testDef)
TestSource
defined by these options.public TestTarget getTestTarget()
TestTarget
defined by these options.public TestWriter<?,?> getTestWriter(TestCaseWriter testCaseWriter)
TestWriter
defined by these options.public TestCaseWriter getTestCaseWriter()
TestCaseWriter
defined by these options.public TestTarget createTestTarget()
TestTarget
instance.createTestTarget
in interface TestTargetFactory
public TestWriter<?,?> createTestWriter(TestCaseWriter testCaseWriter)
TestWriter
instance.createTestWriter
in interface TestWriterFactory
public TestCaseWriter createTestCaseWriter()
TestCaseWriter
instance.createTestCaseWriter
in interface TestCaseWriterFactory
public static ApiTestCommand.Options.Builder builder()
Copyright © 2024 The Cornutum Project. All rights reserved.