Blueprint Test Entities
Structural Test Entities
TestCase
The TestCase
entity acts as a container for a list of child entities which are started sequentially.
- type: org.apache.brooklyn.test.framework.TestCase
brooklyn.children:
- type: org.apache.brooklyn.entity.database.mysql.MySqlNode
...
- type: org.apache.brooklyn.test.framework.TestSensor
...
This can be used to enforce a strict ordering, for example ensuring a sensor has a certain value before attempting to invoke an effector.
Timeouts on child entities should be set relative to the completion of the preceding entity.
The ParallelTestCase
entity can be added as a child to run a subset of entities in parallel as a single step.
ParallelTestCase
The ParallelTestCase
entity acts as a container for a list of child entities which are started in parallel.
- type: org.apache.brooklyn.test.framework.ParallelTestCase
brooklyn.children:
- type: org.apache.brooklyn.entity.database.mysql.MySqlNode
...
- type: org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster
...
This can be used to run a subset of entities in parallel as a single step when nested under a TestCase
entity.
Timeouts on child entities should be set relative to the start of the ParallelTestCase
.
LoopOverGroupMembersTestCase
The LoopOverGroupMembersTestCase
entity is configured with a target group and a test specification. For each member of the targeted group, the test case will create a TargetableTestComponent entity from the supplied test specification and set the components target to be the group member.
- type: org.apache.brooklyn.test.framework.LoopOverGroupMembersTestCase
target: $brooklyn:component("infrastructure").component("child", "DockerHosts")
testSpec:
$brooklyn:entitySpec:
type: org.apache.brooklyn.test.framework.TestSensor
...
Parameters
target
- group who’s members are to be tested, specified via DSL. For example,$brooklyn:component("tomcat")
. See also thetargetId
parameter.targetId
- alternative to thetarget
parameter which wraps the DSL component lookup requiring only theid
be supplied. For example,tomcat
. Please note, this must point to a group.test.spec
- The TargetableTestComponent to create for each child.
InfrastructureDeploymentTestCase
The InfrastructureDeploymentTestCase
will first create and deploy an infrastructure from the infrastructure.deployment.spec
config. It will then retrieve a deployment location by getting the value of the infrastructures infrastructure.deployment.location.sensor
sensor. It will then create and deploy all entities from the infrastructure.deployment.spec
config to the deployment location.
- type: org.apache.brooklyn.test.framework.InfrastructureDeploymentTestCase
brooklyn.config:
infrastructure.deployment.location.sensor: entity.dynamicLocation
infrastructure.deployment.spec:
$brooklyn:entitySpec:
- type: docker-cloud-calico
...
infrastructure.deployment.entity.specs:
- $brooklyn:entitySpec:
type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
...
Parameters
infrastructure.deployment.spec
- the infrastructure to be deployed.infrastructure.deployment.entity.specs
- the entities to be deployed to the infrastructureinfrastructure.deployment.location.sensor
- the name of the sensor on the infrastructure to retrieve the deployment location
Validation Test Entities
TestSensor
The TestSensor
entity performs an assertion on a specified sensors value.
- type: org.apache.brooklyn.test.framework.TestSensor
name: Check tomcat isUp
target: $brooklyn:component("tomcat")
sensor: service.isUp
timeout: 10m
assert:
- equals: true
Parameters
target
- entity whose sensor will be tested, specified via DSL. For example,$brooklyn:component("tomcat")
. See also thetargetId
parameter.targetId
- alternative to thetarget
parameter which wraps the DSL component lookup requiring only theid
be supplied. For example,tomcat
.sensor
- sensor to evaluate. For exampleservice.isUp
.timeout
- duration to wait on assertion to return a result. For example10s
,10m
, etcassert
- assertion to perform on the specified sensor value. See section on assertions below.
TestSensor
is wrapped within a TestCase
, ParallelTestCase
or LoopOverGroupMembersTestCase
that set the target, you don't need to specify the target, unless you want to test another entity.
TestEffector
The TestEffector
entity invokes the specified effector on a target entity. If the result of the effector is a String, it will then perform assertions on the result.
- type: org.apache.brooklyn.test.framework.TestEffector
name: Invoke Deploy Effector
target: $brooklyn:component("tomcat")
effector: deploy
timeout: 5m
params:
url: http://search.maven.org/remotecontent?filepath=org/apache/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.8.0-incubating/brooklyn-example-hello-world-sql-webapp-0.8.0-incubating.war
targetName: newcontext
Parameters
target
- entity whose effector will be invoked, specified via DSL. For example,$brooklyn:component("tomcat")
. See also thetargetId
parameter.targetId
- alternative to thetarget
parameter which wraps the DSL component lookup requiring only theid
be supplied. For example,tomcat
.timeout
- duration to wait on the effector task to complete. For example10s
,10m
, etceffector
- effector to invoke, for exampledeploy
.params
- parameters to pass to the effector, these will depend on the entity and effector being tested. The example above shows theurl
andtargetName
parameters being passed to Tomcatsdeploy
effector.assert
- assertion to perform on the returned result. See section on assertions below.
TestEffector
is wrapped within a TestCase
, ParallelTestCase
or LoopOverGroupMembersTestCase
that set the target, you don't need to specify the target, unless you want to test another entity.
TestHttpCall
The TestHttpCall
entity performs a HTTP GET on the specified URL and performs an assertion on the response.
- type: org.apache.brooklyn.test.framework.TestHttpCall
name: Check HTTP Response Status Code
url: $brooklyn:component("tomcat").attributeWhenReady("webapp.url")
timeout: 60s
applyAssertionTo: status
assert:
- isEqualTo: 200
Parameters
url
- URL to perform GET request on, this can use DSL for example$brooklyn:component("tomcat").attributeWhenReady("webapp.url")
.timeout
- duration to wait on a HTTP response. For example10s
,10m
, etcapplyAssertionTo
- The filed to apply the assertion to. For examplestatus
,body
assert
- assertion to perform on the response. See section on assertions below.
TestHttpCall
is wrapped within a TestCase
, ParallelTestCase
or LoopOverGroupMembersTestCase
that set the target, you don't need to specify the target, unless you want to test another entity.
SimpleShellCommandTest
The SimpleShellCommandTest runs a command on the host of the target entity. The script is expected not to run indefinitely, but to return a result (process exit code), along with its standard out and error streams, which can then be tested using assertions. If no assertions are explicitly configured, the default is to assert a non-zero exit code.
Either a shell command may be provided in the YAML, or a URL for a script which will be executed.
- type: org.apache.brooklyn.test.framework.TestCase
name: testcase1
targetId: testprocess
brooklyn.children:
- type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
id: testprocess
- type: org.apache.brooklyn.test.framework.SimpleShellCommandTest
command: ps -ef
assertStatus:
equals: 0
assertOut:
contains: tomcat
assertErr:
isEmpty: true
- type: org.apache.brooklyn.test.framework.SimpleShellCommandTest
downloadUrl: https://github.com/apache/brooklyn-docs/raw/master/guide/yaml/test/example_yaml/entities/script1.sh
assertStatus:
equals: 0
assertOut:
equals: hello world
assertErr:
isEmpty: true
Parameters
command
- The shell command to execute. (This anddownloadUrl
are mutually exclusive.)downloadUrl
- URL for a script to download and execute. (This andcommand
are mutually exclusive.)scriptDir
- ifdownloadUrl
is used. The directory on the target host where downloaded scripts should be copied to.runDir
- the working directory where the command or script will be executed on the target host.assertStatus
- Assertions on the exit code of the command or script. See section on assertions below.assertOut
- Assertions on the standard output of the command as a String.assertErr
- Assertions on the standard error of the command as a String.
SimpleShellCommandTest
is wrapped within a TestCase
, ParallelTestCase
or LoopOverGroupMembersTestCase
that set the target, you don't need to specify the target, unless you want to test another entity.
Assertions
The following conditions are provided by those test entities above that include assertions
isNull
- asserts that the actual value isnull
.notNull
- asserts that the actual value is NOTnull
.isEqualTo
- asserts that the actual value equals an expected value.equalTo
- a synonym forisEqualTo
equals
- a synonym forisEqualTo
matches
- asserts that the actual value matches a regex pattern, for example".*hello.*"
.contains
- asserts that the actual value contains the supplied valueisEmpty
- asserts that the actual value is an empty stringnotEmpty
- asserts that the actual value is a non empty stringhasTruthValue
- asserts that the actual value has the expected interpretation as a boolean
Assertions may be provided as a simple map:
yaml
assert:
contains: 2 users
matches: .*[\d]* days.*
If there is the need to make multiple assertions with the same key, the assertions can be specified as a list of such maps:
yaml
assert:
- contains: 2 users
- contains: 2 days