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.

PreSetDefTest.java 3.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. */
  18. package org.apache.tools.ant.taskdefs;
  19. import org.apache.tools.ant.BuildException;
  20. import org.apache.tools.ant.BuildFileTest;
  21. import org.apache.tools.ant.Task;
  22. import org.apache.tools.ant.types.FileSet;
  23. /**
  24. */
  25. public class PreSetDefTest extends BuildFileTest {
  26. public PreSetDefTest(String name) {
  27. super(name);
  28. }
  29. public void setUp() {
  30. configureProject("src/etc/testcases/taskdefs/presetdef.xml");
  31. }
  32. public void testSimple() {
  33. expectLog("simple", "Hello world");
  34. }
  35. public void testText() {
  36. expectLog("text", "Inner Text");
  37. }
  38. public void testUri() {
  39. expectLog("uri", "Hello world");
  40. }
  41. public void testDefaultTest() {
  42. expectLog("defaulttest", "attribute is false");
  43. }
  44. public void testDoubleDefault() {
  45. expectLog("doubledefault", "attribute is falseattribute is true");
  46. }
  47. public void testTextOptional() {
  48. expectLog("text.optional", "MyTextoverride text");
  49. }
  50. public void testElementOrder() {
  51. expectLog("element.order", "Line 1Line 2");
  52. }
  53. public void testElementOrder2() {
  54. expectLog("element.order2", "Line 1Line 2Line 3");
  55. }
  56. public void testAntTypeTest() {
  57. expectLog("antTypeTest", "");
  58. }
  59. public void testCorrectTaskNameBadAttr() {
  60. expectBuildExceptionContaining(
  61. "correct_taskname_badattr", "attribute message", "javac doesn't support the");
  62. }
  63. public void testCorrectTaskNameBadEl() {
  64. expectBuildExceptionContaining(
  65. "correct_taskname_badel", "element message", "javac doesn't support the");
  66. }
  67. public void testPresetdefWithNestedElementTwice() { // #38056
  68. executeTarget("presetdef-with-nested-element-twice");
  69. executeTarget("presetdef-with-nested-element-twice");
  70. }
  71. /**
  72. * A test class to check default properties
  73. */
  74. public static class DefaultTest extends Task {
  75. boolean isSet = false;
  76. boolean attribute = false;
  77. public void setAttribute(boolean b) {
  78. if (isSet) {
  79. throw new BuildException("Attribute Already set");
  80. }
  81. attribute = b;
  82. isSet = true;
  83. }
  84. public void execute() {
  85. getProject().log("attribute is " + attribute);
  86. }
  87. }
  88. /**
  89. * A test class to check presetdef with add and addConfigured and ant-type
  90. */
  91. public static class AntTypeTest extends Task {
  92. public void addFileSet(FileSet fileset) {
  93. }
  94. public void addConfiguredConfigured(FileSet fileset) {
  95. }
  96. }
  97. }