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.

IFTestCase.java 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.intermediate;
  19. import java.io.File;
  20. import java.io.FilenameFilter;
  21. import java.io.IOException;
  22. import java.io.OutputStream;
  23. import java.util.ArrayList;
  24. import java.util.Collection;
  25. import javax.xml.transform.Source;
  26. import javax.xml.transform.TransformerFactory;
  27. import org.junit.BeforeClass;
  28. import org.junit.Test;
  29. import org.junit.runner.RunWith;
  30. import org.junit.runners.Parameterized;
  31. import org.junit.runners.Parameterized.Parameters;
  32. import org.w3c.dom.Document;
  33. import org.w3c.dom.Element;
  34. import org.w3c.dom.NodeList;
  35. /**
  36. * Test case for the IF output.
  37. */
  38. @RunWith(Parameterized.class)
  39. public class IFTestCase extends AbstractIFTest {
  40. /**
  41. * Gets the files for this test.
  42. *
  43. * @return a collection of file arrays containing the files to test
  44. * @throws IOException if an error occurs when reading the test files
  45. */
  46. @Parameters
  47. public static Collection<File[]> getParameters() throws IOException {
  48. File testDir = new File("test/intermediate");
  49. String[] tests = testDir.list(new FilenameFilter() {
  50. public boolean accept(File dir, String name) {
  51. return name.endsWith(".xml");
  52. }
  53. });
  54. Collection<File[]> parameters = new ArrayList<File[]>();
  55. for (String test : tests) {
  56. parameters.add(new File[] { new File(testDir, test) });
  57. }
  58. return parameters;
  59. }
  60. private static IFTester ifTester;
  61. @BeforeClass
  62. public static void setupTestEnvironment() {
  63. File backupDir = new File("build/test-results/intermediate");
  64. backupDir.mkdirs();
  65. ifTester = new IFTester(TransformerFactory.newInstance(), backupDir);
  66. }
  67. /**
  68. * Creates a new test case.
  69. *
  70. * @param test the file containing the test case
  71. * @param ifTester the helper instance that will perform checks
  72. * @throws IOException if an I/O error occurs while loading the test case
  73. */
  74. public IFTestCase(File test) throws IOException {
  75. super(test);
  76. this.testDir = test.getParentFile();
  77. }
  78. @Override
  79. @Test
  80. public void runTest() throws Exception {
  81. Element testRoot = testAssistant.getTestRoot(testFile);
  82. NodeList nodes = testRoot.getElementsByTagName("if-checks");
  83. if (nodes.getLength() == 0) {
  84. throw new RuntimeException("No IF check found");
  85. }
  86. Element ifChecks = (Element) nodes.item(0);
  87. Document doc = buildIntermediateDocument(testAssistant.getTestcase2FOStylesheet());
  88. ifTester.doIFChecks(testFile.getName(), ifChecks, doc);
  89. }
  90. @Override
  91. protected void parseAndRender(Source src, OutputStream out) throws Exception {
  92. throw new IllegalStateException("Not applicable to this test");
  93. }
  94. @Override
  95. protected Document parseAndRenderToIntermediateFormat(Source src) throws Exception {
  96. throw new IllegalStateException("Not applicable to this test");
  97. }
  98. }