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.

TableLayoutManagerTestCase.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.layoutmgr.table;
  19. import java.util.HashMap;
  20. import org.junit.Test;
  21. import static org.junit.Assert.assertEquals;
  22. import static org.junit.Assert.assertNull;
  23. import static org.mockito.Mockito.mock;
  24. import static org.mockito.Mockito.never;
  25. import static org.mockito.Mockito.times;
  26. import static org.mockito.Mockito.verify;
  27. import static org.mockito.Mockito.when;
  28. import org.apache.fop.area.PageViewport;
  29. import org.apache.fop.fo.Constants;
  30. import org.apache.fop.fo.flow.Marker;
  31. import org.apache.fop.fo.flow.RetrieveTableMarker;
  32. import org.apache.fop.fo.flow.table.Table;
  33. import org.apache.fop.layoutmgr.BlockLayoutManager;
  34. import org.apache.fop.layoutmgr.Page;
  35. import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
  36. public class TableLayoutManagerTestCase {
  37. @Test
  38. public void testSavedTableCellLayoutManagersFunctionality() {
  39. Table t = mock(Table.class);
  40. TableCellLayoutManager tclm1 = mock(TableCellLayoutManager.class);
  41. TableLayoutManager tlm = new TableLayoutManager(t);
  42. tlm.saveTableHeaderTableCellLayoutManagers(tclm1);
  43. tlm.repeatAddAreasForSavedTableHeaderTableCellLayoutManagers();
  44. verify(tclm1).repeatAddAreas(); // called once
  45. // test that after the first repeatAddAreas() call the list closes to new additions
  46. TableCellLayoutManager tclm2 = mock(TableCellLayoutManager.class);
  47. tlm.saveTableHeaderTableCellLayoutManagers(tclm2);
  48. tlm.repeatAddAreasForSavedTableHeaderTableCellLayoutManagers();
  49. verify(tclm1, times(2)).repeatAddAreas(); // called twice
  50. verify(tclm2, never()).repeatAddAreas(); // never called
  51. }
  52. @Test
  53. public void testResolveRetrieveTableMarker() {
  54. // mock
  55. Table t = mock(Table.class);
  56. // mock
  57. Marker m = mock(Marker.class);
  58. // mock
  59. RetrieveTableMarker rtm = mock(RetrieveTableMarker.class);
  60. when(rtm.getRetrieveClassName()).thenReturn("A");
  61. when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_STARTING);
  62. // mock
  63. PageViewport pv = mock(PageViewport.class);
  64. when(pv.resolveMarker(rtm)).thenReturn(m);
  65. // mock
  66. Page p = mock(Page.class);
  67. when(p.getPageViewport()).thenReturn(pv);
  68. // mock
  69. PageSequenceLayoutManager pslm = mock(PageSequenceLayoutManager.class);
  70. when(pslm.getPSLM()).thenReturn(pslm);
  71. when(pslm.getCurrentPage()).thenReturn(p);
  72. // mock
  73. BlockLayoutManager blm = mock(BlockLayoutManager.class);
  74. blm.setParent(pslm);
  75. when(blm.getPSLM()).thenReturn(pslm);
  76. // real TLM, not mock
  77. TableLayoutManager tlm = new TableLayoutManager(t);
  78. tlm.setParent(blm);
  79. // register a marker
  80. HashMap<String, Marker> markers1 = new HashMap<String, Marker>();
  81. Marker m1 = mock(Marker.class);
  82. markers1.put("A", m1);
  83. tlm.registerMarkers(markers1, true, true, true);
  84. tlm.registerMarkers(markers1, false, true, true);
  85. // check that if there is a marker at table fragment level the RTM is returned
  86. assertEquals(rtm, tlm.resolveRetrieveTableMarker(rtm));
  87. verify(rtm, never()).getBoundary();
  88. // check that if there is no marker at table fragment level and that is the boundary
  89. // we get a null return value
  90. when(rtm.getBoundary()).thenReturn(Constants.EN_TABLE_FRAGMENT);
  91. when(rtm.getRetrieveClassName()).thenReturn("B");
  92. assertNull(tlm.resolveRetrieveTableMarker(rtm));
  93. verify(rtm).getBoundary();
  94. verify(rtm, never()).changePositionTo(Constants.EN_LAST_ENDING);
  95. // check that if there is no marker at table fragment level and the boundary is page
  96. // then we try to do the resolution at page level; test the case a marker is found
  97. when(rtm.getBoundary()).thenReturn(Constants.EN_PAGE);
  98. assertEquals(rtm, tlm.resolveRetrieveTableMarker(rtm));
  99. verify(rtm).changePositionTo(Constants.EN_LAST_ENDING);
  100. verify(rtm).changePositionTo(Constants.EN_FIRST_STARTING);
  101. verify(pv).resolveMarker(rtm);
  102. // test the same situation but in this case the marker is not found
  103. when(pv.resolveMarker(rtm)).thenReturn(null);
  104. assertNull(tlm.resolveRetrieveTableMarker(rtm));
  105. // test the situation where the marker is not found at page level but the boundary is table
  106. when(rtm.getBoundary()).thenReturn(Constants.EN_TABLE);
  107. assertNull(tlm.resolveRetrieveTableMarker(rtm));
  108. }
  109. }