Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 35d75537c -> 4ebe7379b


yaml testing docs


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/cc25df3f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/cc25df3f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/cc25df3f

Branch: refs/heads/master
Commit: cc25df3fa92a7b4d50cae72e44afb61e50ff0cd1
Parents: ca89ed4
Author: John McCabe <[email protected]>
Authored: Fri Nov 13 16:45:30 2015 +0000
Committer: John McCabe <[email protected]>
Committed: Fri Nov 13 16:45:30 2015 +0000

----------------------------------------------------------------------
 docs/guide/yaml/index.md                        |  1 +
 .../example_yaml/paralleltestcase-entity.yaml   |  2 +
 .../example_yaml/paralleltestcase-example.yaml  | 46 +++++++++++++
 ...simple-tomcat-app-effector-test-snippet.yaml | 19 ++++++
 .../simple-tomcat-app-http-test-snippet.yaml    | 11 +++
 .../simple-tomcat-app-sensor-test.yaml          | 24 +++++++
 .../test/example_yaml/simple-tomcat-app.yaml    | 15 ++++
 .../yaml/test/example_yaml/testcase-entity.yaml |  2 +
 .../test/example_yaml/testeffector-entity.yaml  |  7 ++
 .../test/example_yaml/testhttpcall-entity.yaml  |  5 ++
 .../test/example_yaml/testsensor-entity.yaml    |  6 ++
 docs/guide/yaml/test/index.md                   | 24 +++++++
 docs/guide/yaml/test/test-entities.md           | 72 ++++++++++++++++++++
 docs/guide/yaml/test/usage-examples.md          | 57 ++++++++++++++++
 14 files changed, 291 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/index.md
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/index.md b/docs/guide/yaml/index.md
index 55acfee..b0303cb 100644
--- a/docs/guide/yaml/index.md
+++ b/docs/guide/yaml/index.md
@@ -11,6 +11,7 @@ children:
 - custom-entities.md
 - winrm/
 - chef/
+- test/
 - { path: yaml-reference.md, title: YAML Blueprint Reference }
 - { link: 'https://github.com/brooklyncentral/blueprint-library', title: 
'GitHub Blueprint Library' }
 ---

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/paralleltestcase-entity.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/paralleltestcase-entity.yaml 
b/docs/guide/yaml/test/example_yaml/paralleltestcase-entity.yaml
new file mode 100644
index 0000000..1dca082
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/paralleltestcase-entity.yaml
@@ -0,0 +1,2 @@
+- type: org.apache.brooklyn.test.framework.ParallelTestCase
+  brooklyn.children:
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/paralleltestcase-example.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/paralleltestcase-example.yaml 
b/docs/guide/yaml/test/example_yaml/paralleltestcase-example.yaml
new file mode 100644
index 0000000..c7f0f5b
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/paralleltestcase-example.yaml
@@ -0,0 +1,46 @@
+brooklyn.catalog:
+  id: parallel-test
+  version: 1.0
+  itemType: template
+  iconUrl: http://tomcat.apache.org/images/tomcat.png
+  name: Parallel Tomcat and DB Example Test
+  license: Apache-2.0
+  item:
+    brooklyn.config:
+      simple.confg: someValue
+    services:
+    - type: org.apache.brooklyn.test.framework.TestCase
+      name: Parallel Testcase
+      brooklyn.children:
+      - type: org.apache.brooklyn.test.framework.TestCase
+        name: Parallel Testcase
+        brooklyn.children:
+        - type: 
org.apache.brooklyn.entity.webapp.ControlledDynamicWebAppCluster
+          name: My Web
+          id: webappcluster
+          brooklyn.config:
+            wars.root: 
http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.6.0/brooklyn-example-hello-world-sql-webapp-0.6.0.war
+            java.sysprops:
+              brooklyn.example.db.url: >
+                $brooklyn:formatString("jdbc:%s%s?user=%s&password=%s",
+                component("db").attributeWhenReady("datastore.url"),
+                "visitors", "brooklyn", "br00k11n")
+        - type: org.apache.brooklyn.entity.database.mysql.MySqlNode
+          id: db
+          name: My DB
+          brooklyn.config:
+            creationScriptUrl: https://bit.ly/brooklyn-visitors-creation-script
+      - type: org.apache.brooklyn.test.framework.TestSensor
+        name: Test WebApp Cluster service.isUp
+        targetId: webappcluster
+        sensor: service.isUp
+        timeout: 10m
+        assert:
+          equals: true
+      - type: org.apache.brooklyn.test.framework.TestSensor
+        name: Test DB service.isUp
+        targetId: db
+        sensor: service.isUp
+        timeout: 10m
+        assert:
+          equals: true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/simple-tomcat-app-effector-test-snippet.yaml
----------------------------------------------------------------------
diff --git 
a/docs/guide/yaml/test/example_yaml/simple-tomcat-app-effector-test-snippet.yaml
 
b/docs/guide/yaml/test/example_yaml/simple-tomcat-app-effector-test-snippet.yaml
new file mode 100644
index 0000000..a9ab85d
--- /dev/null
+++ 
b/docs/guide/yaml/test/example_yaml/simple-tomcat-app-effector-test-snippet.yaml
@@ -0,0 +1,19 @@
+- type: org.apache.brooklyn.test.framework.TestEffector
+  name: Deploy WAR in /newcontext
+  targetId: tomcat
+  effector: deploy
+  timeout:
+  params:
+    url: https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/sample.war
+    targetName: newcontext
+- type: org.apache.brooklyn.test.framework.TestHttpCall
+  name: /newcontext Status Code 200
+  url: $brooklyn:formatString("%s/newcontext/", 
component("tomcat").attributeWhenReady("webapp.url"))
+  timeout: 5m
+  assert:
+    status: 200
+
+
+
+
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/simple-tomcat-app-http-test-snippet.yaml
----------------------------------------------------------------------
diff --git 
a/docs/guide/yaml/test/example_yaml/simple-tomcat-app-http-test-snippet.yaml 
b/docs/guide/yaml/test/example_yaml/simple-tomcat-app-http-test-snippet.yaml
new file mode 100644
index 0000000..e967908
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/simple-tomcat-app-http-test-snippet.yaml
@@ -0,0 +1,11 @@
+- type: org.apache.brooklyn.test.framework.TestHttpCall
+  name: Status Code 200
+  url: $brooklyn:component("tomcat").attributeWhenReady("webapp.url")
+  timeout: 60s
+  assert:
+    status: 200
+- type: org.apache.brooklyn.test.framework.TestHttpCall
+  name: Regex match
+  url: $brooklyn:component("tomcat").attributeWhenReady("webapp.url")
+  assert:
+    regex: "(?s).*Br[o]{2}klyn Deployed.*"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/simple-tomcat-app-sensor-test.yaml
----------------------------------------------------------------------
diff --git 
a/docs/guide/yaml/test/example_yaml/simple-tomcat-app-sensor-test.yaml 
b/docs/guide/yaml/test/example_yaml/simple-tomcat-app-sensor-test.yaml
new file mode 100644
index 0000000..3e96ac3
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/simple-tomcat-app-sensor-test.yaml
@@ -0,0 +1,24 @@
+brooklyn.catalog:
+  id: simple-tomcat-app-sensor-test
+  version: 1.0
+  itemType: template
+  iconUrl: http://tomcat.apache.org/images/tomcat.png
+  name: Simple Tomcat Application Sensor Test
+  license: Apache-2.0
+  item:
+    brooklyn.config:
+      simple.confg: someValue
+    services:
+    - type: org.apache.brooklyn.test.framework.TestCase
+      name: Simple Tomcat Sensor Test
+      brooklyn.children:
+      - type: simple-tomcat-app
+        name: Deploy Tomcat App
+        id: tomcat
+      - type: org.apache.brooklyn.test.framework.TestSensor
+        name: Test service.isUp
+        targetId: tomcat
+        sensor: service.isUp
+        timeout: 10m
+        assert:
+          equals: true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/simple-tomcat-app.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/simple-tomcat-app.yaml 
b/docs/guide/yaml/test/example_yaml/simple-tomcat-app.yaml
new file mode 100644
index 0000000..7207478
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/simple-tomcat-app.yaml
@@ -0,0 +1,15 @@
+brooklyn.catalog:
+  id: simple-tomcat-app
+  version: 1.0
+  itemType: template
+  iconUrl: http://tomcat.apache.org/images/tomcat.png
+  name: Simple Tomcat Application
+  license: Apache-2.0
+  item:
+    brooklyn.config:
+      simple.confg: someValue
+    services:
+    - type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
+      id: tomcat
+      name: Tomcat
+      war: https://tomcat.apache.org/tomcat-6.0-doc/appdev/sample/sample.war
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/testcase-entity.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/testcase-entity.yaml 
b/docs/guide/yaml/test/example_yaml/testcase-entity.yaml
new file mode 100644
index 0000000..c8a8bd8
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/testcase-entity.yaml
@@ -0,0 +1,2 @@
+- type: org.apache.brooklyn.test.framework.TestCase
+  brooklyn.children:
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/testeffector-entity.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/testeffector-entity.yaml 
b/docs/guide/yaml/test/example_yaml/testeffector-entity.yaml
new file mode 100644
index 0000000..9ce74fa
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/testeffector-entity.yaml
@@ -0,0 +1,7 @@
+- type: org.apache.brooklyn.test.framework.TestEffector
+  name: Deploy WAR in /newcontext
+  target: $brooklyn:component("tomcat")
+  effector: deploy
+  params:
+    url: 
http://search.maven.org/remotecontent?filepath=io/brooklyn/example/brooklyn-example-hello-world-sql-webapp/0.6.0/brooklyn-example-hello-world-sql-webapp-0.6.0.war
+    targetName: newcontext
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/testhttpcall-entity.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/testhttpcall-entity.yaml 
b/docs/guide/yaml/test/example_yaml/testhttpcall-entity.yaml
new file mode 100644
index 0000000..39742c1
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/testhttpcall-entity.yaml
@@ -0,0 +1,5 @@
+  - type: org.apache.brooklyn.test.framework.TestHttpCall
+    name: /newcontext Status Code 404
+    url: $brooklyn:formatString("%s/newcontext/", 
component("tomcat").attributeWhenReady("webapp.url"))
+    assert:
+      status: 404
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/example_yaml/testsensor-entity.yaml
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/example_yaml/testsensor-entity.yaml 
b/docs/guide/yaml/test/example_yaml/testsensor-entity.yaml
new file mode 100644
index 0000000..00c3ff4
--- /dev/null
+++ b/docs/guide/yaml/test/example_yaml/testsensor-entity.yaml
@@ -0,0 +1,6 @@
+- type: org.apache.brooklyn.test.framework.TestSensor
+  target: $brooklyn:component("tomcat")
+  sensor: service.isUp
+  timeout: 10m
+  assert:
+    equals: true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/index.md
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/index.md b/docs/guide/yaml/test/index.md
new file mode 100644
index 0000000..804b055
--- /dev/null
+++ b/docs/guide/yaml/test/index.md
@@ -0,0 +1,24 @@
+---
+title: Testing YAML Blueprints
+layout: website-normal
+children:
+- test-entities.md
+- usage-examples.md
+---
+
+Brooklyn provides a selection of basic test entities which can be used to 
validate Blueprints via YAML. These are divided into two groups structural, 
which effect the order in which child entities are started, and validation, 
which are used to confirm the application is deployed as intended:
+
+Structural test entities include:
+
+- `TestCase`  - starts child entities sequentially.
+- `ParallelTestCase` - starts child entities in parallel.
+
+Validation test entities include:
+
+- `TestSensor` - perform assertion on a specified sensor.
+- `TestEffector` - invoke effector on specified target entity.
+- `TestHttpCall` - perform assertions on response to specified HTTP GET 
Request.
+
+The following sections provide details on each test entity along with examples 
of their use.
+
+{% include list-children.html %}

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/test-entities.md
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/test-entities.md 
b/docs/guide/yaml/test/test-entities.md
new file mode 100644
index 0000000..6ab454f
--- /dev/null
+++ b/docs/guide/yaml/test/test-entities.md
@@ -0,0 +1,72 @@
+---
+title: Blueprint Test Entities
+title_in_menu: Test Entities
+layout: website-normal
+---
+
+{% include fields.md %}
+
+## Structural Test Entities
+
+### TestCase
+The `TestCase` entity acts as a container for a list child entities which are 
started *sequentially*.
+{% highlight yaml %}
+{% readj example_yaml/testcase-entity.yaml %}
+{% endhighlight %}
+The ability to sequentially run entities is used to allow applications to 
fully deploy before attempting to start any test entities.
+
+If your application blueprint consists of multiple services then you will also 
require the `ParallelTestCase` entity.
+
+### ParallelTestCase
+The `ParallelTestCase` entity acts as a container for a list of child entities 
which are started in *parallel*.
+{% highlight yaml %}
+{% readj example_yaml/paralleltestcase-entity.yaml %}
+{% endhighlight %}
+This entity is used when your application blueprint consists of multiple 
services that run in parallel.
+
+
+## Validation Test Entities
+
+### TestSensor
+The `TestSensor` entity performs an assertion on a specified sensor.
+{% highlight yaml %}
+{% readj example_yaml/testsensor-entity.yaml %}
+{% endhighlight %}
+
+#### Parameters
+- `target` - entity whose sensor will be tested, specified via DSL. For 
example, `$brooklyn:component("tomcat")`. See also the `targetId` parameter.
+- `targetId` - alternative to the `target` parameter which wraps the DSL 
component lookup. For example, `tomcat`.
+- `sensor` - sensor to evaluate. For example `service.isUp`.
+- `timeout` - time to wait for assertion to return a result.
+- `assert` - assertion to perform on the specified sensor, options include
+  - `equals` - tests that the sensor equals the supplied value. For example 
`true`.
+  - `regex` - tests that the sensor value matches the supplied [regex 
pattern](http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html?is-external=true),
 for example `".*hello.*"`.
+  - `isNull` - tests that the sensor value is `null`.
+
+### TestEffector
+The `TestEffector` entity invokes the specified effector on a target entity.
+{% highlight yaml %}
+{% readj example_yaml/testeffector-entity.yaml %}
+{% endhighlight %}
+
+#### Parameters
+- `target` - entity whose effector will be invoked, specified via DSL. For 
example, `$brooklyn:component("tomcat")`. See also the `targetId` parameter.
+- `targetId` - alternative to the `target` parameter which wraps the DSL 
component lookup. For example, `tomcat`.
+- `timeout` - time to wait for the effector task to complete.
+- `effector` - effector to invoke, for example `deploy`.
+- `params` - parameters to pass to the effector, these will depend on the 
entity and effector being tested. The example above shows the `url` and 
`targetName` parameters being passed to Tomcats `deploy` effector.
+
+### TestHttpCall
+The `TestHttpCall` entity performs a HTTP GET on the specified URL and 
performs an assertion on the response.
+{% highlight yaml %}
+{% readj example_yaml/testhttpcall-entity.yaml %}
+{% endhighlight %}
+
+#### Parameters
+- `url` - URL to perform GET request on, for example 
`$brooklyn:component("tomcat").attributeWhenReady("webapp.url")``.
+- `timeout` - time to wait for a HTTP response. For example `10s`, `10m`, etc
+- `assertions` - perform one of the following assertions.
+  - `status` - response must match the specified status code. The example 
above shows an assertions on a `404` response.
+  - `bodyContains` - response body must contain the supplied string, for 
example `"hello world"`.
+  - `regex` - response body must match the supplied [regex 
pattern](http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html?is-external=true),
 for example `".*hello.*"`
+

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cc25df3f/docs/guide/yaml/test/usage-examples.md
----------------------------------------------------------------------
diff --git a/docs/guide/yaml/test/usage-examples.md 
b/docs/guide/yaml/test/usage-examples.md
new file mode 100644
index 0000000..38bdcb2
--- /dev/null
+++ b/docs/guide/yaml/test/usage-examples.md
@@ -0,0 +1,57 @@
+---
+title: Example Blueprint Tests
+title_in_menu: Example Tests
+layout: website-normal
+---
+
+{% include fields.md %}
+
+## Introduction
+This section provides example tests carried out on the following 
`simple-tomcat-app` web application catalog item:
+
+{% highlight yaml %}
+{% readj example_yaml/simple-tomcat-app.yaml %}
+{% endhighlight %}
+
+### Sensor Test Example
+
+This test catalog carries out the following test actions:
+
+- deploys the `sample-tomcat-app`
+- tests that the `service.isUp` sensor is `true` within 10 minutes of the 
`sample-tomcat-app` deployment completing.
+
+{% highlight yaml %}
+{% read example_yaml/simple-tomcat-app-sensor-test.yaml %}
+{% endhighlight %}
+
+### HTTP Call Test Example
+
+The following yaml snippet extends the sensor test above with a selection of 
HTTP Call tests:
+
+- application url returns a HTTP status code 200 within 60 seconds.
+- response body matches the regex `(?s).*Br[o]{2}klyn Deployed.*`. Note the 
presence of the `(?s)` dotall flag to test a multiline response.
+
+{% highlight yaml %}
+{% readj example_yaml/simple-tomcat-app-http-test-snippet.yaml %}
+{% endhighlight %}
+
+### Effector Test Example
+
+Extending the preceeding examples yet again, the following yaml snippet 
invokes the Tomcat entities `deploy` effector to deploy a new war file whose 
endpoint is subsequently tested:
+
+- `deploy` effector invoked to deploy war to a `newcontext`
+- `/newcontext` url returns a HTTP status code 200 within 5 minutes.
+
+{% highlight yaml %}
+{% readj example_yaml/simple-tomcat-app-effector-test-snippet.yaml %}
+{% endhighlight %}
+
+## Parallel Test example
+
+The preceeding examples had a single application entity which lends itself to 
running sequentially within a `TestCase` entity, if a Blueprint consists of 
multiple services then it is necessary to structure the test with multiple 
services starting under the `ParallelTestCase` entity.
+
+The following example tests the example multi-service application from the 
[Getting Started]({{ site.path.guide }}/start/blueprints.html#entitlements) 
section.
+
+{% highlight yaml %}
+{% readj example_yaml/paralleltestcase-example.yaml %}
+{% endhighlight %}
\ No newline at end of file

Reply via email to