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 18 /* $Id: CommonAccessibilityHolderTestCase.java 1551536 2013-12-17 13:15:06Z vhennebert $ */ 19 20 package org.apache.fop.fo.properties; 21 22 import java.lang.reflect.Constructor; 23 import java.util.ArrayList; 24 import java.util.List; 25 26 import org.junit.Test; 27 28 import static org.junit.Assert.assertEquals; 29 import static org.mockito.Mockito.mock; 30 import static org.mockito.Mockito.when; 31 32 import org.apache.fop.fo.Constants; 33 import org.apache.fop.fo.FONode; 34 import org.apache.fop.fo.FONodeMocks; 35 import org.apache.fop.fo.PropertyList; 36 import org.apache.fop.fo.expr.PropertyException; 37 import org.apache.fop.fo.flow.table.UnimplementedWarningNeutralizer; 38 39 /** 40 * This tests that all the FONodes that implement CommonAccessibilityHolder correctly configure 41 * the CommonAccessibility property. 42 */ 43 public class CommonAccessibilityHolderTestCase { 44 45 private static final List<Class<? extends CommonAccessibilityHolder>> IMPLEMENTATIONS 46 = new ArrayList<Class<? extends CommonAccessibilityHolder>>(); 47 48 private final String role = "role"; 49 50 private final String sourceDocument = "source document"; 51 52 static { 53 /* This triggers 'unimplemented feature' FO validation events so that the event system is 54 * not triggered when testing, avoiding extra convoluted dependency stubbing. */ UnimplementedWarningNeutralizer.neutralizeUnimplementedWarning()55 UnimplementedWarningNeutralizer.neutralizeUnimplementedWarning(); 56 57 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.BasicLink.class); 58 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Block.class); 59 IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.bookmarks.Bookmark.class); 60 IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.bookmarks.BookmarkTitle.class); 61 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ExternalGraphic.class); 62 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Footnote.class); 63 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.FootnoteBody.class); 64 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.InitialPropertySet.class); 65 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Inline.class); 66 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.InstreamForeignObject.class); 67 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.Leader.class); 68 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListBlock.class); 69 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListItem.class); 70 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListItemBody.class); 71 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.ListItemLabel.class); 72 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.PageNumber.class); 73 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.PageNumberCitation.class); 74 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.PageNumberCitationLast.class); 75 IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.Root.class); 76 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.Table.class); 77 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableAndCaption.class); 78 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableBody.class); 79 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableCaption.class); 80 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableCell.class); 81 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableFooter.class); 82 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableHeader.class); 83 IMPLEMENTATIONS.add(org.apache.fop.fo.flow.table.TableRow.class); 84 IMPLEMENTATIONS.add(org.apache.fop.fo.pagination.Title.class); 85 } 86 87 /** 88 * Bind should be overridden to correctly configure the CommonAccessibility property 89 * @throws Exception - 90 */ 91 @Test bindMustSetRoleAndSourceDoc()92 public void bindMustSetRoleAndSourceDoc() throws Exception { 93 final PropertyList mockPList = mockPropertyList(); 94 final FONode parent = FONodeMocks.mockFONode(); 95 for (Class<? extends CommonAccessibilityHolder> clazz : IMPLEMENTATIONS) { 96 Constructor<? extends CommonAccessibilityHolder> constructor 97 = clazz.getConstructor(FONode.class); 98 CommonAccessibilityHolder sut = constructor.newInstance(parent); 99 ((FONode)sut).bind(mockPList); 100 String errorMessage = "Test failed for " + clazz + ": "; 101 assertEquals(errorMessage, role, sut.getCommonAccessibility().getRole()); 102 assertEquals(errorMessage, sourceDocument, 103 sut.getCommonAccessibility().getSourceDocument()); 104 } 105 } 106 mockPropertyList()107 private PropertyList mockPropertyList() throws PropertyException { 108 final PropertyList mockPList = PropertyListMocks.mockPropertyList(); 109 PropertyListMocks.mockTableProperties(mockPList); 110 PropertyListMocks.mockCommonBorderPaddingBackgroundProps(mockPList); 111 mockRoleProperty(mockPList); 112 mockSourceDocProperty(mockPList); 113 return mockPList; 114 } 115 mockRoleProperty(PropertyList mockPList)116 private void mockRoleProperty(PropertyList mockPList) throws PropertyException { 117 final Property mockRoleProperty = mock(Property.class); 118 when(mockRoleProperty.getString()).thenReturn(role); 119 when(mockPList.get(Constants.PR_ROLE)).thenReturn(mockRoleProperty); 120 } 121 mockSourceDocProperty(PropertyList mockPList)122 private void mockSourceDocProperty(PropertyList mockPList) throws PropertyException { 123 final Property mockSourceDocProperty = mock(Property.class); 124 when(mockSourceDocProperty.getString()).thenReturn(sourceDocument); 125 when(mockPList.get(Constants.PR_SOURCE_DOCUMENT)).thenReturn(mockSourceDocProperty); 126 } 127 128 } 129