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.

PageSequenceLayoutManagerTestCase.java 4.0KB

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;
  19. import org.junit.Test;
  20. import static org.junit.Assert.assertEquals;
  21. import static org.mockito.Matchers.anyInt;
  22. import static org.mockito.Mockito.mock;
  23. import static org.mockito.Mockito.when;
  24. import org.apache.fop.area.AreaTreeHandler;
  25. import org.apache.fop.area.PageViewport;
  26. import org.apache.fop.fo.pagination.Flow;
  27. import org.apache.fop.fo.pagination.PageSequence;
  28. import org.apache.fop.fo.pagination.Region;
  29. import org.apache.fop.fo.pagination.Root;
  30. import org.apache.fop.fo.pagination.SimplePageMaster;
  31. public class PageSequenceLayoutManagerTestCase {
  32. private static final String MAIN_FLOW_NAME = "main";
  33. private static final String EMPTY_FLOW_NAME = "empty";
  34. /**
  35. * Blank pages can be created from empty pages
  36. *
  37. * @throws Exception
  38. */
  39. @Test
  40. public void testGetNextPageBlank() throws Exception {
  41. final Page expectedPage = createPageForRegionName(EMPTY_FLOW_NAME);
  42. final Page[] providedPages = new Page[]{expectedPage};
  43. testGetNextPage(providedPages, expectedPage, true);
  44. }
  45. /**
  46. * Empty pages should not be provided by the PageSequenceLayoutManager
  47. * to layout the main flow
  48. *
  49. * @throws Exception
  50. */
  51. @Test
  52. public void testGetNextPageFirstEmpty() throws Exception {
  53. final Page emptyPage = createPageForRegionName(EMPTY_FLOW_NAME);
  54. final Page expectedPage = createPageForRegionName(MAIN_FLOW_NAME);
  55. final Page[] providedPages = new Page[]{emptyPage, expectedPage};
  56. testGetNextPage(providedPages, expectedPage, false);
  57. }
  58. private void testGetNextPage(final Page[] providedPages, Page expectedPage, boolean isBlank) {
  59. final Flow flow = mock(Flow.class);
  60. final PageSequence pseq = mock(PageSequence.class);
  61. final Root root = mock(Root.class);
  62. final AreaTreeHandler ath = mock(AreaTreeHandler.class);
  63. when(flow.getFlowName()).thenReturn(MAIN_FLOW_NAME);
  64. when(pseq.getMainFlow()).thenReturn(flow);
  65. when(pseq.getRoot()).thenReturn(root);
  66. PageSequenceLayoutManager sut = new PageSequenceLayoutManager(ath, pseq) {
  67. @Override
  68. protected Page createPage(int i, boolean b) {
  69. return providedPages[i - 1];
  70. }
  71. @Override
  72. protected void finishPage() {
  73. //nop
  74. }
  75. // Expose the protected method for testing
  76. public Page makeNewPage(boolean isBlank) {
  77. return super.makeNewPage(isBlank);
  78. }
  79. };
  80. assertEquals(expectedPage, sut.makeNewPage(isBlank));
  81. }
  82. private static Page createPageForRegionName(final String regionName) {
  83. final Page page = mock(Page.class);
  84. final SimplePageMaster spm = mock(SimplePageMaster.class);
  85. final PageViewport pageViewport = mock(PageViewport.class);
  86. final Region region = mock(Region.class);
  87. when(page.getSimplePageMaster()).thenReturn(spm);
  88. when(page.getPageViewport()).thenReturn(pageViewport);
  89. when(spm.getRegion(anyInt())).thenReturn(region);
  90. when(region.getRegionName()).thenReturn(regionName);
  91. return page;
  92. }
  93. }