1 package org.apache.maven.doxia.sink;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.CharArrayWriter;
23 import java.io.IOException;
24 import java.io.Writer;
25
26 import org.apache.maven.doxia.AbstractModuleTest;
27 import org.apache.maven.doxia.logging.PlexusLoggerWrapper;
28 import org.codehaus.plexus.util.IOUtil;
29
30
31
32
33
34
35
36 public abstract class AbstractSinkTest
37 extends AbstractModuleTest
38 {
39 private final CharArrayWriter testWriter = new CharArrayWriter();
40 private Sink sink;
41
42
43
44
45
46
47
48
49 @Override
50 protected void setUp()
51 throws Exception
52 {
53 super.setUp();
54
55 testWriter.reset();
56 sink = createSink( testWriter );
57 sink.enableLogging( new PlexusLoggerWrapper( getContainer().getLogger() ) );
58 }
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75 public final void testTestDocument() throws IOException
76 {
77 Writer writer = ( isXmlSink() ? getXmlTestWriter( "testDocument" ) : getTestWriter( "testDocument" ) );
78 Sink testSink = createSink( writer );
79
80 try
81 {
82 SinkTestDocument.generate( testSink );
83 }
84 finally
85 {
86 testSink.close();
87 IOUtil.close( writer );
88 }
89 }
90
91
92
93
94
95
96 public void testTitle()
97 {
98 String title = "Grodek";
99 sink.title();
100 sink.text( title );
101 sink.title_();
102 sink.flush();
103 sink.close();
104
105 String actual = testWriter.toString();
106 String expected = getTitleBlock( title );
107
108 assertEquals( "Wrong title!", expected, actual );
109 }
110
111
112
113
114
115
116 public void testAuthor()
117 {
118 String author = "Georg_Trakl";
119 sink.author();
120 sink.text( author );
121 sink.author_();
122 sink.flush();
123 sink.close();
124
125 String actual = testWriter.toString();
126 String expected = getAuthorBlock( author );
127
128 assertEquals( "Wrong author!", expected, actual );
129 }
130
131
132
133
134
135
136 public void testDate()
137 {
138 String date = "1914";
139 sink.date();
140 sink.text( date );
141 sink.date_();
142 sink.flush();
143 sink.close();
144
145 String actual = testWriter.toString();
146 String expected = getDateBlock( date );
147
148 assertEquals( "Wrong date!", expected, actual );
149 }
150
151
152
153
154
155
156 public void testHead()
157 {
158 sink.head();
159 sink.head_();
160 sink.flush();
161 sink.close();
162
163 String actual = testWriter.toString();
164 String expected = getHeadBlock();
165
166 assertEquals( "Wrong head!", expected, actual );
167 }
168
169
170
171
172
173
174 public void testBody()
175 {
176 sink.body();
177 sink.body_();
178 sink.flush();
179 sink.close();
180
181 String actual = testWriter.toString();
182 String expected = getBodyBlock();
183
184 assertEquals( "Wrong body!", expected, actual );
185 }
186
187
188
189
190
191
192
193 public void testSectionTitle()
194 {
195 String title = "Title";
196 sink.sectionTitle();
197 sink.text( title );
198 sink.sectionTitle_();
199 sink.flush();
200 sink.close();
201
202 String actual = testWriter.toString();
203 String expected = getSectionTitleBlock( title );
204
205 assertEquals( "Wrong sectionTitle!", expected, actual );
206 }
207
208
209
210
211
212
213
214 public void testSection1()
215 {
216 String title = "Title1";
217 sink.section1();
218 sink.sectionTitle1();
219 sink.text( title );
220 sink.sectionTitle1_();
221 sink.section1_();
222 sink.flush();
223 sink.close();
224
225 String actual = testWriter.toString();
226 String expected = getSection1Block( title );
227
228 assertEquals( "Wrong section1 block!", expected, actual );
229 }
230
231
232
233
234
235
236
237 public void testSection2()
238 {
239 String title = "Title2";
240 sink.section2();
241 sink.sectionTitle2();
242 sink.text( title );
243 sink.sectionTitle2_();
244 sink.section2_();
245 sink.flush();
246 sink.close();
247
248 String actual = testWriter.toString();
249 String expected = getSection2Block( title );
250
251 assertEquals( "Wrong section2 block!", expected, actual );
252 }
253
254
255
256
257
258
259
260 public void testSection3()
261 {
262 String title = "Title3";
263 sink.section3();
264 sink.sectionTitle3();
265 sink.text( title );
266 sink.sectionTitle3_();
267 sink.section3_();
268 sink.flush();
269 sink.close();
270
271 String actual = testWriter.toString();
272 String expected = getSection3Block( title );
273
274 assertEquals( "Wrong section3 block!", expected, actual );
275 }
276
277
278
279
280
281
282
283
284 public void testSection4()
285 {
286 String title = "Title4";
287 sink.section4();
288 sink.sectionTitle4();
289 sink.text( title );
290 sink.sectionTitle4_();
291 sink.section4_();
292 sink.flush();
293 sink.close();
294
295 String actual = testWriter.toString();
296 String expected = getSection4Block( title );
297
298 assertEquals( "Wrong section4 block!", expected, actual );
299 }
300
301
302
303
304
305
306
307 public void testSection5()
308 {
309 String title = "Title5";
310 sink.section5();
311 sink.sectionTitle5();
312 sink.text( title );
313 sink.sectionTitle5_();
314 sink.section5_();
315 sink.flush();
316 sink.close();
317
318 String actual = testWriter.toString();
319 String expected = getSection5Block( title );
320
321 assertEquals( "Wrong section5 block!", expected, actual );
322 }
323
324
325
326
327
328
329
330 public void testList()
331 {
332 String item = "list_item";
333 sink.list();
334 sink.listItem();
335 sink.text( item );
336 sink.listItem_();
337 sink.list_();
338 sink.flush();
339 sink.close();
340
341 String actual = testWriter.toString();
342 String expected = getListBlock( item );
343
344 assertEquals( "Wrong list!", expected, actual );
345 }
346
347
348
349
350
351
352
353
354 public void testNumberedList()
355 {
356 String item = "numbered_list_item";
357 sink.numberedList( Sink.NUMBERING_LOWER_ROMAN );
358 sink.numberedListItem();
359 sink.text( item );
360 sink.numberedListItem_();
361 sink.numberedList_();
362 sink.flush();
363 sink.close();
364
365 String actual = testWriter.toString();
366 String expected = getNumberedListBlock( item );
367
368 assertEquals( "Wrong numbered list!", expected, actual );
369 }
370
371
372
373
374
375
376
377
378
379 public void testDefinitionList()
380 {
381 String definum = "definum";
382 String definition = "definition";
383 sink.definitionList();
384 sink.definitionListItem();
385 sink.definedTerm();
386 sink.text( definum );
387 sink.definedTerm_();
388 sink.definition();
389 sink.text( definition );
390 sink.definition_();
391 sink.definitionListItem_();
392 sink.definitionList_();
393 sink.flush();
394 sink.close();
395
396 String actual = testWriter.toString();
397 String expected = getDefinitionListBlock( definum, definition );
398
399 assertEquals( "Wrong definition list!", expected, actual );
400 }
401
402
403
404
405
406
407
408 public void testFigure()
409 {
410 String source = "figure.jpg";
411 String caption = "Figure_caption";
412 sink.figure();
413 sink.figureGraphics( source );
414 sink.figureCaption();
415 sink.text( caption );
416 sink.figureCaption_();
417 sink.figure_();
418 sink.flush();
419 sink.close();
420
421 String actual = testWriter.toString();
422 String expected = getFigureBlock( source, caption );
423
424 assertEquals( "Wrong figure!", expected, actual );
425 }
426
427
428 public void testFigureWithoutCaption()
429 {
430 String source = "figure.jpg";
431 sink.figure();
432 sink.figureGraphics( source );
433 sink.figure_();
434 sink.flush();
435 sink.close();
436
437 String actual = testWriter.toString();
438 String expected = getFigureBlock( source, null );
439
440 assertEquals( "Wrong figure!", expected, actual );
441
442 }
443
444
445
446
447
448
449
450
451
452 public void testTable()
453 {
454 String cell = "cell";
455 String caption = "Table_caption";
456 int[] justify = { Sink.JUSTIFY_CENTER };
457 sink.table();
458 sink.tableRows( justify, false );
459 sink.tableRow();
460 sink.tableCell();
461 sink.text( cell );
462 sink.tableCell_();
463 sink.tableRow_();
464 sink.tableRows_();
465 sink.tableCaption();
466 sink.text( caption );
467 sink.tableCaption_();
468 sink.table_();
469 sink.flush();
470 sink.close();
471
472 String actual = testWriter.toString();
473 String expected = getTableBlock( cell, caption );
474
475 assertEquals( "Wrong table!", expected, actual );
476 }
477
478
479
480
481
482
483 public void testParagraph()
484 {
485 String text = "Text";
486 sink.paragraph();
487 sink.text( text );
488 sink.paragraph_();
489 sink.flush();
490 sink.close();
491
492 String actual = testWriter.toString();
493 String expected = getParagraphBlock( text );
494
495 assertEquals( "Wrong paragraph!", expected, actual );
496 }
497
498
499
500
501
502
503 public void testVerbatim()
504 {
505 String text = "Text";
506 sink.verbatim( SinkEventAttributeSet.BOXED );
507 sink.text( text );
508 sink.verbatim_();
509 sink.flush();
510 sink.close();
511
512 String actual = testWriter.toString();
513 String expected = getVerbatimBlock( text );
514
515 assertEquals( "Wrong verbatim!", expected, actual );
516 }
517
518
519
520
521
522
523 public void testHorizontalRule()
524 {
525 sink.horizontalRule();
526 sink.flush();
527 sink.close();
528
529 String actual = testWriter.toString();
530 String expected = getHorizontalRuleBlock();
531
532 assertEquals( "Wrong horizontal rule!", expected, actual );
533 }
534
535
536
537
538
539
540 public void testPageBreak()
541 {
542 sink.pageBreak();
543 sink.flush();
544 sink.close();
545
546 String actual = testWriter.toString();
547 String expected = getPageBreakBlock();
548
549 assertEquals( "Wrong pageBreak!", expected, actual );
550 }
551
552
553
554
555
556
557 public void testAnchor()
558 {
559 String anchor = "Anchor";
560 sink.anchor( anchor );
561 sink.text( anchor );
562 sink.anchor_();
563 sink.flush();
564 sink.close();
565
566 String actual = testWriter.toString();
567 String expected = getAnchorBlock( anchor );
568
569 assertEquals( "Wrong anchor!", expected, actual );
570 }
571
572
573
574
575
576
577 public void testLink()
578 {
579 String link = "#Link";
580 String text = "Text";
581 sink.link( link );
582 sink.text( text );
583 sink.link_();
584 sink.flush();
585 sink.close();
586
587 String actual = testWriter.toString();
588 String expected = getLinkBlock( link, text );
589
590 assertEquals( "Wrong link!", expected, actual );
591 }
592
593
594
595
596
597
598 public void testItalic()
599 {
600 String text = "Italic";
601 sink.italic();
602 sink.text( text );
603 sink.italic_();
604 sink.flush();
605 sink.close();
606
607 String actual = testWriter.toString();
608 String expected = getItalicBlock( text );
609
610 assertEquals( "Wrong italic!", expected, actual );
611 }
612
613
614
615
616
617
618 public void testBold()
619 {
620 String text = "Bold";
621 sink.bold();
622 sink.text( text );
623 sink.bold_();
624 sink.flush();
625 sink.close();
626
627 String actual = testWriter.toString();
628 String expected = getBoldBlock( text );
629
630 assertEquals( "Wrong bold!", expected, actual );
631 }
632
633
634
635
636
637
638 public void testMonospaced()
639 {
640 String text = "Monospaced";
641 sink.monospaced();
642 sink.text( text );
643 sink.monospaced_();
644 sink.flush();
645 sink.close();
646
647 String actual = testWriter.toString();
648 String expected = getMonospacedBlock( text );
649
650 assertEquals( "Wrong monospaced!", expected, actual );
651 }
652
653
654
655
656
657
658 public void testLineBreak()
659 {
660 sink.lineBreak();
661 sink.flush();
662 sink.close();
663
664 String actual = testWriter.toString();
665 String expected = getLineBreakBlock();
666
667 assertEquals( "Wrong lineBreak!", expected, actual );
668 }
669
670
671
672
673
674
675 public void testNonBreakingSpace()
676 {
677 sink.nonBreakingSpace();
678 sink.flush();
679 sink.close();
680
681 String actual = testWriter.toString();
682 String expected = getNonBreakingSpaceBlock();
683
684 assertEquals( "Wrong nonBreakingSpace!", expected, actual );
685 }
686
687
688
689
690
691
692 public void testText()
693 {
694 String text = "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
695 sink.text( text );
696 sink.flush();
697 sink.close();
698
699 String actual = testWriter.toString();
700 String expected = getTextBlock( text );
701
702 assertEquals( "Wrong text!", expected, actual );
703 }
704
705
706
707
708
709
710 public void testRawText()
711 {
712 String text = "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\";
713 sink.rawText( text );
714 sink.flush();
715 sink.close();
716
717 String actual = testWriter.toString();
718 String expected = getRawTextBlock( text );
719
720 assertEquals( "Wrong rawText!", expected, actual );
721 }
722
723
724
725
726
727
728
729 public void testComment()
730 {
731 String comment = "Simple comment with ----";
732 sink.comment( comment );
733 sink.flush();
734 sink.close();
735
736 String actual = testWriter.toString();
737 String expected = getCommentBlock( comment );
738
739 assertEquals( "Wrong comment!", expected, actual );
740 }
741
742
743
744
745
746
747
748
749
750 protected Sink getSink()
751 {
752 return sink;
753 }
754
755
756
757
758
759 protected String getSinkContent()
760 {
761 return testWriter.toString();
762 }
763
764
765
766
767
768 protected String getOutputDir()
769 {
770 return "sink/";
771 }
772
773
774
775
776
777
778
779
780
781
782
783 protected abstract boolean isXmlSink();
784
785
786
787
788
789
790 protected abstract Sink createSink( Writer writer );
791
792
793
794
795
796
797
798 protected abstract String getTitleBlock( String title );
799
800
801
802
803
804
805
806 protected abstract String getAuthorBlock( String author );
807
808
809
810
811
812
813
814 protected abstract String getDateBlock( String date );
815
816
817
818
819
820
821 protected abstract String getHeadBlock();
822
823
824
825
826
827
828 protected abstract String getBodyBlock();
829
830
831
832
833
834
835
836 protected abstract String getSectionTitleBlock( String title );
837
838
839
840
841
842
843
844 protected abstract String getSection1Block( String title );
845
846
847
848
849
850
851
852 protected abstract String getSection2Block( String title );
853
854
855
856
857
858
859
860 protected abstract String getSection3Block( String title );
861
862
863
864
865
866
867
868 protected abstract String getSection4Block( String title );
869
870
871
872
873
874
875
876 protected abstract String getSection5Block( String title );
877
878
879
880
881
882
883
884 protected abstract String getListBlock( String item );
885
886
887
888
889
890
891
892 protected abstract String getNumberedListBlock( String item );
893
894
895
896
897
898
899
900
901 protected abstract String getDefinitionListBlock( String definum,
902 String definition );
903
904
905
906
907
908
909
910
911 protected abstract String getFigureBlock( String source, String caption );
912
913
914
915
916
917
918
919
920 protected abstract String getTableBlock( String cell, String caption );
921
922
923
924
925
926
927
928 protected abstract String getParagraphBlock( String text );
929
930
931
932
933
934
935
936 protected abstract String getVerbatimBlock( String text );
937
938
939
940
941
942
943 protected abstract String getHorizontalRuleBlock();
944
945
946
947
948
949
950 protected abstract String getPageBreakBlock();
951
952
953
954
955
956
957
958 protected abstract String getAnchorBlock( String anchor );
959
960
961
962
963
964
965
966
967 protected abstract String getLinkBlock( String link, String text );
968
969
970
971
972
973
974
975 protected abstract String getItalicBlock( String text );
976
977
978
979
980
981
982
983 protected abstract String getBoldBlock( String text );
984
985
986
987
988
989
990
991 protected abstract String getMonospacedBlock( String text );
992
993
994
995
996
997
998 protected abstract String getLineBreakBlock();
999
1000
1001
1002
1003
1004
1005
1006 protected abstract String getNonBreakingSpaceBlock();
1007
1008
1009
1010
1011
1012
1013
1014 protected abstract String getTextBlock( String text );
1015
1016
1017
1018
1019
1020
1021
1022 protected abstract String getRawTextBlock( String text );
1023
1024
1025
1026
1027
1028
1029
1030
1031 protected abstract String getCommentBlock( String text );
1032
1033 protected final void verifyValignSup( String text )
1034 {
1035 sink.text( "ValignSup", new SinkEventAttributeSet( SinkEventAttributes.VALIGN, "sup" ) );
1036 sink.flush();
1037 sink.close();
1038
1039 String actual = testWriter.toString();
1040
1041 assertEquals( "Wrong valign sup!", text, actual );
1042 }
1043
1044 protected final void verifyValignSub( String text )
1045 {
1046 sink.text( "ValignSub", new SinkEventAttributeSet( SinkEventAttributes.VALIGN, "sub" ) );
1047 sink.flush();
1048 sink.close();
1049
1050 String actual = testWriter.toString();
1051
1052 assertEquals( "Wrong valign sub!", text, actual );
1053 }
1054
1055 protected final void verifyDecorationUnderline( String text )
1056 {
1057 sink.text( "DecorationUnderline", new SinkEventAttributeSet( SinkEventAttributes.DECORATION, "underline" ) );
1058 sink.flush();
1059 sink.close();
1060
1061 String actual = testWriter.toString();
1062
1063 assertEquals( "Wrong decoration underline!", text, actual );
1064 }
1065
1066 protected final void verifyDecorationLineThrough( String text )
1067 {
1068 sink.text( "DecorationLineThrough", new SinkEventAttributeSet( SinkEventAttributes.DECORATION, "line-through" ) );
1069 sink.flush();
1070 sink.close();
1071
1072 String actual = testWriter.toString();
1073
1074 assertEquals( "Wrong decoration line-through!", text, actual );
1075 }
1076
1077
1078 }