summaryrefslogtreecommitdiff
path: root/Tomcat/package/Classes/TomcatTest.yaml
blob: 792cc6630589a737392dac277db4e3eeafe4e0a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

Namespaces:
  =: io.murano.test
  sys: io.murano.system

Extends: TestFixture

Name: TomcatTest

Methods:
    .init:
        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
        # by providing YAQL expression representing the predefined heat output
        - inject(sys:HeatStack, push, $.heatOutput)

        # Set up mock for the output method of env's stack in the same way
        - inject($.env.stack, output, $.heatOutput)

        # Set up mock for the call method of murano agent class
        # by providing the name of the method from the test class
        - 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()

        # Check, that variable has a correct value
        - $isDeployed: $.env.applications[0].getAttr(deployed, false, 'com.example.apache.Tomcat')
        - $.assertEqual(true, $isDeployed)