| 1 |
--- |
| 2 |
# Copyright (c) 2019, Andrew Klychkov (@Andersson007) <[email protected]> |
| 3 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
# Integration tests for jboss module. |
| 5 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 |
|
| 7 |
# helloworld.war (got from https://github.com/aeimer/java-example-helloworld-war/) is licensed |
| 8 |
# under the MIT license: |
| 9 |
# |
| 10 |
# Copyright (c) 2017 Alex Eimer |
| 11 |
# |
| 12 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 13 |
# of this software and associated documentation files (the "Software"), to deal |
| 14 |
# in the Software without restriction, including without limitation the rights |
| 15 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 16 |
# copies of the Software, and to permit persons to whom the Software is |
| 17 |
# furnished to do so, subject to the following conditions: |
| 18 |
# |
| 19 |
# The above copyright notice and this permission notice shall be included in all |
| 20 |
# copies or substantial portions of the Software. |
| 21 |
# |
| 22 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 23 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 24 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 25 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 26 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 27 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 28 |
# SOFTWARE. |
| 29 |
# |
| 30 |
# =============================== |
| 31 |
# Module's note section contains: |
| 32 |
# "- The JBoss standalone deployment-scanner has to be enabled in standalone.xml" |
| 33 |
# |
| 34 |
# Also from https://docs.jboss.org/author/display/WFLY10/Application+deployment?_sscc=t |
| 35 |
# "Deployment content (for example, war, ear, jar, and sar files) can be placed |
| 36 |
# in the standalone/deployments directory of the WildFly distribution, |
| 37 |
# in order to be automatically deployed into the server runtime. |
| 38 |
# For this to work the deployment-scanner subsystem must be present. |
| 39 |
# The scanner periodically checks the contents of the deployments directory |
| 40 |
# and reacts to changes by updating the server." |
| 41 |
# Regarding the information above JBoss server must be installed and running for full test suite. |
| 42 |
# We use WildFly server, free alternative, instead. See setup_wildfly_server role for more information. |
| 43 |
|
| 44 |
- vars: |
| 45 |
war_file_1: 'helloworld-1.war' |
| 46 |
war_file_1_path: '{{ wf_homedir }}/{{ war_file_1 }}' |
| 47 |
fake_src_path: /fake/src |
| 48 |
test_deployment: helloworld-1.war |
| 49 |
task_parameters: &task_parameters |
| 50 |
become_user: '{{ wf_user }}' |
| 51 |
become: true |
| 52 |
register: result |
| 53 |
|
| 54 |
block: |
| 55 |
- name: Create test files |
| 56 |
<<: *task_parameters |
| 57 |
get_url: |
| 58 |
url: 'https://ansible-ci-files.s3.amazonaws.com/test/integration/targets/jboss/{{ war_file_1 }}' |
| 59 |
dest: '{{ wf_homedir }}' |
| 60 |
|
| 61 |
################## |
| 62 |
# Start the tests: |
| 63 |
|
| 64 |
# Test if state=present and not deployed, check_mode: |
| 65 |
- name: jboss - deploy war in check_mode, the default deploy_path |
| 66 |
<<: *task_parameters |
| 67 |
jboss: |
| 68 |
deployment: '{{ war_file_1 }}' |
| 69 |
src: '{{ war_file_1_path }}' |
| 70 |
check_mode: true |
| 71 |
|
| 72 |
- assert: |
| 73 |
that: |
| 74 |
- result is changed |
| 75 |
|
| 76 |
# Check |
| 77 |
- name: check that nothing changed after the previous step |
| 78 |
<<: *task_parameters |
| 79 |
file: |
| 80 |
path: '{{ deploy_dir }}/{{ war_file_1 }}.deployed' |
| 81 |
ignore_errors: true |
| 82 |
|
| 83 |
- assert: |
| 84 |
that: |
| 85 |
- "'is absent' in result.msg" |
| 86 |
|
| 87 |
# Test if state=present and not deployed, actual mode: |
| 88 |
- name: jboss - deploy war |
| 89 |
<<: *task_parameters |
| 90 |
jboss: |
| 91 |
deployment: helloworld-1.war |
| 92 |
deploy_path: '{{ deploy_dir }}' |
| 93 |
src: '{{ war_file_1_path }}' |
| 94 |
|
| 95 |
- assert: |
| 96 |
that: |
| 97 |
- result is changed |
| 98 |
|
| 99 |
# Check |
| 100 |
- name: check that the file is deployed after the previous step |
| 101 |
<<: *task_parameters |
| 102 |
file: |
| 103 |
path: '{{ deploy_dir }}/{{ war_file_1 }}.deployed' |
| 104 |
|
| 105 |
- assert: |
| 106 |
that: |
| 107 |
- result.state == 'file' |
| 108 |
|
| 109 |
# Test if state=present and deployed in check mode, try again: |
| 110 |
- name: jboss - try again to deploy war in check_mode, war is deployed now |
| 111 |
<<: *task_parameters |
| 112 |
jboss: |
| 113 |
deployment: '{{ war_file_1 }}' |
| 114 |
src: '{{ war_file_1_path }}' |
| 115 |
deploy_path: '{{ deploy_dir }}' |
| 116 |
check_mode: true |
| 117 |
|
| 118 |
- assert: |
| 119 |
that: |
| 120 |
- result is not changed |
| 121 |
|
| 122 |
# Test if state=present and deployed, try again: |
| 123 |
- name: jboss - try again to deploy war in actual mode, war is deployed now |
| 124 |
<<: *task_parameters |
| 125 |
jboss: |
| 126 |
deployment: '{{ war_file_1 }}' |
| 127 |
src: '{{ war_file_1_path }}' |
| 128 |
deploy_path: '{{ deploy_dir }}' |
| 129 |
|
| 130 |
- assert: |
| 131 |
that: |
| 132 |
- result is not changed |
| 133 |
|
| 134 |
# Check |
| 135 |
- name: check that nothing changed after the previous step |
| 136 |
<<: *task_parameters |
| 137 |
file: |
| 138 |
path: '{{ deploy_dir }}/{{ war_file_1 }}.deployed' |
| 139 |
|
| 140 |
- assert: |
| 141 |
that: |
| 142 |
- result.state == 'file' |
| 143 |
|
| 144 |
# Test if state=absent and deployed: |
| 145 |
- name: jboss - undeploy war in check_mode, war is deployed |
| 146 |
<<: *task_parameters |
| 147 |
jboss: |
| 148 |
deployment: '{{ war_file_1 }}' |
| 149 |
deploy_path: '{{ deploy_dir }}' |
| 150 |
state: absent |
| 151 |
check_mode: true |
| 152 |
|
| 153 |
- assert: |
| 154 |
that: |
| 155 |
- result is changed |
| 156 |
|
| 157 |
- name: check that nothing actually changed after the previous step |
| 158 |
<<: *task_parameters |
| 159 |
file: |
| 160 |
path: '{{ deploy_dir }}/{{ war_file_1 }}.deployed' |
| 161 |
|
| 162 |
- assert: |
| 163 |
that: |
| 164 |
- result.state == 'file' |
| 165 |
|
| 166 |
# Test if state=absent and deployed: |
| 167 |
- name: jboss - undeploy war in actual mode, war is deployed |
| 168 |
<<: *task_parameters |
| 169 |
jboss: |
| 170 |
deployment: '{{ war_file_1 }}' |
| 171 |
deploy_path: '{{ deploy_dir }}' |
| 172 |
state: absent |
| 173 |
|
| 174 |
- assert: |
| 175 |
that: |
| 176 |
- result is changed |
| 177 |
|
| 178 |
- name: check that file is undeployed after the previous step |
| 179 |
<<: *task_parameters |
| 180 |
file: |
| 181 |
path: '{{ deploy_dir }}/{{ war_file_1 }}.undeployed' |
| 182 |
|
| 183 |
- assert: |
| 184 |
that: |
| 185 |
- result.state == 'file' |
| 186 |
|
| 187 |
# Test if state=absent and undeployed: |
| 188 |
- name: jboss - undeploy war in check_mode, war is undeployed |
| 189 |
<<: *task_parameters |
| 190 |
jboss: |
| 191 |
deployment: '{{ war_file_1 }}' |
| 192 |
deploy_path: '{{ deploy_dir }}' |
| 193 |
state: absent |
| 194 |
check_mode: true |
| 195 |
|
| 196 |
- assert: |
| 197 |
that: |
| 198 |
- result is not changed |
| 199 |
|
| 200 |
# Test if state=absent and undeployed: |
| 201 |
- name: jboss - undeploy war in actual_mode, war is undeployed |
| 202 |
<<: *task_parameters |
| 203 |
jboss: |
| 204 |
deployment: '{{ war_file_1 }}' |
| 205 |
deploy_path: '{{ deploy_dir }}' |
| 206 |
state: absent |
| 207 |
|
| 208 |
- assert: |
| 209 |
that: |
| 210 |
- result is not changed |
| 211 |
|
| 212 |
# Test fake src: |
| 213 |
- name: jboss - test fake src |
| 214 |
<<: *task_parameters |
| 215 |
jboss: |
| 216 |
deployment: '{{ war_file_1 }}' |
| 217 |
deploy_path: '{{ deploy_dir }}' |
| 218 |
src: '{{ fake_src_path }}' |
| 219 |
state: present |
| 220 |
ignore_errors: true |
| 221 |
|
| 222 |
- assert: |
| 223 |
that: |
| 224 |
- result is failed |
| 225 |
- "'Source file {{ fake_src_path }} does not exist.' in result.msg" |
| 226 |
|
| 227 |
# Test errors where state=present and src is not passed: |
| 228 |
- name: jboss - must fail when state=present and src is not passed |
| 229 |
<<: *task_parameters |
| 230 |
jboss: |
| 231 |
deployment: '{{ war_file_1 }}' |
| 232 |
state: present |
| 233 |
ignore_errors: true |
| 234 |
|
| 235 |
- assert: |
| 236 |
that: |
| 237 |
- result is failed |
| 238 |
- "'state is present but all of the following are missing: src' in result.msg" |