update copyright
[fedora-idea.git] / plugins / maven / src / test / java / org / jetbrains / idea / maven / dom / MavenParentCompletionAndResolutionTest.java
blob451d589b11a027a93fea85fbfdb89d7392224831
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.jetbrains.idea.maven.dom;
18 import com.intellij.codeInsight.intention.IntentionAction;
19 import com.intellij.openapi.vfs.LocalFileSystem;
20 import com.intellij.openapi.vfs.VirtualFile;
21 import com.intellij.psi.ElementManipulators;
22 import com.intellij.psi.PsiElement;
24 public class MavenParentCompletionAndResolutionTest extends MavenDomWithIndicesTestCase {
25 public void testVariants() throws Exception {
26 importProject("<groupId>test</groupId>" +
27 "<artifactId>project</artifactId>" +
28 "<version>1</version>");
30 createProjectPom("<groupId>test</groupId>" +
31 "<artifactId>project</artifactId>" +
32 "<version>1</version>" +
34 "<parent>" +
35 " <groupId><caret></groupId>" +
36 " <artifactId>junit</artifactId>" +
37 " <version><caret></version>" +
38 "</parent>");
39 assertCompletionVariants(myProjectPom, "junit", "jmock", "test");
41 createProjectPom("<groupId>test</groupId>" +
42 "<artifactId>project</artifactId>" +
43 "<version>1</version>" +
45 "<parent>" +
46 " <groupId>junit</groupId>" +
47 " <artifactId><caret></artifactId>" +
48 "</parent>");
49 assertCompletionVariants(myProjectPom, "junit");
51 createProjectPom("<groupId>test</groupId>" +
52 "<artifactId>project</artifactId>" +
53 "<version>1</version>" +
55 "<parent>" +
56 " <groupId>junit</groupId>" +
57 " <artifactId>junit</artifactId>" +
58 " <version><caret></version>" +
59 "</parent>");
60 assertCompletionVariants(myProjectPom, "3.8.1", "3.8.2", "4.0");
63 public void testResolutionInsideTheProject() throws Exception {
64 createProjectPom("<groupId>test</groupId>" +
65 "<artifactId>project</artifactId>" +
66 "<version>1</version>");
68 VirtualFile m = createModulePom("m",
69 "<groupId>test</groupId>" +
70 "<artifactId>m</artifactId>" +
71 "<version>1</version>");
73 importProjects(myProjectPom, m);
75 createModulePom("m", "<groupId>test</groupId>" +
76 "<artifactId>m</artifactId>" +
77 "<version>1</version>" +
79 "<parent>" +
80 " <groupId><caret>test</groupId>" +
81 " <artifactId>project</artifactId>" +
82 " <version>1</version>" +
83 "</parent>");
85 assertResolved(m, findPsiFile(myProjectPom));
88 public void testResolutionOutsideOfTheProject() throws Exception {
89 importProject("<groupId>test</groupId>" +
90 "<artifactId>project</artifactId>" +
91 "<version>1</version>");
93 createProjectPom("<groupId>test</groupId>" +
94 "<artifactId>project</artifactId>" +
95 "<version>1</version>" +
97 "<parent>" +
98 " <groupId><caret>junit</groupId>" +
99 " <artifactId>junit</artifactId>" +
100 " <version>4.0</version>" +
101 "</parent>");
103 String filePath = myIndicesFixture.getRepositoryHelper().getTestDataPath("local1/junit/junit/4.0/junit-4.0.pom");
104 VirtualFile f = LocalFileSystem.getInstance().findFileByPath(filePath);
105 assertResolved(myProjectPom, findPsiFile(f));
108 public void testResolvingByRelativePath() throws Throwable {
109 importProject("<groupId>test</groupId>" +
110 "<artifactId>project</artifactId>" +
111 "<version>1</version>");
113 createProjectPom("<groupId>test</groupId>" +
114 "<artifactId>project</artifactId>" +
115 "<version>1</version>" +
117 "<parent>" +
118 " <groupId><caret>test</groupId>" +
119 " <artifactId>parent</artifactId>" +
120 " <version>1</version>" +
121 " <relativePath>parent/pom.xml</relativePath>" +
122 "</parent>");
124 VirtualFile parent = createModulePom("parent",
125 "<groupId>test</groupId>" +
126 "<artifactId>parent</artifactId>" +
127 "<version>1</version>");
129 assertResolved(myProjectPom, findPsiFile(parent));
132 public void testResolvingByRelativePathWithProperties() throws Throwable {
133 importProject("<groupId>test</groupId>" +
134 "<artifactId>project</artifactId>" +
135 "<version>1</version>");
137 createProjectPom("<groupId>test</groupId>" +
138 "<artifactId>project</artifactId>" +
139 "<version>1</version>" +
141 "<properties>" +
142 " <parentPath>parent/pom.xml</parentPath>" +
143 "</properties>" +
145 "<parent>" +
146 " <groupId><caret>test</groupId>" +
147 " <artifactId>parent</artifactId>" +
148 " <version>1</version>" +
149 " <relativePath>${parentPath}</relativePath>" +
150 "</parent>");
152 VirtualFile parent = createModulePom("parent",
153 "<groupId>test</groupId>" +
154 "<artifactId>parent</artifactId>" +
155 "<version>1</version>");
157 assertResolved(myProjectPom, findPsiFile(parent));
160 public void testResolvingByRelativePathWhenOutsideOfTheProject() throws Throwable {
161 VirtualFile parent = createPomFile(myProjectRoot.getParent(),
162 "<groupId>test</groupId>" +
163 "<artifactId>project</artifactId>" +
164 "<version>1</version>");
166 importProject("<groupId>test</groupId>" +
167 "<artifactId>project</artifactId>" +
168 "<version>1</version>");
170 createProjectPom("<groupId>test</groupId>" +
171 "<artifactId>project</artifactId>" +
172 "<version>1</version>" +
174 "<parent>" +
175 " <groupId><caret>test</groupId>" +
176 " <artifactId>parent</artifactId>" +
177 " <version>1</version>" +
178 " <relativePath>../pom.xml</relativePath>" +
179 "</parent>");
181 assertResolved(myProjectPom, findPsiFile(parent));
184 public void testResolvingByRelativePathWithoutPomXmlAtTheEnd() throws Throwable {
185 importProject("<groupId>test</groupId>" +
186 "<artifactId>project</artifactId>" +
187 "<version>1</version>");
189 createProjectPom("<groupId>test</groupId>" +
190 "<artifactId>project</artifactId>" +
191 "<version>1</version>" +
193 "<parent>" +
194 " <groupId>test</groupId>" +
195 " <artifactId>parent</artifactId>" +
196 " <version>1</version>" +
197 " <relativePath><caret>parent</relativePath>" +
198 "</parent>");
200 VirtualFile parent = createModulePom("parent",
201 "<groupId>test</groupId>" +
202 "<artifactId>parent</artifactId>" +
203 "<version>1</version>");
205 assertResolved(myProjectPom, findPsiFile(parent));
208 public void testDoNotHighlightResolvedParentByRelativePathWhenOutsideOfTheProject() throws Throwable {
209 createPomFile(myProjectRoot.getParent(),
210 "<groupId>test</groupId>" +
211 "<artifactId>project</artifactId>" +
212 "<version>1</version>");
214 importProject("<groupId>test</groupId>" +
215 "<artifactId>project</artifactId>" +
216 "<version>1</version>");
218 createProjectPom("<groupId>test</groupId>" +
219 "<artifactId>project</artifactId>" +
220 "<version>1</version>" +
222 "<parent>" +
223 " <groupId>test</groupId>" +
224 " <artifactId>parent</artifactId>" +
225 " <version>1</version>" +
226 " <relativePath>../pom.xml</relativePath>" +
227 "</parent>");
228 checkHighlighting(myProjectPom);
231 public void testRelativePathCompletion() throws Throwable {
232 importProject("<groupId>test</groupId>" +
233 "<artifactId>project</artifactId>" +
234 "<version>1</version>");
236 createProjectPom("<groupId>test</groupId>" +
237 "<artifactId>project</artifactId>" +
238 "<version>1</version>" +
240 "<parent>" +
241 " <groupId>test</groupId>" +
242 " <artifactId>parent</artifactId>" +
243 " <version>1</version>" +
244 " <relativePath><caret></relativePath>" +
245 "</parent>");
247 createModulePom("dir/one",
248 "<groupId>test</groupId>" +
249 "<artifactId>one</artifactId>" +
250 "<version>1</version>");
252 createModulePom("two",
253 "<groupId>test</groupId>" +
254 "<artifactId>two</artifactId>" +
255 "<version>1</version>");
257 assertCompletionVariants(myProjectPom, "dir/one/pom.xml", "two/pom.xml");
260 public void testHighlightingUnknownValues() throws Throwable {
261 importProject("<groupId>test</groupId>" +
262 "<artifactId>project</artifactId>" +
263 "<version>1</version>" +
265 "<parent>" +
266 " <groupId><error>xxx</error></groupId>" +
267 " <artifactId><error>xxx</error></artifactId>" +
268 " <version><error>xxx</error></version>" +
269 "</parent>");
271 checkHighlighting();
274 public void testHighlightingAbsentGroupId() throws Throwable {
275 importProject("<groupId>test</groupId>" +
276 "<artifactId>project</artifactId>" +
277 "<version>1</version>" +
279 "<<error descr=\"'groupId' child tag should be defined\">parent</error>>" +
280 " <artifactId><error>junit</error></artifactId>" +
281 " <version><error>4.0</error></version>" +
282 "</parent>");
283 checkHighlighting();
286 public void testHighlightingAbsentArtifactId() throws Throwable {
287 importProject("<groupId>test</groupId>" +
288 "<artifactId>project</artifactId>" +
289 "<version>1</version>" +
291 "<<error descr=\"'artifactId' child tag should be defined\">parent</error>>" +
292 " <groupId>junit</groupId>" +
293 " <version><error>4.0</error></version>" +
294 "</parent>");
295 checkHighlighting();
298 public void testHighlightingAbsentVersion() throws Throwable {
299 importProject("<groupId>test</groupId>" +
300 "<artifactId>project</artifactId>" +
301 "<version>1</version>" +
303 "<<error descr=\"'version' child tag should be defined\">parent</error>>" +
304 " <groupId>junit</groupId>" +
305 " <artifactId>junit</artifactId>" +
306 "</parent>");
307 checkHighlighting();
310 public void testHighlightingInvalidRelativePath() throws Throwable {
311 importProject("<groupId>test</groupId>" +
312 "<artifactId>project</artifactId>" +
313 "<version>1</version>" +
315 "<parent>" +
316 " <groupId>junit</groupId>" +
317 " <artifactId>junit</artifactId>" +
318 " <version>4.0</version>" +
319 " <relativePath><error>parent/pom.xml</error></relativePath>" +
320 "</parent>");
322 checkHighlighting();
325 public void testPathQuickFixForInvalidValue() throws Throwable {
326 createProjectPom("<groupId>test</groupId>" +
327 "<artifactId>project</artifactId>" +
328 "<version>1</version>");
330 VirtualFile m = createModulePom("bar",
331 "<groupId>test</groupId>" +
332 "<artifactId>one</artifactId>" +
333 "<version>1</version>");
335 importProjects(myProjectPom, m);
337 createProjectPom("<groupId>test</groupId>" +
338 "<artifactId>project</artifactId>" +
339 "<version>1</version>" +
341 "<parent>" +
342 " <groupId>test</groupId>" +
343 " <artifactId>one</artifactId>" +
344 " <version>1</version>" +
345 " <relativePath><caret>xxx</relativePath>" +
346 "</parent>");
348 IntentionAction i = getIntentionAtCaret("Fix relative path");
349 assertNotNull(i);
351 myCodeInsightFixture.launchAction(i);
352 PsiElement el = getElementAtCaret(myProjectPom);
354 assertEquals("bar/pom.xml", ElementManipulators.getValueText(el));
357 public void testDoNotShowPathQuickFixForValidPath() throws Throwable {
358 createProjectPom("<groupId>test</groupId>" +
359 "<artifactId>project</artifactId>" +
360 "<version>1</version>");
362 VirtualFile m = createModulePom("bar",
363 "<groupId>test</groupId>" +
364 "<artifactId>one</artifactId>" +
365 "<version>1</version>");
367 importProjects(myProjectPom, m);
369 createProjectPom("<groupId>test</groupId>" +
370 "<artifactId>project</artifactId>" +
371 "<version>1</version>" +
373 "<parent>" +
374 " <groupId>test</groupId>" +
375 " <artifactId>one</artifactId>" +
376 " <version>1</version>" +
377 " <relativePath><caret>bar/pom.xml</relativePath>" +
378 "</parent>");
380 assertNull(getIntentionAtCaret("Fix relative path"));