summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/incidental_xml/tasks/test-add-element-implicitly.yml
blob: db674ba4fc07c43b6d59b2494c15bcf2deeb0f1b (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
---
- name: Setup test fixture
  copy:
    src: fixtures/ansible-xml-beers.xml
    dest: /tmp/ansible-xml-beers-implicit.xml


- name: Add a phonenumber element to the business element. Implicit mkdir -p behavior where applicable
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/phonenumber
    value: 555-555-1234

- name: Add a owner element to the business element, testing implicit mkdir -p behavior 1/2
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/owner/name/last
    value: Smith

- name: Add a owner element to the business element, testing implicit mkdir -p behavior 2/2
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/owner/name/first
    value: John

- name: Add a validxhtml element to the website element. Note that ensure is present by default and while value defaults to null for elements, if one doesn't specify it we don't know what to do.
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/website/validxhtml

- name: Add an empty validateon attribute to the validxhtml element. This actually makes the previous example redundant because of the implicit parent-node creation behavior.
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/website/validxhtml/@validateon

- name: Add an empty validateon attribute to the validxhtml element. Actually verifies the implicit parent-node creation behavior.
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/website_bis/validxhtml/@validateon

- name: Add an attribute with a value
  xml:
     file: /tmp/ansible-xml-beers-implicit.xml
     xpath: /business/owner/@dob='1976-04-12'

- name: Add an element with a value, alternate syntax
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/beers/beer/text()="George Killian's Irish Red"  # note the quote within an XPath string thing

- name: Add an element without special characters
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/testnormalelement
    value: xml tag with no special characters
    pretty_print: yes

- name: Add an element with dash
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/test-with-dash
    value: xml tag with dashes
    pretty_print: yes

- name: Add an element with dot
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/test-with-dash.and.dot
    value: xml tag with dashes and dots
    pretty_print: yes

- name: Add an element with underscore
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/test-with.dash_and.dot_and-underscores
    value: xml tag with dashes, dots and underscores
    pretty_print: yes

- name: Add an attribute on a conditional element
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/beers/beer[text()="George Killian's Irish Red"]/@color='red'

- name: Add two attributes on a conditional element
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/beers/beer[text()="Pilsner Urquell" and @origin='CZ']/@color='blonde'

- name: Add a owner element to the business element, testing implicit mkdir -p behavior 3/2 -- complex lookup
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/owner/name[first/text()='John']/middle
    value: Q

- name: Pretty Print this!
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    pretty_print: yes

- name: Compare to expected result
  copy:
    src: results/test-add-element-implicitly.yml
    dest: /tmp/ansible-xml-beers-implicit.xml
  check_mode: yes
  diff: yes
  register: comparison

- name: Test expected result
  assert:
    that:
    - comparison.changed == false  # identical
  #command: diff -u {{ role_path }}/results/test-add-element-implicitly.yml /tmp/ansible-xml-beers-implicit.xml


# Now we repeat the same, just to ensure proper use of namespaces
- name: Add a phonenumber element to the business element. Implicit mkdir -p behavior where applicable
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:phonenumber
    value: 555-555-1234
    namespaces:
      a: http://example.com/some/namespace

- name: Add a owner element to the business element, testing implicit mkdir -p behavior 1/2
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:owner/a:name/a:last
    value: Smith
    namespaces:
      a: http://example.com/some/namespace

- name: Add a owner element to the business element, testing implicit mkdir -p behavior 2/2
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:owner/a:name/a:first
    value: John
    namespaces:
      a: http://example.com/some/namespace

- name: Add a validxhtml element to the website element. Note that ensure is present by default and while value defaults to null for elements, if one doesn't specify it we don't know what to do.
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:website/a:validxhtml
    namespaces:
      a: http://example.com/some/namespace

- name: Add an empty validateon attribute to the validxhtml element. This actually makes the previous example redundant because of the implicit parent-node creation behavior.
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:website/a:validxhtml/@a:validateon
    namespaces:
      a: http://example.com/some/namespace

- name: Add an empty validateon attribute to the validxhtml element. Actually verifies the implicit parent-node creation behavior.
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:website_bis/a:validxhtml/@a:validateon
    namespaces:
      a: http://example.com/some/namespace

- name: Add an attribute with a value
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:owner/@a:dob='1976-04-12'
    namespaces:
      a: http://example.com/some/namespace

- name: Add an element with a value, alternate syntax
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:beers/a:beer/text()="George Killian's Irish Red"  # note the quote within an XPath string thing
    namespaces:
      a: http://example.com/some/namespace

- name: Add an attribute on a conditional element
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:beers/a:beer[text()="George Killian's Irish Red"]/@a:color='red'
    namespaces:
      a: http://example.com/some/namespace

- name: Add two attributes on a conditional element
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:beers/a:beer[text()="Pilsner Urquell" and @a:origin='CZ']/@a:color='blonde'
    namespaces:
      a: http://example.com/some/namespace

- name: Add a owner element to the business element, testing implicit mkdir -p behavior 3/2 -- complex lookup
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/a:owner/a:name[a:first/text()='John']/a:middle
    value: Q
    namespaces:
      a: http://example.com/some/namespace

- name: Add an element without special characters
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/testnormalelement
    value: xml tag with no special characters
    pretty_print: yes
    namespaces:
      a:  http://example.com/some/namespace


- name: Add an element with dash
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/test-with-dash
    value: xml tag with dashes
    pretty_print: yes
    namespaces:
      a:  http://example.com/some/namespace

- name: Add an element with dot
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/test-with-dash.and.dot
    value: xml tag with dashes and dots
    pretty_print: yes
    namespaces:
      a:  http://example.com/some/namespace

- name: Add an element with underscore
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    xpath: /business/test-with.dash_and.dot_and-underscores
    value: xml tag with dashes, dots and underscores
    pretty_print: yes
    namespaces:
      a:  http://example.com/some/namespace

- name: Pretty Print this!
  xml:
    file: /tmp/ansible-xml-beers-implicit.xml
    pretty_print: yes