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.

FlowNamedNotMappedTestCase.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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.events;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.util.Map;
  22. import javax.xml.transform.Source;
  23. import javax.xml.transform.Transformer;
  24. import javax.xml.transform.TransformerException;
  25. import javax.xml.transform.TransformerFactory;
  26. import javax.xml.transform.sax.SAXResult;
  27. import javax.xml.transform.stream.StreamSource;
  28. import org.junit.Test;
  29. import static org.junit.Assert.assertEquals;
  30. import static org.junit.Assert.assertTrue;
  31. import org.apache.commons.io.output.NullOutputStream;
  32. import org.apache.fop.apps.FOUserAgent;
  33. import org.apache.fop.apps.Fop;
  34. import org.apache.fop.apps.FopFactory;
  35. import org.apache.fop.apps.MimeConstants;
  36. import org.apache.fop.fo.FOValidationEventProducer;
  37. public class FlowNamedNotMappedTestCase {
  38. private static class FlowNameNotMappedEventChecker implements EventListener {
  39. private final String personalID = FOValidationEventProducer.class.getName() + ".flowNameNotMapped";
  40. public void processEvent(Event event) {
  41. Map<String, Object> t = event.getParams();
  42. assertEquals("fo:flow", event.getParam("elementName"));
  43. assertEquals("ContentPage_Body", event.getParam("flowName"));
  44. assertEquals(personalID, event.getEventID());
  45. }
  46. }
  47. @Test
  48. public void testFlowNamedNotMapped() throws Exception {
  49. FlowNameNotMappedEventChecker flowChecker;
  50. Fop fop;
  51. FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
  52. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  53. flowChecker = new FlowNameNotMappedEventChecker();
  54. userAgent.getEventBroadcaster().addEventListener(flowChecker);
  55. fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, new NullOutputStream());
  56. Source src = new StreamSource(new FileInputStream("test/events/flowNameNotMapped.fo"));
  57. SAXResult res = new SAXResult(fop.getDefaultHandler());
  58. Transformer transformer = TransformerFactory.newInstance().newTransformer();
  59. String expected = "on fo:flow could not be mapped to a region-name in the layout-master-set.";
  60. String test = "";
  61. try {
  62. transformer.transform(src, res);
  63. } catch (TransformerException te) {
  64. test = te.getLocalizedMessage();
  65. }
  66. assertTrue(test.contains(expected));
  67. }
  68. }