You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

StyleTest.java 5.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright 2003-2006 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs;
  18. import java.io.FileReader;
  19. import java.io.IOException;
  20. import java.io.Reader;
  21. import org.apache.tools.ant.BuildFileTest;
  22. import org.apache.tools.ant.taskdefs.optional.XsltTest;
  23. import org.apache.tools.ant.util.FileUtils;
  24. /**
  25. * TestCases for {@link XSLTProcess} task.
  26. * XXX merge with {@link XsltTest}?
  27. * @version 2003-08-05
  28. */
  29. public class StyleTest extends BuildFileTest {
  30. public StyleTest(String s) {
  31. super(s);
  32. }
  33. protected void setUp() throws Exception {
  34. configureProject("src/etc/testcases/taskdefs/style/build.xml");
  35. //executeTarget("setup");
  36. //commented out for performance while target is empty
  37. }
  38. protected void tearDown() throws Exception {
  39. executeTarget("teardown");
  40. }
  41. public void testStyleIsSet() throws Exception {
  42. expectBuildException("testStyleIsSet", "no stylesheet specified");
  43. }
  44. public void testTransferParameterSet() throws Exception {
  45. expectFileContains("testTransferParameterSet", // target
  46. "out/out.xml", // file
  47. "set='myvalue'"); // exptected string
  48. }
  49. public void testTransferParameterEmpty() throws Exception {
  50. expectFileContains("testTransferParameterEmpty",
  51. "out/out.xml",
  52. "empty=''");
  53. }
  54. public void testTransferParameterUnset() throws Exception {
  55. expectFileContains("testTransferParameterUnset",
  56. "out/out.xml",
  57. "undefined='${value}'");
  58. }
  59. public void testTransferParameterUnsetWithIf() throws Exception {
  60. expectFileContains("testTransferParameterUnsetWithIf",
  61. "out/out.xml",
  62. "undefined='undefined default value'");
  63. }
  64. public void testNewerStylesheet() throws Exception {
  65. expectFileContains("testNewerStylesheet",
  66. "out/out.xml",
  67. "new-value");
  68. }
  69. public void testDefaultMapper() throws Exception {
  70. testDefaultMapper("testDefaultMapper");
  71. }
  72. public void testExplicitFileset() throws Exception {
  73. testDefaultMapper("testExplicitFileset");
  74. }
  75. public void testDefaultMapper(String target) throws Exception {
  76. assertTrue(!getProject().resolveFile("out/data.html").exists());
  77. expectFileContains(target,
  78. "out/data.html",
  79. "set='myvalue'");
  80. }
  81. public void testCustomMapper() throws Exception {
  82. assertTrue(!getProject().resolveFile("out/out.xml").exists());
  83. expectFileContains("testCustomMapper",
  84. "out/out.xml",
  85. "set='myvalue'");
  86. }
  87. public void testTypedMapper() throws Exception {
  88. assertTrue(!getProject().resolveFile("out/out.xml").exists());
  89. expectFileContains("testTypedMapper",
  90. "out/out.xml",
  91. "set='myvalue'");
  92. }
  93. public void testDirectoryHierarchyWithDirMatching() throws Exception {
  94. executeTarget("testDirectoryHierarchyWithDirMatching");
  95. assertTrue(getProject().resolveFile("out/dest/level1/data.html")
  96. .exists());
  97. }
  98. public void testDirsWithSpaces() throws Exception {
  99. executeTarget("testDirsWithSpaces");
  100. assertTrue(getProject().resolveFile("out/d est/data.html")
  101. .exists());
  102. }
  103. // ************* copied from ConcatTest *************
  104. // ------------------------------------------------------
  105. // Helper methods - should be in BuildFileTest
  106. // -----------------------------------------------------
  107. private String getFileString(String filename)
  108. throws IOException
  109. {
  110. Reader r = null;
  111. try {
  112. r = new FileReader(getProject().resolveFile(filename));
  113. return FileUtils.readFully(r);
  114. }
  115. finally {
  116. FileUtils.close(r);
  117. }
  118. }
  119. private String getFileString(String target, String filename)
  120. throws IOException
  121. {
  122. executeTarget(target);
  123. return getFileString(filename);
  124. }
  125. private void expectFileContains(
  126. String target, String filename, String contains)
  127. throws IOException
  128. {
  129. String content = getFileString(target, filename);
  130. assertTrue(
  131. "expecting file " + filename + " to contain " +
  132. contains +
  133. " but got " + content, content.indexOf(contains) > -1);
  134. }
  135. }