1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.myfaces.config;
17
18 import org.apache.myfaces.config.element.FacesConfig;
19 import org.apache.myfaces.config.element.OrderSlot;
20 import org.apache.myfaces.config.impl.digester.DigesterFacesConfigUnmarshallerImpl;
21 import org.apache.myfaces.config.impl.digester.elements.AbsoluteOrderingImpl;
22 import org.apache.myfaces.config.impl.digester.elements.ConfigOthersSlotImpl;
23 import org.apache.myfaces.config.impl.digester.elements.FacesConfigNameSlotImpl;
24 import org.apache.myfaces.config.impl.digester.elements.OrderingImpl;
25 import org.apache.myfaces.test.base.AbstractJsfTestCase;
26
27 import javax.faces.FacesException;
28 import java.util.ArrayList;
29 import java.util.Collections;
30 import java.util.List;
31 import java.util.logging.Level;
32 import java.util.logging.Logger;
33
34 public class OrderingFacesConfigTest extends AbstractJsfTestCase
35 {
36 private static final Logger log = Logger.getLogger(OrderingFacesConfigTest.class.getName());
37
38 private DigesterFacesConfigUnmarshallerImpl _impl;
39
40 public OrderingFacesConfigTest(String name)
41 {
42 super(name);
43 }
44
45 protected void setUp() throws Exception
46 {
47 super.setUp();
48 _impl = new DigesterFacesConfigUnmarshallerImpl(null);
49 }
50
51 public void printFacesConfigList(String label, List<FacesConfig> appConfigResources)
52 {
53 System.out.println("");
54 System.out.print(""+label+": [");
55 for (int i = 0; i < appConfigResources.size();i++)
56 {
57 if (appConfigResources.get(i).getName() == null)
58 {
59 System.out.print("No_id,");
60 }
61 else
62 {
63 System.out.print(appConfigResources.get(i).getName()+",");
64 }
65 }
66 System.out.println("]");
67
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81 public void testSimpleOrdering() throws Exception
82 {
83 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
84 "empty-config.xml"), "empty-config.xml");
85 FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
86 "a-config.xml"), "a-config.xml");
87 FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
88 "b-config.xml"), "b-config.xml");
89 FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
90 "c-config.xml"), "c-config.xml");
91
92
93 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
94 appConfigResources.add(cfgA);
95 appConfigResources.add(cfgB);
96 appConfigResources.add(cfgC);
97 appConfigResources.add(cfg);
98 appConfigResources.add(cfg);
99
100
101 for (int i = 0; i < 30; i++)
102 {
103 Collections.shuffle(appConfigResources);
104 applyAlgorithm(appConfigResources);
105 }
106 }
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124 public void testMiddleOrdering() throws Exception
125 {
126 FacesConfig cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
127 "empty-config.xml"), "empty-config.xml");
128 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
129 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
130 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
131 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
132 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgE = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
133
134 cfgA.setName("A");
135 cfgB.setName("B");
136 cfgC.setName("C");
137 cfgD.setName("D");
138 cfgE.setName("E");
139
140 cfgC.setOrdering(new OrderingImpl());
141 FacesConfigNameSlotImpl temp = new FacesConfigNameSlotImpl();
142 temp.setName("D");
143 cfgC.getOrdering().getBeforeList().add(temp);
144 temp = new FacesConfigNameSlotImpl();
145 temp.setName("E");
146 cfgC.getOrdering().getBeforeList().add(temp);
147 temp = new FacesConfigNameSlotImpl();
148 temp.setName("A");
149 cfgC.getOrdering().getAfterList().add(temp);
150 temp = new FacesConfigNameSlotImpl();
151 temp.setName("B");
152 cfgC.getOrdering().getAfterList().add(temp);
153
154 cfgA.setOrdering(new OrderingImpl());
155 temp = new FacesConfigNameSlotImpl();
156 temp.setName("B");
157 cfgA.getOrdering().getBeforeList().add(temp);
158 temp = new FacesConfigNameSlotImpl();
159 temp.setName("E");
160 cfgA.getOrdering().getBeforeList().add(temp);
161
162 cfgE.setOrdering(new OrderingImpl());
163 temp = new FacesConfigNameSlotImpl();
164 temp.setName("D");
165 cfgE.getOrdering().getAfterList().add(temp);
166
167 cfgD.setOrdering(new OrderingImpl());
168 cfgD.getOrdering().getBeforeList().add(new ConfigOthersSlotImpl());
169
170 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
171 appConfigResources.add(cfgA);
172 appConfigResources.add(cfgB);
173 appConfigResources.add(cfgC);
174 appConfigResources.add(cfgD);
175 appConfigResources.add(cfgE);
176 appConfigResources.add(cfg);
177
178
179 for (int i = 0; i < 30; i++)
180 {
181 Collections.shuffle(appConfigResources);
182 applyAlgorithm(appConfigResources);
183 }
184 }
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200 public void testMaxConditionsOrdering() throws Exception
201 {
202 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfg = _impl.getFacesConfig(getClass().getResourceAsStream(
203 "empty-config.xml"), "empty-config.xml");
204 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
205 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
206 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
207
208 cfgA.setName("A");
209 cfgB.setName("B");
210 cfgC.setName("C");
211
212 cfgA.setOrdering(new OrderingImpl());
213 FacesConfigNameSlotImpl temp = new FacesConfigNameSlotImpl();
214 temp.setName("B");
215 cfgA.getOrdering().getBeforeList().add(temp);
216 temp = new FacesConfigNameSlotImpl();
217 temp.setName("C");
218 cfgA.getOrdering().getBeforeList().add(temp);
219
220 cfgB.setOrdering(new OrderingImpl());
221 temp = new FacesConfigNameSlotImpl();
222 temp.setName("A");
223 cfgB.getOrdering().getAfterList().add(temp);
224 temp = new FacesConfigNameSlotImpl();
225 temp.setName("C");
226 cfgB.getOrdering().getBeforeList().add(temp);
227
228 cfgC.setOrdering(new OrderingImpl());
229 temp = new FacesConfigNameSlotImpl();
230 temp.setName("A");
231 cfgC.getOrdering().getAfterList().add(temp);
232 temp = new FacesConfigNameSlotImpl();
233 temp.setName("B");
234 cfgC.getOrdering().getAfterList().add(temp);
235
236
237 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
238 appConfigResources.add(cfgC);
239 appConfigResources.add(cfgA);
240 appConfigResources.add(cfgB);
241
242
243 for (int i = 0; i < 30; i++)
244 {
245 Collections.shuffle(appConfigResources);
246 applyAlgorithm(appConfigResources);
247 }
248 }
249
250 public void testEx1()
251 {
252 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
253 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
254 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
255 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
256 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgE = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
257 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgF = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
258
259 cfgA.setName("A");
260 cfgB.setName("B");
261 cfgC.setName("C");
262 cfgD.setName("D");
263 cfgE.setName("E");
264 cfgF.setName("F");
265
266 cfgA.setOrdering(new OrderingImpl());
267 cfgA.getOrdering().getAfterList().add(new ConfigOthersSlotImpl());
268 FacesConfigNameSlotImpl temp = new FacesConfigNameSlotImpl();
269 temp.setName("C");
270 cfgA.getOrdering().getAfterList().add(temp);
271
272 cfgB.setOrdering(new OrderingImpl());
273 cfgB.getOrdering().getBeforeList().add(new ConfigOthersSlotImpl());
274
275 cfgC.setOrdering(new OrderingImpl());
276 cfgC.getOrdering().getAfterList().add(new ConfigOthersSlotImpl());
277
278 cfgF.setOrdering(new OrderingImpl());
279 cfgF.getOrdering().getBeforeList().add(new ConfigOthersSlotImpl());
280 temp = new FacesConfigNameSlotImpl();
281 temp.setName("B");
282 cfgF.getOrdering().getBeforeList().add(temp);
283
284
285 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
286 appConfigResources.add(cfgA);
287 appConfigResources.add(cfgB);
288 appConfigResources.add(cfgC);
289 appConfigResources.add(cfgD);
290 appConfigResources.add(cfgE);
291 appConfigResources.add(cfgF);
292
293
294 for (int i = 0; i < 30; i++)
295 {
296 Collections.shuffle(appConfigResources);
297 applyAlgorithm(appConfigResources);
298 }
299 }
300
301 public void testEx2()
302 {
303 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfg = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
304 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
305 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
306 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
307 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgE = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
308 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgF = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
309
310 cfgB.setName("B");
311 cfgC.setName("C");
312 cfgD.setName("D");
313 cfgE.setName("E");
314 cfgF.setName("F");
315
316 cfg.setOrdering(new OrderingImpl());
317 cfg.getOrdering().getAfterList().add(new ConfigOthersSlotImpl());
318 FacesConfigNameSlotImpl temp = new FacesConfigNameSlotImpl();
319 temp.setName("C");
320 cfg.getOrdering().getBeforeList().add(temp);
321
322 cfgB.setOrdering(new OrderingImpl());
323 cfgB.getOrdering().getBeforeList().add(new ConfigOthersSlotImpl());
324
325 cfgD.setOrdering(new OrderingImpl());
326 cfgD.getOrdering().getAfterList().add(new ConfigOthersSlotImpl());
327
328 cfgE.setOrdering(new OrderingImpl());
329 cfgE.getOrdering().getBeforeList().add(new ConfigOthersSlotImpl());
330
331 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
332 appConfigResources.add(cfg);
333 appConfigResources.add(cfgB);
334 appConfigResources.add(cfgC);
335 appConfigResources.add(cfgD);
336 appConfigResources.add(cfgE);
337 appConfigResources.add(cfgF);
338
339
340 for (int i = 0; i < 30; i++)
341 {
342 Collections.shuffle(appConfigResources);
343 applyAlgorithm(appConfigResources);
344 }
345 }
346
347 public void testEx3()
348 {
349 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgA = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
350 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgB = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
351 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgC = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
352 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgD = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
353
354 cfgA.setName("A");
355 cfgB.setName("B");
356 cfgC.setName("C");
357 cfgD.setName("D");
358
359 cfgA.setOrdering(new OrderingImpl());
360 FacesConfigNameSlotImpl temp = new FacesConfigNameSlotImpl();
361 temp.setName("B");
362 cfgA.getOrdering().getAfterList().add(temp);
363
364 cfgC.setOrdering(new OrderingImpl());
365 cfgC.getOrdering().getBeforeList().add(new ConfigOthersSlotImpl());
366
367 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
368 appConfigResources.add(cfgA);
369 appConfigResources.add(cfgB);
370 appConfigResources.add(cfgC);
371 appConfigResources.add(cfgD);
372
373
374 for (int i = 0; i < 30; i++)
375 {
376 Collections.shuffle(appConfigResources);
377 applyAlgorithm(appConfigResources);
378 }
379 }
380
381 public void testEx4() throws Exception
382 {
383 FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
384 "transitive-a-config.xml"), "transitive-a-config.xml");
385 FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
386 "transitive-b-config.xml"), "transitive-b-config.xml");
387 FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
388 "transitive-c-config.xml"), "transitive-c-config.xml");
389
390 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
391 appConfigResources.add(cfgA);
392 appConfigResources.add(cfgB);
393 appConfigResources.add(cfgC);
394
395
396 for (int i = 0; i < 30; i++)
397 {
398 Collections.shuffle(appConfigResources);
399 applyAlgorithm(appConfigResources);
400 }
401 }
402
403 public void applyAlgorithm(List<FacesConfig> appConfigResources) throws FacesException
404 {
405 DefaultFacesConfigurationMerger merger = new DefaultFacesConfigurationMerger();
406
407 List<FacesConfig> postOrderedList = merger.getPostOrderedList(appConfigResources);
408
409 List<FacesConfig> sortedList = merger.sortRelativeOrderingList(postOrderedList);
410
411 if (sortedList == null)
412 {
413
414 sortedList = merger.applySortingAlgorithm(appConfigResources);
415 }
416
417
418 }
419
420 public void testBeforeOthers1() throws Exception
421 {
422 FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
423 "no-name-config.xml"), "no-name-config.xml");
424 FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
425 "no-name-config.xml"), "no-name-config.xml");
426 FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
427 "before-others-config.xml"), "before-others-config.xml");
428 FacesConfig cfgD = _impl.getFacesConfig(getClass().getResourceAsStream(
429 "no-name-config.xml"), "no-name-config.xml");
430 FacesConfig cfgE = _impl.getFacesConfig(getClass().getResourceAsStream(
431 "no-name-config.xml"), "no-name-config.xml");
432
433 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
434 appConfigResources.add(cfgA);
435 appConfigResources.add(cfgB);
436 appConfigResources.add(cfgC);
437 appConfigResources.add(cfgD);
438 appConfigResources.add(cfgE);
439
440
441 for (int i = 0; i < 30; i++)
442 {
443 Collections.shuffle(appConfigResources);
444 List<FacesConfig> sortedList = applyFullAlgorithm(appConfigResources);
445
446 assertEquals(cfgC, sortedList.get(0));
447 }
448 }
449
450 public void testAfterOthers1() throws Exception
451 {
452 FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
453 "no-name-config.xml"), "no-name-config.xml");
454 FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
455 "no-name-config.xml"), "no-name-config.xml");
456 FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
457 "after-others-config.xml"), "after-others-config.xml");
458 FacesConfig cfgD = _impl.getFacesConfig(getClass().getResourceAsStream(
459 "no-name-config.xml"), "no-name-config.xml");
460 FacesConfig cfgE = _impl.getFacesConfig(getClass().getResourceAsStream(
461 "no-name-config.xml"), "no-name-config.xml");
462
463 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
464 appConfigResources.add(cfgA);
465 appConfigResources.add(cfgB);
466 appConfigResources.add(cfgC);
467 appConfigResources.add(cfgD);
468 appConfigResources.add(cfgE);
469
470
471 for (int i = 0; i < 30; i++)
472 {
473 Collections.shuffle(appConfigResources);
474 List<FacesConfig> sortedList = applyFullAlgorithm(appConfigResources);
475
476 assertEquals(cfgC, sortedList.get(sortedList.size()-1));
477 }
478 }
479
480 public void testBeforeOthers2() throws Exception
481 {
482 FacesConfig cfg1 = _impl.getFacesConfig(getClass().getResourceAsStream(
483 "no-name-config.xml"), "no-name-config.xml");
484 FacesConfig cfg2 = _impl.getFacesConfig(getClass().getResourceAsStream(
485 "no-name-config.xml"), "no-name-config.xml");
486 FacesConfig cfg3 = _impl.getFacesConfig(getClass().getResourceAsStream(
487 "before-others-config.xml"), "before-others-config.xml");
488 FacesConfig cfg4 = _impl.getFacesConfig(getClass().getResourceAsStream(
489 "no-name-config.xml"), "no-name-config.xml");
490 FacesConfig cfg5 = _impl.getFacesConfig(getClass().getResourceAsStream(
491 "no-name-config.xml"), "no-name-config.xml");
492 FacesConfig cfgA = _impl.getFacesConfig(getClass().getResourceAsStream(
493 "transitive-a-config.xml"), "transitive-a-config.xml");
494 FacesConfig cfgB = _impl.getFacesConfig(getClass().getResourceAsStream(
495 "transitive-b-config.xml"), "transitive-b-config.xml");
496 FacesConfig cfgC = _impl.getFacesConfig(getClass().getResourceAsStream(
497 "transitive-c-config.xml"), "transitive-c-config.xml");
498 FacesConfig cfg6 = _impl.getFacesConfig(getClass().getResourceAsStream(
499 "after-others-config.xml"), "after-others-config.xml");
500
501
502 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
503 appConfigResources.add(cfgA);
504 appConfigResources.add(cfgB);
505 appConfigResources.add(cfgC);
506 appConfigResources.add(cfg1);
507 appConfigResources.add(cfg2);
508 appConfigResources.add(cfg3);
509 appConfigResources.add(cfg4);
510 appConfigResources.add(cfg5);
511 appConfigResources.add(cfg6);
512
513
514 for (int i = 0; i < 30; i++)
515 {
516 Collections.shuffle(appConfigResources);
517 List<FacesConfig> sortedList = applyFullAlgorithm(appConfigResources);
518
519 assertEquals(cfg3, sortedList.get(0));
520
521 assertEquals(cfg6, sortedList.get(sortedList.size()-1));
522 }
523 }
524
525 public List<FacesConfig> applyFullAlgorithm(List<FacesConfig> appConfigResources) throws FacesException
526 {
527 DefaultFacesConfigurationMerger merger = new DefaultFacesConfigurationMerger();
528
529 System.out.println("");
530 System.out.print("Start List: [");
531 for (int i = 0; i < appConfigResources.size();i++)
532 {
533 if (appConfigResources.get(i).getName() == null)
534 {
535 System.out.print("No id,");
536 }
537 else
538 {
539 System.out.print(appConfigResources.get(i).getName()+",");
540 }
541 }
542 System.out.println("]");
543
544 List<FacesConfig> postOrderedList = merger.getPostOrderedList(appConfigResources);
545
546 System.out.print("Pre-Ordered-List: [");
547 for (int i = 0; i < postOrderedList.size();i++)
548 {
549 if (postOrderedList.get(i).getName() == null)
550 {
551 System.out.print("No id,");
552 }
553 else
554 {
555 System.out.print(postOrderedList.get(i).getName()+",");
556 }
557 }
558 System.out.println("]");
559
560 List<FacesConfig> sortedList = merger.sortRelativeOrderingList(postOrderedList);
561
562 if (sortedList == null)
563 {
564 System.out.print("After Fix ");
565
566 sortedList = merger.applySortingAlgorithm(appConfigResources);
567 }
568
569 System.out.print("Sorted-List: [");
570 for (int i = 0; i < sortedList.size();i++)
571 {
572 if (sortedList.get(i).getName() == null)
573 {
574 System.out.print("No id,");
575 }
576 else
577 {
578 System.out.print(sortedList.get(i).getName()+",");
579 }
580 }
581 System.out.println("]");
582
583 return sortedList;
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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805 public void applyAlgorithm2(List<FacesConfig> appConfigResources) throws FacesException
806 {
807 DefaultFacesConfigurationMerger merger = new DefaultFacesConfigurationMerger();
808
809 System.out.println("");
810 System.out.print("Start List: [");
811 for (int i = 0; i < appConfigResources.size();i++)
812 {
813 if (appConfigResources.get(i).getName() == null)
814 {
815 System.out.print("No id,");
816 }
817 else
818 {
819 System.out.print(appConfigResources.get(i).getName()+",");
820 }
821 }
822 System.out.println("]");
823
824 List<FacesConfig> postOrderedList = merger.getPostOrderedList(appConfigResources);
825
826 System.out.print("Pre-Ordered-List: [");
827 for (int i = 0; i < postOrderedList.size();i++)
828 {
829 if (postOrderedList.get(i).getName() == null)
830 {
831 System.out.print("No id,");
832 }
833 else
834 {
835 System.out.print(postOrderedList.get(i).getName()+",");
836 }
837 }
838 System.out.println("]");
839
840 List<FacesConfig> sortedList = merger.sortRelativeOrderingList(postOrderedList);
841
842 System.out.print("Sorted-List: [");
843 for (int i = 0; i < sortedList.size();i++)
844 {
845 if (sortedList.get(i).getName() == null)
846 {
847 System.out.print("No id,");
848 }
849 else
850 {
851 System.out.print(sortedList.get(i).getName()+",");
852 }
853 }
854 System.out.println("]");
855 }
856
857 public void testAbsoluteOrdering1() throws Exception
858 {
859 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgAbs = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
860 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgMK = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
861 org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl cfgOWB = new org.apache.myfaces.config.impl.digester.elements.FacesConfigImpl();
862
863 cfgMK.setName("cz_markoc_faces");
864
865 AbsoluteOrderingImpl ao = new AbsoluteOrderingImpl();
866 FacesConfigNameSlotImpl temp = new FacesConfigNameSlotImpl();
867 temp.setName("cz_markoc_faces");
868 ao.addOrderSlot(temp);
869 ao.addOrderSlot(new ConfigOthersSlotImpl());
870
871 cfgAbs.setAbsoluteOrdering(ao);
872
873 List<FacesConfig> appConfigResources = new ArrayList<FacesConfig>();
874 appConfigResources.add(cfgMK);
875 appConfigResources.add(cfgOWB);
876
877
878
879 List<FacesConfig> sortedResources = orderAndFeedArtifactsAbsolute(appConfigResources, cfgAbs);
880
881
882
883 assertTrue(sortedResources.containsAll(appConfigResources));
884
885 appConfigResources = new ArrayList<FacesConfig>();
886 appConfigResources.add(cfgOWB);
887 appConfigResources.add(cfgMK);
888
889
890
891 sortedResources = orderAndFeedArtifactsAbsolute(appConfigResources, cfgAbs);
892
893
894
895 assertTrue(sortedResources.containsAll(appConfigResources));
896
897 }
898
899 public List<FacesConfig> orderAndFeedArtifactsAbsolute(List<FacesConfig> appConfigResources, FacesConfig webAppConfig)
900 {
901 FacesConfigurator configurator = new FacesConfigurator(externalContext);
902
903 if (webAppConfig != null && webAppConfig.getAbsoluteOrdering() != null)
904 {
905 if (webAppConfig.getOrdering() != null)
906 {
907 if (log.isLoggable(Level.WARNING))
908 {
909 log.warning("<ordering> element found in application faces config. " +
910 "This description will be ignored and the actions described " +
911 "in <absolute-ordering> element will be taken into account instead.");
912 }
913 }
914
915
916
917
918
919 List<FacesConfig> othersResources = new ArrayList<FacesConfig>();
920 List<OrderSlot> slots = webAppConfig.getAbsoluteOrdering().getOrderList();
921 for (FacesConfig resource : appConfigResources)
922 {
923
924
925
926
927 if ((resource.getName() == null) || (resource.getName() != null && !containsResourceInSlot(slots, resource.getName())))
928 {
929 othersResources.add(resource);
930 }
931 }
932
933 List<FacesConfig> sortedResources = new ArrayList<FacesConfig>();
934
935 for (OrderSlot slot : webAppConfig.getAbsoluteOrdering().getOrderList())
936 {
937 if (slot instanceof ConfigOthersSlotImpl)
938 {
939
940 for (FacesConfig resource : othersResources)
941 {
942 sortedResources.add(resource);
943 }
944 }
945 else
946 {
947
948 FacesConfigNameSlotImpl nameSlot = (FacesConfigNameSlotImpl) slot;
949 sortedResources.add(getFacesConfig(appConfigResources, nameSlot.getName()));
950 }
951 }
952
953 return sortedResources;
954 }
955
956 return null;
957 }
958
959 private FacesConfig getFacesConfig(List<FacesConfig> appConfigResources, String name)
960 {
961 for (FacesConfig cfg: appConfigResources)
962 {
963 if (cfg.getName() != null && name.equals(cfg.getName()))
964 {
965 return cfg;
966 }
967 }
968 return null;
969 }
970
971 private boolean containsResourceInSlot(List<OrderSlot> slots, String name)
972 {
973 for (OrderSlot slot: slots)
974 {
975 if (slot instanceof FacesConfigNameSlotImpl)
976 {
977 FacesConfigNameSlotImpl nameSlot = (FacesConfigNameSlotImpl) slot;
978 if (name.equals(nameSlot.getName()))
979 {
980 return true;
981 }
982 }
983 }
984 return false;
985 }
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605 }