[Tomcat] Add unit-tests to Tomcat application

It contains mock examples and shows how to
test tomcat application deployment without murano-engine
and heat set up

Change-Id: Ic00209dce747c11c56734ae440b8d78a63bd42c1
This commit is contained in:
Ekaterina Chernova 2015-12-18 16:30:11 +03:00
parent 70568f2e68
commit 884612b572
4 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,71 @@
Namespaces:
=: io.murano.test
sys: io.murano.system
Extends: TestFixture
Name: TomcatTest
Methods:
initialize:
Body:
# Object model can be loaded from json file, or provided
# directly in MuranoPL code as a yaml insertion.
- $.appJson: new(sys:Resources).json('tomcat-for-mock.json')
- $.heatOutput: new(sys:Resources).json('output.json')
- $.log: logger('test')
- $.agentCallCount: 0
# Mock method to replace the original one
agentMock:
Arguments:
- template:
Contract: $
- resources:
Contract: $
- timeout:
Contract: $
Default: null
Body:
- $.log.info('Mocking murano agent')
- $.assertEqual('Deploy Tomcat', $template.Name)
- $.agentCallCount: $.agentCallCount + 1
# Mock method, that returns predefined heat stack output
getStackOut:
Body:
- $.log.info('Mocking heat stack')
- Return: $.heatOutput
testDeploy1:
Body:
# Loading object model
- $.env: $this.load($.appJson)
# Set up mock for the push method of *io.murano.system.HeatStack* class
- inject(sys:HeatStack, push, $.heatOutput)
# Set up mock for the concrete object with mock method name
- inject($.env.stack, output, $.heatOutput)
# Set up mock with YAQL function
- inject('io.murano.system.Agent', call, $this, agentMock)
# Mocks will be called instead of original function during the deployment
- $.env.deploy()
# Check, that mock worked correctly
- $.assertEqual($.agentCallCount, 1)
testDeploy2:
Body:
- inject(sys:HeatStack, push, $this, getStackOut)
- inject(sys:HeatStack, output, $this, getStackOut)
# Mock is defined with YAQL function and it will print the original variable (agent template)
- inject(sys:Agent, call, withOriginal(t => $template) -> $.log.info('{0}', $t))
- $.env: $this.load($.appJson)
- $.env.deploy()

View File

@ -0,0 +1,8 @@
{
"cnxubigthiddg2-id": "f86c752d-dd4f-42e0-9982-3e66072362c7",
"cnxubigthiddg2-assigned-ips": {
"quick-env-1-network-8604202a0f1a40419dcdda0fbc7a25da": [
"10.0.168.2"
]
},
"quick-env-1-network-id": "1dd9652c-87df-43ee-8a1c-d31e78912b08"}

View File

@ -0,0 +1,41 @@
{"Attributes": [], "Objects": {
"defaultNetworks": {
"environment": {
"name": "quick-env-1-network",
"?": {
"type": "io.murano.resources.NeutronNetwork",
"id": "326e367d49f34d4c8d3b234d053411f3"
}
},
"flat": null
},
"name": "test",
"?": {
"type": "io.murano.Environment",
"id": "41549905e496409685339575dbd01894"
},
"applications": [
{
"instance": {
"availabilityZone": "nova",
"name": "cnxubigthiddg2",
"assignFloatingIp": false,
"keyname": "kate",
"flavor": "m1.medium",
"image": "283aa37f-d18a-48fc-b94e-c0721dbcf059",
"?": {
"type": "io.murano.resources.LinuxMuranoInstance",
"id": "13e3c264-f002-4958-a619-94d13d7fa3f5"
}
},
"name": "Tomcat",
"?": {
"_26411a1861294160833743e45d0eaad9": {
"name": "Apache Tomcat"
},
"type": "io.murano.apps.apache.Tomcat",
"id": "312534e2-f1aa-4ed3-811c-7f5c10530484"
}
}
]
}}

View File

@ -20,3 +20,4 @@ Author: 'Mirantis, Inc'
Tags: [Servlets, Server, Pages, Java]
Classes:
io.murano.apps.apache.Tomcat: Tomcat.yaml
io.murano.test.TomcatTest: TomcatTest.yaml