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.types.selectors;
020:
021: import org.apache.tools.ant.BuildException;
022: import org.apache.tools.ant.Project;
023: import org.apache.tools.ant.types.Parameter;
024:
025: /**
026: * Tests Contains Selectors.
027: *
028: */
029: public class ContainsSelectorTest extends BaseSelectorTest {
030:
031: private Project project;
032:
033: public ContainsSelectorTest(String name) {
034: super (name);
035: }
036:
037: /**
038: * Factory method from base class. This is overriden in child
039: * classes to return a specific Selector class.
040: */
041: public BaseSelector getInstance() {
042: return new ContainsSelector();
043: }
044:
045: /**
046: * Test the code that validates the selector.
047: */
048: public void testValidate() {
049: ContainsSelector s = (ContainsSelector) getInstance();
050: try {
051: s.isSelected(basedir, filenames[0], files[0]);
052: fail("ContainsSelector did not check for required field 'text'");
053: } catch (BuildException be1) {
054: assertEquals("The text attribute is required", be1
055: .getMessage());
056: }
057:
058: s = (ContainsSelector) getInstance();
059: Parameter param = new Parameter();
060: param.setName("garbage in");
061: param.setValue("garbage out");
062: Parameter[] params = { param };
063: s.setParameters(params);
064: try {
065: s.isSelected(basedir, filenames[0], files[0]);
066: fail("ContainsSelector did not check for valid parameter element");
067: } catch (BuildException be2) {
068: assertEquals("Invalid parameter garbage in", be2
069: .getMessage());
070: }
071:
072: }
073:
074: /**
075: * Tests to make sure that the selector is selecting files correctly.
076: */
077: public void testSelectionBehaviour() {
078: ContainsSelector s;
079: String results;
080:
081: try {
082: makeBed();
083:
084: s = (ContainsSelector) getInstance();
085: s.setText("no such string in test files");
086: results = selectionString(s);
087: assertEquals("TFFFFFFFFFFT", results);
088:
089: s = (ContainsSelector) getInstance();
090: s.setText("Apache Ant");
091: results = selectionString(s);
092: assertEquals("TFFFTFFFFFFT", results);
093:
094: s = (ContainsSelector) getInstance();
095: s.setText("apache ant");
096: s.setCasesensitive(true);
097: results = selectionString(s);
098: assertEquals("TFFFFFFFFFFT", results);
099:
100: s = (ContainsSelector) getInstance();
101: s.setText("apache ant");
102: s.setCasesensitive(false);
103: results = selectionString(s);
104: assertEquals("TFFFTFFFFFFT", results);
105:
106: s = (ContainsSelector) getInstance();
107: s.setText("ApacheAnt");
108: s.setIgnorewhitespace(true);
109: results = selectionString(s);
110: assertEquals("TFFFTFFFFFFT", results);
111:
112: s = (ContainsSelector) getInstance();
113: s.setText("A p a c h e A n t");
114: s.setIgnorewhitespace(true);
115: results = selectionString(s);
116: assertEquals("TFFFTFFFFFFT", results);
117:
118: } finally {
119: cleanupBed();
120: }
121:
122: }
123:
124: }
|