source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/types/selectors/DependSelectorTest.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: 5.9 KB
Line 
1/*
2 * Copyright 2000-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.BuildFileTest;
23import org.apache.tools.ant.types.Mapper;
24import org.apache.tools.ant.util.FileNameMapper;
25import org.apache.tools.ant.util.IdentityMapper;
26import org.apache.tools.ant.util.GlobPatternMapper;
27import org.apache.tools.ant.util.JavaEnvUtils;
28
29import java.io.File;
30
31import junit.framework.TestCase;
32import junit.framework.AssertionFailedError;
33
34/**
35 * Tests Depend Selectors
36 *
37 */
38public class DependSelectorTest extends BaseSelectorTest {
39
40 private Project project;
41
42 public DependSelectorTest(String name) {
43 super(name);
44 }
45
46 /**
47 * Factory method from base class. This is overriden in child
48 * classes to return a specific Selector class.
49 */
50 public BaseSelector getInstance() {
51 return new DependSelector();
52 }
53
54 /**
55 * Test the code that validates the selector.
56 */
57 public void testValidate() {
58 DependSelector s = (DependSelector)getInstance();
59 try {
60 s.createMapper();
61 s.createMapper();
62 fail("DependSelector allowed more than one nested mapper.");
63 } catch (BuildException be1) {
64 assertEquals("Cannot define more than one mapper",
65 be1.getMessage());
66 }
67
68 s = (DependSelector)getInstance();
69 try {
70 s.isSelected(basedir,filenames[0],files[0]);
71 fail("DependSelector did not check for required fields");
72 } catch (BuildException be2) {
73 assertEquals("The targetdir attribute is required.",
74 be2.getMessage());
75 }
76
77 }
78
79 /**
80 * Tests to make sure that the selector is selecting files correctly.
81 */
82 public void testSelectionBehaviour() {
83 DependSelector s;
84 String results;
85 File subdir;
86 Mapper m;
87 Mapper.MapperType identity = new Mapper.MapperType();
88 identity.setValue("identity");
89 Mapper.MapperType glob = new Mapper.MapperType();
90 glob.setValue("glob");
91 Mapper.MapperType merge = new Mapper.MapperType();
92 merge.setValue("merge");
93
94 try {
95 makeBed();
96
97 s = (DependSelector)getInstance();
98 s.setTargetdir(beddir);
99 results = selectionString(s);
100 assertEquals("FFFFFFFFFFFF", results);
101
102 s = (DependSelector)getInstance();
103 s.setTargetdir(beddir);
104 m = s.createMapper();
105 m.setType(identity);
106 results = selectionString(s);
107 assertEquals("FFFFFFFFFFFF", results);
108
109 if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) {
110 s = (DependSelector)getInstance();
111 s.setTargetdir(beddir);
112 m = s.createMapper();
113 m.setType(merge);
114 m.setTo("asf-logo.gif.gz");
115 results = selectionString(s);
116 assertEquals("TFFFFTTTFFF", results.substring(0,11));
117
118 s = (DependSelector)getInstance();
119 s.setTargetdir(beddir);
120 m = s.createMapper();
121 m.setType(merge);
122 m.setTo("asf-logo.gif.bz2");
123 results = selectionString(s);
124 assertEquals("TTFTTTTTTTTT", results);
125
126 // Test for path relative to project base directory
127 s = (DependSelector)getInstance();
128 subdir = new File("selectortest/tar/bz2");
129 s.setTargetdir(subdir);
130 m = s.createMapper();
131 m.setType(glob);
132 m.setFrom("*.bz2");
133 m.setTo("*.tar.bz2");
134 results = selectionString(s);
135 assertEquals("FFTFFFFFFTTF", results);
136 }
137
138 s = (DependSelector)getInstance();
139 subdir = new File(beddir,"tar/bz2");
140 s.setTargetdir(subdir);
141 m = s.createMapper();
142 m.setType(glob);
143 m.setFrom("*.bz2");
144 m.setTo("*.tar.bz2");
145 results = selectionString(s);
146 assertEquals("FFFFFFFFFTTF", results);
147
148 try {
149 makeMirror();
150
151 s = (DependSelector)getInstance();
152 File testdir = getProject().resolveFile("selectortest2");
153 s.setTargetdir(testdir);
154 results = selectionString(s);
155 assertEquals("FFFTTFFFFFFF", results);
156
157 s = (DependSelector)getInstance();
158 testdir = getProject().resolveFile("selectortest2/tar/bz2");
159 s.setTargetdir(testdir);
160 m = s.createMapper();
161 m.setType(glob);
162 m.setFrom("*.bz2");
163 m.setTo("*.tar.bz2");
164 results = mirrorSelectionString(s);
165 assertEquals("FFFFFFFFFTTF", results);
166 results = selectionString(s);
167 assertEquals("FFFFFFFFFTTF", results);
168 }
169 finally {
170 cleanupMirror();
171 }
172
173 }
174 finally {
175 cleanupBed();
176 }
177
178 }
179
180}
Note: See TracBrowser for help on using the repository browser.