source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.9 KB
Line 
1/*
2 * Copyright 2002-2004 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
18package org.apache.tools.ant.types.selectors;
19
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.Project;
22import org.apache.tools.ant.util.*;
23import org.apache.tools.ant.BuildFileTest;
24import org.apache.tools.ant.types.Parameter;
25
26import junit.framework.TestCase;
27import junit.framework.AssertionFailedError;
28
29/**
30 * Tests Contains Selectors.
31 *
32 */
33public class ContainsSelectorTest extends BaseSelectorTest {
34
35 private Project project;
36
37 public ContainsSelectorTest(String name) {
38 super(name);
39 }
40
41 /**
42 * Factory method from base class. This is overriden in child
43 * classes to return a specific Selector class.
44 */
45 public BaseSelector getInstance() {
46 return new ContainsSelector();
47 }
48
49 /**
50 * Test the code that validates the selector.
51 */
52 public void testValidate() {
53 ContainsSelector s = (ContainsSelector)getInstance();
54 try {
55 s.isSelected(basedir,filenames[0],files[0]);
56 fail("ContainsSelector did not check for required field 'text'");
57 } catch (BuildException be1) {
58 assertEquals("The text attribute is required", be1.getMessage());
59 }
60
61 s = (ContainsSelector)getInstance();
62 Parameter param = new Parameter();
63 param.setName("garbage in");
64 param.setValue("garbage out");
65 Parameter[] params = {param};
66 s.setParameters(params);
67 try {
68 s.isSelected(basedir,filenames[0],files[0]);
69 fail("ContainsSelector did not check for valid parameter element");
70 } catch (BuildException be2) {
71 assertEquals("Invalid parameter garbage in", be2.getMessage());
72 }
73
74 }
75
76 /**
77 * Tests to make sure that the selector is selecting files correctly.
78 */
79 public void testSelectionBehaviour() {
80 ContainsSelector s;
81 String results;
82
83 try {
84 makeBed();
85
86 s = (ContainsSelector)getInstance();
87 s.setText("no such string in test files");
88 results = selectionString(s);
89 assertEquals("TFFFFFFFFFFT", results);
90
91 s = (ContainsSelector)getInstance();
92 s.setText("Apache Ant");
93 results = selectionString(s);
94 assertEquals("TFFFTFFFFFFT", results);
95
96 s = (ContainsSelector)getInstance();
97 s.setText("apache ant");
98 s.setCasesensitive(true);
99 results = selectionString(s);
100 assertEquals("TFFFFFFFFFFT", results);
101
102 s = (ContainsSelector)getInstance();
103 s.setText("apache ant");
104 s.setCasesensitive(false);
105 results = selectionString(s);
106 assertEquals("TFFFTFFFFFFT", results);
107
108 s = (ContainsSelector)getInstance();
109 s.setText("ApacheAnt");
110 s.setIgnorewhitespace(true);
111 results = selectionString(s);
112 assertEquals("TFFFTFFFFFFT", results);
113
114 s = (ContainsSelector)getInstance();
115 s.setText("A p a c h e A n t");
116 s.setIgnorewhitespace(true);
117 results = selectionString(s);
118 assertEquals("TFFFTFFFFFFT", results);
119
120 }
121 finally {
122 cleanupBed();
123 }
124
125 }
126
127}
Note: See TracBrowser for help on using the repository browser.