/
URLClient.java
631 lines (521 loc) · 22.6 KB
/
URLClient.java
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
/*
* Copyright (c) 2009, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
/*
* $Id$
*/
package com.sun.ts.tests.jsf.spec.render.manylistbox;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.List;
import java.util.TreeMap;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlOption;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSelect;
import com.sun.javatest.Status;
import com.sun.ts.tests.jsf.common.client.BaseHtmlUnitClient;
import com.sun.ts.tests.jsf.spec.render.common.SelectManyValidator;
public class URLClient extends BaseHtmlUnitClient {
private static final String CONTEXT_ROOT = "/jsf_render_manylistbox_web";
public static void main(String[] args) {
URLClient theTests = new URLClient();
Status s = theTests.run(args, new PrintWriter(System.out, true),
new PrintWriter(System.err, true));
s.exit();
}
public Status run(String[] args, PrintWriter out, PrintWriter err) {
return super.run(args, out, err);
}
/*
* @class.setup_props: webServerHost; webServerPort; ts_home;
*/
/**
* @testName: manyListboxRenderEncodeTest
*
* @assertion_ids: PENDING
*
* @test_Strategy: Validate the rendering of jakarta.faces.SelectOne.Listbox
* case 1: - Only the id attribute is defined and two options.
* Verify that - the correct number of options are rendered -
* none of the options are selected - the value attributes for
* each option are correctly rendered. case 2: - Attributes
* for id, enabledClass, and disabledClass are defined. Verify
* that - each option is rendered as enabled or disabled as
* appropriate, and - each option is rendered with the correct
* style class. case 3: - Attributes for id, value, and class
* are defined. case 4,5: - ensure the disabled attribute is
* handled using html attribute minimization (only the
* attribute name is rendered when value is true, and nothing
* rendered when false) case 6,7: - ensure the readonly
* attribute is handled using html attribute minimization
* (only the attribute name is rendered when value is true,
* and nothing rendered when false) case 8: - Ensure that the
* size and multiple attrubute are render correctly. case 9:
* Ensure when using the binding attribute that the following
* holds true. - Only the id attribute is defined and two
* options. Verify that - the correct number of options are
* rendered - none of the options are selected - the value
* attributes for each option are correctly rendered.
*
* @since 1.2
*/
public void manyListboxRenderEncodeTest() throws Fault {
StringBuilder messages = new StringBuilder(128);
Formatter formatter = new Formatter(messages);
HtmlPage page = getPage(CONTEXT_ROOT + "/faces/encodetest.xhtml");
// ------------------------------------------------------------ listbox1
HtmlSelect listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox1");
if (!validateExistence(listbox1.getId(), "select", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
if (listbox1.getOptionSize() != 2) {
formatter.format(
"Expected the number of options rendered for"
+ " the component listbox1 to be '%d', but found '%d'",
2, listbox1.getOptionSize());
}
List<HtmlOption> selectedOptions = listbox1.getSelectedOptions();
if (selectedOptions == null) {
formatter.format("List of selected options for listbox1 is null");
handleTestStatus(messages);
return;
}
if (selectedOptions.size() != 0) {
formatter.format("Expected the number of selected options "
+ "rendered for the component listbox1 to be '%d', but "
+ "found '%d'", 0, selectedOptions.size());
}
if (!"true".equals(listbox1.getOption(0).getValueAttribute())) {
formatter.format(
"Expected the value of option '%d' for listbox1"
+ " to be '%s', found '%s'",
0, "true", listbox1.getOption(0).getValueAttribute());
}
if (!"false".equals(listbox1.getOption(1).getValueAttribute())) {
formatter.format(
"Expected the value of option '%d' for listbox1"
+ " to be '%s', found '%s'",
1, "true", listbox1.getOption(1).getValueAttribute());
}
// ------------------------------------------------------------ listbox2
HtmlSelect listbox2 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox2");
if (!validateExistence(listbox2.getId(), "select", listbox2, formatter)) {
handleTestStatus(messages);
return;
}
if (!"disabled".equals(listbox2.getOption(0).getDisabledAttribute())) {
formatter.format("Expected option '%d' for listbox2 to be '%s'", 0,
"disabled");
}
if (!"Color: red;".equals(listbox2.getOption(0).getAttribute("class"))) {
formatter.format(
"Expected the value of the class attribute for"
+ "option '%d' for listbox2" + " to be '%s', found '%s'",
0, "Color: red;", listbox2.getOption(0).getAttribute("class"));
}
if (listbox2.getOption(1).isDisabled()) {
formatter.format("Expected option '%d' for listbox2 to be '%s'", 1,
"enabled");
}
if (!"text".equals(listbox2.getOption(1).getAttribute("class"))) {
formatter.format(
"Expected the value of the class attribute for"
+ "option '%d' for listbox2" + " to be '%s', found '%s'",
1, "text", listbox2.getOption(1).getAttribute("class"));
}
// ------------------------------------------------------------ listbox3
HtmlSelect listbox3 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox3");
if (!validateExistence(listbox3.getId(), "select", listbox3, formatter)) {
handleTestStatus(messages);
return;
}
if (!"text".equals(listbox3.getAttribute("class"))) {
formatter.format(
"Expected the rendered value of the class "
+ "attribute to be 'text' for the text field containing"
+ " ID 'listbox3', but found '%s'%n",
listbox3.getAttribute("class"));
}
// ------------------------------------------------------------ listbox4
HtmlSelect listbox4 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox4");
if (!validateExistence(listbox4.getId(), "select", listbox4, formatter)) {
handleTestStatus(messages);
return;
}
if (!"disabled".equals(listbox4.getDisabledAttribute())) {
formatter.format(
"(listbox4) Expected the disabled attribute "
+ "to be rendered as '%s', instead found '%s'%n",
"disabled", listbox4.getDisabledAttribute());
}
// ------------------------------------------------------------ listbox5
HtmlSelect listbox5 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox5");
if (!validateExistence(listbox5.getId(), "select", listbox5, formatter)) {
handleTestStatus(messages);
return;
}
if (!HtmlElement.ATTRIBUTE_NOT_DEFINED
.equals(listbox5.getDisabledAttribute())) {
formatter.format("(listbox5) Expected the disabled attribute "
+ "to not be rendered when the disabled "
+ "attribute was specified as false in the JSP%n.");
}
// ------------------------------------------------------------ listbox6
HtmlSelect listbox6 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox6");
if (!validateExistence(listbox6.getId(), "select", listbox6, formatter)) {
handleTestStatus(messages);
return;
}
if (!"readonly".equals(listbox6.getAttribute("readonly"))) {
formatter.format(
"(listbox6) Expected the readonly attribute "
+ "to be rendered as '%s', instead found '%s'%n",
"readonly", listbox6.getAttribute("readonly"));
}
// ------------------------------------------------------------ listbox7
HtmlSelect listbox7 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox7");
if (!validateExistence(listbox7.getId(), "select", listbox7, formatter)) {
handleTestStatus(messages);
return;
}
if (!HtmlElement.ATTRIBUTE_NOT_DEFINED
.equals(listbox7.getAttribute("readonly"))) {
formatter.format("(listbox7) Expected the readonly attribute "
+ "to not be rendered when the readonly "
+ "attribute was specified as false in the JSP" + "%n");
}
// ------------------------------------------------------------ listbox8
HtmlSelect listbox8 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox8");
if (!validateExistence(listbox8.getId(), "select", listbox8, formatter)) {
handleTestStatus(messages);
return;
}
if (!"multiple".equals(listbox8.getMultipleAttribute())) {
formatter.format(
"Expected the rendered value of the multiple "
+ "attribute to be '%s', instead found '%s'%n",
"mulitple", listbox8.getMultipleAttribute());
}
if ("".equals(listbox8.getSizeAttribute())
|| 5 != Integer.parseInt(listbox8.getSizeAttribute())) {
formatter.format("(listbox8) Expected the size attribute "
+ "to be rendered as the value of '%s', instead found " + "'%s' %n.",
5, listbox8.getSizeAttribute());
}
// ------------------------------------------------------------ listbox9
HtmlSelect listbox9 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "form:listbox9");
if (!validateExistence(listbox9.getId(), "select", listbox9, formatter)) {
handleTestStatus(messages);
return;
}
if (listbox9.getOptionSize() != 2) {
formatter.format(
"Unexpected number of options rendered for"
+ " the component '%s' %n." + "Expected: '%d' %n"
+ "Recieved: '%d' %n",
listbox9.getId(), 2, listbox9.getOptionSize());
}
List<HtmlOption> selected = listbox9.getSelectedOptions();
if (selected.size() != 0) {
formatter.format("Unexpected the number of selected options "
+ "rendered for the component '%s' %n." + "Expected: '%d' %n"
+ "Received: '%d'", listbox9.getId(), 0, selectedOptions.size());
}
if (!"no".equals(listbox9.getOption(0).getValueAttribute())) {
formatter.format(
"Unexpected value for option '%d' for '%s' %n" + "Expected: '%s' '%n'"
+ "Received: '%s'",
0, "no", listbox9.getOption(0).getValueAttribute(), listbox9.getId());
}
if (!"yes".equals(listbox9.getOption(1).getValueAttribute())) {
formatter.format(
"Unexpected value for option '%d' for '%s' %n" + "Expected: '%s' '%n'"
+ "Received: '%s'",
0, "yes", listbox9.getOption(1).getValueAttribute(),
listbox9.getId());
}
handleTestStatus(messages);
} // END manyListboxRenderEncodeTest
/**
* @testName: manyListboxRenderDecodeTest
*
* @assertion_ids: PENDING
*
* @test_Strategy: Create a listbox with three options. Click a button to
* select one option and submit the form. Verify that the
* correct option is selected. Click the button again to
* select another option. Verify that the correct option is
* selected and that the original option is no longer
* selected. Select the first and last options in the list,
* click the button. Verify teh correct options are selected.
* Then select all the options and submit the form, Verify all
* options are selected.
*
* @since 1.2
*/
public void manyListboxRenderDecodeTest() throws Fault {
StringBuilder messages = new StringBuilder(128);
Formatter formatter = new Formatter(messages);
HtmlPage page = getPage(CONTEXT_ROOT + "/faces/decodetest.xhtml");
HtmlSelect listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "listbox1");
if (!validateExistence(listbox1.getId(), "select", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
List<HtmlOption> selectedOptions = listbox1.getSelectedOptions();
if (selectedOptions.size() != 0) {
formatter.format("Expected the number of selected options "
+ "rendered for the component listbox1 to be '%d', but "
+ "found '%d'", 0, selectedOptions.size());
}
listbox1.getOption(0).setSelected(true);
listbox1.getOption(1).setSelected(false);
listbox1.getOption(2).setSelected(false);
HtmlInput button1 = (HtmlInput) getInputIncludingId(page, "button1");
try {
page = (HtmlPage) button1.click();
} catch (IOException e) {
formatter.format("Unexpected exception clicking button1: %s%n", e);
handleTestStatus(messages);
return;
}
listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page, "select",
"listbox1");
if (!validateExistence("listbox1", "input", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
if (!listbox1.getOption(0).isSelected()
|| listbox1.getOption(1).isSelected()
|| listbox1.getOption(2).isSelected()) {
formatter.format(
"After first click, expected option '%d' "
+ "selected attribute to be '%s', found '%s'; expected "
+ "option '%d' selected attribute to be '%s', found '%s';"
+ "expected option '%d' selected attribute to be '%s', "
+ "found '%s'.",
0, "true", listbox1.getOption(0).isSelected(), 1, "false",
listbox1.getOption(1).isSelected(), 2, "false",
listbox1.getOption(2).isSelected());
}
listbox1.getOption(0).setSelected(false);
listbox1.getOption(1).setSelected(true);
listbox1.getOption(2).setSelected(false);
button1 = (HtmlInput) getInputIncludingId(page, "button1");
try {
page = (HtmlPage) button1.click();
} catch (IOException e) {
formatter.format("Unexpected exception clicking button1: %s%n", e);
handleTestStatus(messages);
return;
}
listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page, "select",
"listbox1");
if (!validateExistence("listbox1", "input", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
if (listbox1.getOption(0).isSelected()
|| !listbox1.getOption(1).isSelected()
|| listbox1.getOption(2).isSelected()) {
formatter.format(
"After second click, expected option '%d' "
+ "selected attribute to be '%s', found '%s'; expected "
+ "option '%d' selected attribute to be '%s', found '%s'; "
+ "expected option '%d' selected attribute to be '%s', "
+ "found '%s'.",
0, "false", listbox1.getOption(0).isSelected(), 1, "true",
listbox1.getOption(1).isSelected(), 2, "false",
listbox1.getOption(0).isSelected());
}
listbox1.getOption(0).setSelected(true);
listbox1.getOption(1).setSelected(false);
listbox1.getOption(2).setSelected(true);
button1 = (HtmlInput) getInputIncludingId(page, "button1");
try {
page = (HtmlPage) button1.click();
} catch (IOException e) {
formatter.format("Unexpected exception clicking button1: %s%n", e);
handleTestStatus(messages);
return;
}
listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page, "select",
"listbox1");
if (!validateExistence("listbox1", "input", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
if (!listbox1.getOption(0).isSelected()
|| listbox1.getOption(1).isSelected()
|| !listbox1.getOption(2).isSelected()) {
formatter.format(
"After third click, expected option '%d' "
+ "selected attribute to be '%s', found '%s'; expected "
+ "option '%d' selected attribute to be '%s', found '%s';"
+ "expected option '%d' selected attribute to be '%s', "
+ "found '%s'.",
0, "true", listbox1.getOption(0).isSelected(), 1, "false",
listbox1.getOption(1).isSelected(), 2, "true",
listbox1.getOption(2).isSelected());
}
listbox1.getOption(0).setSelected(true);
listbox1.getOption(1).setSelected(true);
listbox1.getOption(2).setSelected(true);
button1 = (HtmlInput) getInputIncludingId(page, "button1");
try {
page = (HtmlPage) button1.click();
} catch (IOException e) {
formatter.format("Unexpected exception clicking button1: %s%n", e);
handleTestStatus(messages);
return;
}
listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page, "select",
"listbox1");
if (!validateExistence("listbox1", "input", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
if (!listbox1.getOption(0).isSelected()
|| !listbox1.getOption(1).isSelected()
|| !listbox1.getOption(2).isSelected()) {
formatter.format(
"After third click, expected option '%d' "
+ "selected attribute to be '%s', found '%s'; expected "
+ "option '%d' selected attribute to be '%s', found '%s';"
+ "expected option '%d' selected attribute to be '%s', "
+ "found '%s'.",
0, "true", listbox1.getOption(0).isSelected(), 1, "true",
listbox1.getOption(1).isSelected(), 2, "true",
listbox1.getOption(2).isSelected());
}
/*
* Validate Conversion Types (PDL == jsp)
*/
SelectManyValidator smv = new SelectManyValidator();
HtmlForm form2 = (HtmlForm) getElementOfTypeIncludingId(page, "form",
"selectmany01");
if (!smv.validate(page, formatter, form2)) {
handleTestStatus(messages);
return;
}
handleTestStatus(messages);
} // END manyListboxRenderDecodeTest
/**
* @testName: manyListboxSelectMany01Test
*
* @assertion_ids: PENDING
*
* @test_Strategy: If modelType is a concrete class, let
* targetForConvertedValues be a new instance of that class.
* Otherwise, the concrete type for targetForConvertedValues
* is taken from the following table. All classes are in the
* java.util package. All collections must be created with an
* initial capacity equal to the length of the values array
* from the request.
*
* modelType targetForConvertedValues
* -------------------------------------------- SortedSet
* TreeSet Queue LinkedList Set HashSet anything else
* ArrayList
*
* @since 2.0
*/
public void manyListboxSelectMany01Test() throws Fault {
StringBuilder messages = new StringBuilder(128);
Formatter formatter = new Formatter(messages);
HtmlPage page = getPage(CONTEXT_ROOT + "/faces/selectmany01.xhtml");
SelectManyValidator smv = new SelectManyValidator();
HtmlForm form = (HtmlForm) getElementOfTypeIncludingId(page, "form",
"selectmany01");
if (!smv.validate(page, formatter, form)) {
handleTestStatus(messages);
return;
}
handleTestStatus(messages);
} // END manyListboxSelectMany01Test
/**
* @testName: manyListboxRenderPassthroughTest
*
* @assertion_ids: PENDING
*
* @test_Strategy: Ensure the attributes that are considered passthrough by
* the specification are rendered as is.
*
* @since 1.2
*/
public void manyListboxRenderPassthroughTest() throws Fault {
StringBuilder messages = new StringBuilder(128);
Formatter formatter = new Formatter(messages);
TreeMap<String, String> control = new TreeMap<String, String>();
control.put("accesskey", "P");
control.put("dir", "LTR");
control.put("lang", "en");
control.put("onblur", "js1");
control.put("onchange", "js2");
control.put("onclick", "js3");
control.put("ondblclick", "js4");
control.put("onfocus", "js5");
control.put("onkeydown", "js6");
control.put("onkeypress", "js7");
control.put("onkeyup", "js8");
control.put("onmousedown", "js9");
control.put("onmousemove", "js10");
control.put("onmouseout", "js11");
control.put("onmouseover", "js12");
control.put("onmouseup", "js13");
control.put("style", "Color: red;");
control.put("tabindex", "0");
control.put("title", "title");
List<HtmlPage> pages = new ArrayList<HtmlPage>();
pages.add(getPage(CONTEXT_ROOT + "/faces/passthroughtest.xhtml"));
pages.add(getPage(CONTEXT_ROOT + "/faces/passthroughtest_facelet.xhtml"));
for (HtmlPage page : pages) {
// Facelet Specific PassThrough options
if (page.getTitleText().contains("facelet")) {
control.put("foo", "bar");
control.put("singleatt", "singleAtt");
control.put("manyattone", "manyOne");
control.put("manyatttwo", "manyTwo");
control.put("manyattthree", "manyThree");
}
HtmlSelect listbox1 = (HtmlSelect) getElementOfTypeIncludingId(page,
"select", "listbox1");
if (!validateExistence("listbox1", "select", listbox1, formatter)) {
handleTestStatus(messages);
return;
}
validateAttributeSet(control, listbox1,
new String[] { "id", "value", "name", "type", "size", "multiple" },
formatter);
handleTestStatus(messages);
}
} // END oneListboxRenderPassthroughTest
} // END URLClient