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.

MissingLanguageWarningTestCase.java 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.accessibility.pdf;
  19. import java.io.File;
  20. import java.util.Arrays;
  21. import java.util.LinkedList;
  22. import javax.xml.transform.Source;
  23. import javax.xml.transform.Transformer;
  24. import javax.xml.transform.TransformerFactory;
  25. import javax.xml.transform.sax.SAXResult;
  26. import javax.xml.transform.stream.StreamSource;
  27. import org.junit.Before;
  28. import org.junit.Test;
  29. import static org.junit.Assert.assertEquals;
  30. import static org.junit.Assert.assertFalse;
  31. import static org.junit.Assert.assertTrue;
  32. import org.apache.commons.io.output.NullOutputStream;
  33. import org.apache.fop.apps.FOUserAgent;
  34. import org.apache.fop.apps.Fop;
  35. import org.apache.fop.apps.FopFactory;
  36. import org.apache.fop.apps.MimeConstants;
  37. import org.apache.fop.events.Event;
  38. import org.apache.fop.events.EventListener;
  39. import org.apache.fop.render.pdf.PDFEventProducer;
  40. public class MissingLanguageWarningTestCase {
  41. private Fop fop;
  42. private MissingLanguageEventChecker eventChecker;
  43. private static class MissingLanguageEventChecker implements EventListener {
  44. private final String unknownLanguageEventID = PDFEventProducer.class.getName() + ".unknownLanguage";
  45. private final LinkedList<String> expectedLocations = new LinkedList<String>(
  46. Arrays.asList("30:37", "34:40"));
  47. public void processEvent(Event event) {
  48. if (event.getEventID().equals(unknownLanguageEventID)) {
  49. assertFalse("Too many unknownLanguage events", expectedLocations.isEmpty());
  50. assertEquals(expectedLocations.removeFirst(), event.getParam("location"));
  51. }
  52. }
  53. void end() {
  54. assertTrue("Expected more unknownLanguage events", expectedLocations.isEmpty());
  55. }
  56. }
  57. @Before
  58. public void setUp() throws Exception {
  59. FopFactory fopFactory = FopFactory.newInstance(new File(".").toURI());
  60. FOUserAgent userAgent = fopFactory.newFOUserAgent();
  61. userAgent.setAccessibility(true);
  62. eventChecker = new MissingLanguageEventChecker();
  63. userAgent.getEventBroadcaster().addEventListener(eventChecker);
  64. fop = fopFactory.newFop(MimeConstants.MIME_PDF, userAgent, new NullOutputStream());
  65. }
  66. @Test
  67. public void testMissingLanguage() throws Exception {
  68. Source src = new StreamSource(getClass().getResourceAsStream("missing-language.fo"));
  69. SAXResult res = new SAXResult(fop.getDefaultHandler());
  70. Transformer transformer = TransformerFactory.newInstance().newTransformer();
  71. transformer.transform(src, res);
  72. eventChecker.end();
  73. }
  74. }