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.

MarkersTestCase.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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.flow;
  19. import java.util.HashMap;
  20. import java.util.Map;
  21. import org.junit.Test;
  22. import static org.junit.Assert.assertEquals;
  23. import static org.junit.Assert.fail;
  24. import static org.mockito.Mockito.mock;
  25. import static org.mockito.Mockito.when;
  26. import org.apache.fop.fo.Constants;
  27. public class MarkersTestCase {
  28. @Test
  29. public void testRegisterAndResolve() {
  30. // consider 3 regions, and a boundary; the first region starts before the boundary and ends inside
  31. // the boundary, the second region is fully inside the boundary, and the third region starts inside
  32. // the boundary and ends after the boundary. in every region there are 2 markers, A and B.
  33. // ======== region 1
  34. Map<String, Marker> markers_region_1 = new HashMap<String, Marker>();
  35. Marker marker_1A = mock(Marker.class);
  36. Marker marker_1B = mock(Marker.class);
  37. markers_region_1.put("A", marker_1A);
  38. markers_region_1.put("B", marker_1B);
  39. // ======== region 2
  40. Map<String, Marker> markers_region_2 = new HashMap<String, Marker>();
  41. Marker marker_2A = mock(Marker.class);
  42. Marker marker_2B = mock(Marker.class);
  43. markers_region_2.put("A", marker_2A);
  44. markers_region_2.put("B", marker_2B);
  45. // ======== region 3
  46. Map<String, Marker> markers_region_3 = new HashMap<String, Marker>();
  47. Marker marker_3A = mock(Marker.class);
  48. Marker marker_3B = mock(Marker.class);
  49. markers_region_3.put("A", marker_3A);
  50. markers_region_3.put("B", marker_3B);
  51. // instantiate markers for the boundary
  52. Markers markers = new Markers();
  53. // register the markers for the different regions
  54. // region 1
  55. markers.register(markers_region_1, true, false, true);
  56. markers.register(markers_region_1, false, false, true);
  57. // region 2
  58. markers.register(markers_region_2, true, true, true);
  59. markers.register(markers_region_2, false, true, true);
  60. // region 3
  61. markers.register(markers_region_3, true, true, false);
  62. markers.register(markers_region_3, false, true, false);
  63. // now prepare a RetrieveMarker
  64. RetrieveMarker rm = mock(RetrieveMarker.class);
  65. when(rm.getRetrieveClassName()).thenReturn("A");
  66. when(rm.getLocalName()).thenReturn("retrieve-marker");
  67. when(rm.getPositionLabel()).thenReturn("position-label"); // not relevant for the test
  68. // and resolve the marker for different positions
  69. // EN_FSWP
  70. when(rm.getPosition()).thenReturn(Constants.EN_FSWP);
  71. // expect marker_2A
  72. assertEquals(marker_2A, markers.resolve(rm));
  73. // EN_LSWP
  74. when(rm.getPosition()).thenReturn(Constants.EN_LSWP);
  75. // expect marker_3A
  76. assertEquals(marker_3A, markers.resolve(rm));
  77. // EN_LEWP
  78. when(rm.getPosition()).thenReturn(Constants.EN_LEWP);
  79. // expect marker_2A
  80. assertEquals(marker_2A, markers.resolve(rm));
  81. // EN_FIC
  82. when(rm.getPosition()).thenReturn(Constants.EN_FIC);
  83. // expect marker_1A
  84. assertEquals(marker_1A, markers.resolve(rm));
  85. // now prepare a RetrieveTableMarker
  86. RetrieveTableMarker rtm = mock(RetrieveTableMarker.class);
  87. when(rtm.getRetrieveClassName()).thenReturn("B");
  88. when(rtm.getLocalName()).thenReturn("retrieve-table-marker");
  89. when(rtm.getPositionLabel()).thenReturn("position-label"); // not relevant for the test
  90. // and resolve the marker for different positions
  91. // EN_FIRST_STARTING
  92. when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_STARTING);
  93. // expect marker_2B
  94. assertEquals(marker_2B, markers.resolve(rtm));
  95. // EN_LAST_STARTING
  96. when(rtm.getPosition()).thenReturn(Constants.EN_LAST_STARTING);
  97. // expect marker_3B
  98. assertEquals(marker_3B, markers.resolve(rtm));
  99. // EN_LAST_ENDING
  100. when(rtm.getPosition()).thenReturn(Constants.EN_LAST_ENDING);
  101. // expect marker_2B
  102. assertEquals(marker_2B, markers.resolve(rtm));
  103. // EN_FIRST_INCLUDING_CARRYOVER
  104. when(rtm.getPosition()).thenReturn(Constants.EN_FIRST_INCLUDING_CARRYOVER);
  105. // expect marker_1B
  106. assertEquals(marker_1B, markers.resolve(rtm));
  107. // test also an invalid position
  108. when(rm.getPosition()).thenReturn(Constants.EN_ABSOLUTE);
  109. try {
  110. Marker m = markers.resolve(rm);
  111. fail("Expected an exception... instead got:" + m.toString());
  112. } catch (RuntimeException re) {
  113. // do nothing
  114. }
  115. }
  116. }