001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.BuildFileTest;
023: import org.apache.tools.ant.Task;
024: import org.apache.tools.ant.types.FileSet;
025:
026: /**
027: */
028: public class PreSetDefTest extends BuildFileTest {
029: public PreSetDefTest(String name) {
030: super (name);
031: }
032:
033: public void setUp() {
034: configureProject("src/etc/testcases/taskdefs/presetdef.xml");
035: }
036:
037: public void testSimple() {
038: expectLog("simple", "Hello world");
039: }
040:
041: public void testText() {
042: expectLog("text", "Inner Text");
043: }
044:
045: public void testUri() {
046: expectLog("uri", "Hello world");
047: }
048:
049: public void testDefaultTest() {
050: expectLog("defaulttest", "attribute is false");
051: }
052:
053: public void testDoubleDefault() {
054: expectLog("doubledefault",
055: "attribute is falseattribute is true");
056: }
057:
058: public void testTextOptional() {
059: expectLog("text.optional", "MyTextoverride text");
060: }
061:
062: public void testElementOrder() {
063: expectLog("element.order", "Line 1Line 2");
064: }
065:
066: public void testElementOrder2() {
067: expectLog("element.order2", "Line 1Line 2Line 3");
068: }
069:
070: public void testAntTypeTest() {
071: expectLog("antTypeTest", "");
072: }
073:
074: public void testCorrectTaskNameBadAttr() {
075: expectBuildExceptionContaining("correct_taskname_badattr",
076: "attribute message", "javac doesn't support the");
077: }
078:
079: public void testCorrectTaskNameBadEl() {
080: expectBuildExceptionContaining("correct_taskname_badel",
081: "element message", "javac doesn't support the");
082: }
083:
084: public void testPresetdefWithNestedElementTwice() { // #38056
085: executeTarget("presetdef-with-nested-element-twice");
086: executeTarget("presetdef-with-nested-element-twice");
087: }
088:
089: /**
090: * A test class to check default properties
091: */
092: public static class DefaultTest extends Task {
093: boolean isSet = false;
094: boolean attribute = false;
095:
096: public void setAttribute(boolean b) {
097: if (isSet) {
098: throw new BuildException("Attribute Already set");
099: }
100: attribute = b;
101: isSet = true;
102: }
103:
104: public void execute() {
105: getProject().log("attribute is " + attribute);
106: }
107: }
108:
109: /**
110: * A test class to check presetdef with add and addConfigured and ant-type
111: */
112: public static class AntTypeTest extends Task {
113: public void addFileSet(FileSet fileset) {
114: }
115:
116: public void addConfiguredConfigured(FileSet fileset) {
117: }
118: }
119: }
|