You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommonAccessibilityHolderTestCase.java 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.fo.properties;
  19. import java.lang.reflect.Constructor;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import org.junit.Test;
  23. import static org.junit.Assert.assertEquals;
  24. import static org.mockito.Mockito.mock;
  25. import static org.mockito.Mockito.when;
  26. import org.apache.fop.fo.Constants;
  27. import org.apache.fop.fo.FONode;
  28. import org.apache.fop.fo.FONodeMocks;
  29. import org.apache.fop.fo.PropertyList;
  30. import org.apache.fop.fo.expr.PropertyException;
  31. import org.apache.fop.fo.flow.table.UnimplementedWarningNeutralizer;
  32. /**
  33. * This tests that all the FONodes that implement CommonAccessibilityHolder correctly configure
  34. * the CommonAccessibility property.
  35. */
  36. public class CommonAccessibilityHolderTestCase {
  37. private static final List<Class<? extends CommonAccessibilityHolder>> IMPLEMENTATIONS
  38. = new ArrayList<Class<? extends CommonAccessibilityHolder>>();
  39. private final String role = "role";
  40. private final String sourceDocument = "source document";
  41. static {
  42. /* This triggers 'unimplemented feature' FO validation events so that the event system is
  43. * not triggered when testing, avoiding extra convoluted dependency stubbing. */
  44. UnimplementedWarningNeutralizer.neutralizeUnimplementedWarning();
  45. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.BasicLink.class);
  46. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Block.class);
  47. IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.bookmarks.Bookmark.class);
  48. IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.bookmarks.BookmarkTitle.class);
  49. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ExternalGraphic.class);
  50. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Footnote.class);
  51. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.FootnoteBody.class);
  52. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.InitialPropertySet.class);
  53. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Inline.class);
  54. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.InstreamForeignObject.class);
  55. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Leader.class);
  56. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListBlock.class);
  57. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListItem.class);
  58. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListItemBody.class);
  59. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListItemLabel.class);
  60. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.PageNumber.class);
  61. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.PageNumberCitation.class);
  62. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.PageNumberCitationLast.class);
  63. IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.Root.class);
  64. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.Table.class);
  65. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableAndCaption.class);
  66. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableBody.class);
  67. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableCaption.class);
  68. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableCell.class);
  69. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableFooter.class);
  70. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableHeader.class);
  71. IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableRow.class);
  72. IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.Title.class);
  73. }
  74. /**
  75. * Bind should be overridden to correctly configure the CommonAccessibility property
  76. * @throws Exception -
  77. */
  78. @Test
  79. public void bindMustSetRoleAndSourceDoc() throws Exception {
  80. final PropertyList mockPList = mockPropertyList();
  81. final FONode parent = FONodeMocks.mockFONode();
  82. for (Class<? extends CommonAccessibilityHolder> clazz : IMPLEMENTATIONS) {
  83. Constructor<? extends CommonAccessibilityHolder> constructor
  84. = clazz.getConstructor(FONode.class);
  85. CommonAccessibilityHolder sut = constructor.newInstance(parent);
  86. ((FONode)sut).bind(mockPList);
  87. String errorMessage = "Test failed for " + clazz + ": ";
  88. assertEquals(errorMessage, role, sut.getCommonAccessibility().getRole());
  89. assertEquals(errorMessage, sourceDocument,
  90. sut.getCommonAccessibility().getSourceDocument());
  91. }
  92. }
  93. private PropertyList mockPropertyList() throws PropertyException {
  94. final PropertyList mockPList = PropertyListMocks.mockPropertyList();
  95. PropertyListMocks.mockTableProperties(mockPList);
  96. PropertyListMocks.mockCommonBorderPaddingBackgroundProps(mockPList);
  97. mockRoleProperty(mockPList);
  98. mockSourceDocProperty(mockPList);
  99. return mockPList;
  100. }
  101. private void mockRoleProperty(PropertyList mockPList) throws PropertyException {
  102. final Property mockRoleProperty = mock(Property.class);
  103. when(mockRoleProperty.getString()).thenReturn(role);
  104. when(mockPList.get(Constants.PR_ROLE)).thenReturn(mockRoleProperty);
  105. }
  106. private void mockSourceDocProperty(PropertyList mockPList) throws PropertyException {
  107. final Property mockSourceDocProperty = mock(Property.class);
  108. when(mockSourceDocProperty.getString()).thenReturn(sourceDocument);
  109. when(mockPList.get(Constants.PR_SOURCE_DOCUMENT)).thenReturn(mockSourceDocProperty);
  110. }
  111. }