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.

TestXDGFVisioExtractor.java 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.xdgf.extractor;
  16. import static org.junit.Assert.assertEquals;
  17. import static org.junit.Assert.assertTrue;
  18. import static org.apache.poi.POITestCase.assertContains;
  19. import java.io.IOException;
  20. import java.io.InputStream;
  21. import org.apache.poi.POIDataSamples;
  22. import org.apache.poi.openxml4j.opc.OPCPackage;
  23. import org.apache.poi.xdgf.usermodel.XmlVisioDocument;
  24. import org.junit.After;
  25. import org.junit.Before;
  26. import org.junit.Ignore;
  27. import org.junit.Test;
  28. public class TestXDGFVisioExtractor {
  29. private static final POIDataSamples SAMPLES = POIDataSamples.getDiagramInstance();
  30. private OPCPackage pkg;
  31. private XmlVisioDocument xml;
  32. @Before
  33. public void setUp() throws Exception {
  34. pkg = OPCPackage.open(SAMPLES.openResourceAsStream("test_text_extraction.vsdx"));
  35. xml = new XmlVisioDocument(pkg);
  36. }
  37. @After
  38. public void closeResoures() throws IOException {
  39. xml.close();
  40. pkg.close();
  41. }
  42. @Test
  43. public void testGetSimpleText() throws IOException {
  44. new XDGFVisioExtractor(xml).close();
  45. new XDGFVisioExtractor(pkg).close();
  46. XDGFVisioExtractor extractor = new XDGFVisioExtractor(xml);
  47. extractor.getText();
  48. String text = extractor.getText();
  49. String expected = "Text here\nText there\nText, text, everywhere!\nRouter here\n";
  50. assertEquals(expected, text);
  51. extractor.close();
  52. }
  53. //the point of this is to trigger the addition of
  54. //some common visio classes -- ConnectsType
  55. @Test
  56. public void testVisioConnects() throws IOException {
  57. InputStream is = SAMPLES.openResourceAsStream("60489.vsdx");
  58. XmlVisioDocument document = new XmlVisioDocument(is);
  59. is.close();
  60. XDGFVisioExtractor extractor = new XDGFVisioExtractor(document);
  61. String text = extractor.getText();
  62. assertContains(text, "Arrears");
  63. extractor.close();
  64. }
  65. /**
  66. * Currently failing with:
  67. * org.apache.poi.POIXMLException: Invalid 'Row_Type' name 'PolylineTo'
  68. * at org.apache.poi.xdgf.util.ObjectFactory.load
  69. * at org.apache.poi.xdgf.usermodel.section.geometry.GeometryRowFactory.load
  70. */
  71. @Test
  72. @Ignore("TODO Fix bug #60973")
  73. public void testPolylineTo() throws IOException {
  74. InputStream is = SAMPLES.openResourceAsStream("60973.vsdx");
  75. XmlVisioDocument document = new XmlVisioDocument(is);
  76. is.close();
  77. XDGFVisioExtractor extractor = new XDGFVisioExtractor(document);
  78. String text = extractor.getText();
  79. assertContains(text, "42 U");
  80. assertContains(text, "Access VLANS");
  81. extractor.close();
  82. }
  83. }