From 295d6a601f23d513fc545906e359b19e323ca896 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Fri, 4 Jun 2010 17:40:34 +0400 Subject: [PATCH] Maven: community tests fixes --- plugins/maven/maven.iml | 1 + .../jetbrains/idea/maven/MavenTestCase.java | 50 +++++++++++--- .../idea/maven/dom/MavenDomTestCase.java | 7 +- ...PropertiesCompletionAndResolutionTest.java | 3 + .../importing/ArtifactsDownloadingTest.java | 66 +++++++++++++++++++ .../importing/DependenciesImportingTest.java | 2 + 6 files changed, 117 insertions(+), 12 deletions(-) diff --git a/plugins/maven/maven.iml b/plugins/maven/maven.iml index 276526c316bf..9fcf9be4dc66 100644 --- a/plugins/maven/maven.iml +++ b/plugins/maven/maven.iml @@ -30,6 +30,7 @@ + diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java index 2996687d1ebb..562d0ae1a9aa 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/MavenTestCase.java @@ -15,6 +15,7 @@ */ package org.jetbrains.idea.maven; +import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; @@ -36,6 +37,7 @@ import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory; import org.jetbrains.idea.maven.project.*; import org.jetbrains.idea.maven.utils.MavenProgressIndicator; +import java.awt.*; import java.io.File; import java.io.IOException; import java.lang.reflect.Field; @@ -157,15 +159,28 @@ public abstract class MavenTestCase extends UsefulTestCase { @Override protected void runTest() throws Throwable { - if (runInWriteAction()) { - new WriteAction() { - protected void run(Result result) throws Throwable { - MavenTestCase.super.runTest(); - } - }.executeSilently().throwException(); + try { + if (runInWriteAction()) { + new WriteAction() { + protected void run(Result result) throws Throwable { + MavenTestCase.super.runTest(); + } + }.executeSilently().throwException(); + } + else { + MavenTestCase.super.runTest(); + } } - else { - MavenTestCase.super.runTest(); + catch (Exception throwable) { + Throwable each = throwable; + do { + if (each instanceof HeadlessException) { + printIgnoredMessage("Doesn't work in Headless environment"); + return; + } + } + while ((each = each.getCause()) != null); + throw throwable; } } @@ -450,16 +465,31 @@ public abstract class MavenTestCase extends UsefulTestCase { } protected boolean ignore() { - System.out.println("Ignored: " + getClass().getSimpleName() + "." + getName()); + printIgnoredMessage(null); return true; } + public boolean checkUltimate() { + if ("IU".equals(ApplicationInfo.getInstance().getBuild().getProductCode())) return true; + printIgnoredMessage("Ultimate edition is required"); + return false; + } + protected boolean hasMavenInstallation() { boolean result = getTestMavenHome() != null; - if (!result) System.out.println("Ignored, because Maven installation not found: " + getClass().getSimpleName() + "." + getName()); + if (!result) printIgnoredMessage("Maven installation not found"); return result; } + private void printIgnoredMessage(String message) { + String toPrint = "Ignored"; + if (message != null) { + toPrint += ", beacuse " + message; + } + toPrint += ": " + getClass().getSimpleName() + "." + getName(); + System.out.println(toPrint); + } + private String getTestMavenHome() { return System.getProperty("idea.maven.test.home"); } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java index ceb7e5b75ec4..edd3a2256009 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenDomTestCase.java @@ -52,6 +52,7 @@ import com.intellij.usages.UsageTargetUtil; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashMap; +import junit.framework.AssertionFailedError; import org.jetbrains.annotations.NonNls; import org.jetbrains.idea.maven.MavenImportingTestCase; import org.jetbrains.idea.maven.dom.model.MavenDomProjectModel; @@ -279,7 +280,7 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase { invokeRename(context, renameHandler); } - protected void assertCannotRename() throws IOException { + protected void assertCannotRename() throws Exception { MapDataContext context = createRenameDataContext(myProjectPom, "new name"); RenameHandler handler = RenameHandlerRegistry.getInstance().getRenameHandler(context); if (handler == null) return; @@ -287,7 +288,9 @@ public abstract class MavenDomTestCase extends MavenImportingTestCase { invokeRename(context, handler); } catch (Exception e) { - assertTrue(e.getMessage(), e.getMessage().startsWith("Cannot perform refactoring.")); + if (!e.getMessage().startsWith("Cannot perform refactoring.")) { + throw e; + } } } diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenFilteredPropertiesCompletionAndResolutionTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenFilteredPropertiesCompletionAndResolutionTest.java index cc25c4ae2889..d8b15db05518 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenFilteredPropertiesCompletionAndResolutionTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/dom/MavenFilteredPropertiesCompletionAndResolutionTest.java @@ -21,6 +21,9 @@ import com.intellij.psi.PsiManager; import org.jetbrains.idea.maven.dom.model.MavenDomProfilesModel; import org.jetbrains.idea.maven.dom.references.MavenPropertyPsiReference; +import java.awt.*; +import java.io.IOException; + public class MavenFilteredPropertiesCompletionAndResolutionTest extends MavenDomTestCase { public void testBasic() throws Exception { createProjectSubDir("res"); diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java index 90415f08e8dc..904bd52127a0 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/ArtifactsDownloadingTest.java @@ -146,6 +146,72 @@ public class ArtifactsDownloadingTest extends MavenImportingTestCase { assertTrue(javadoc.exists()); } + public void testCustomDocsAndSources() throws Exception { + if (!checkUltimate()) return; + + String remoteRepo = FileUtil.toSystemIndependentName(myDir.getPath() + "/repo"); + updateSettingsXmlFully("" + + "" + + " " + + " Nexus" + + " " + VfsUtil.pathToUrl(remoteRepo) + "" + + " *" + + " " + + "" + + ""); + + FileUtil.writeToFile(new File(remoteRepo, "/xxx/yyy/1/yyy-1-sources.jar"), "111".getBytes()); + FileUtil.writeToFile(new File(remoteRepo, "/xxx/yyy/1/yyy-1-sources.jar.sha1"), + "6216f8a75fd5bb3d5f22b6f9958cdede3fc086c2 xxx/yyy/1/yyy-1-sources.jar".getBytes()); + + FileUtil.writeToFile(new File(remoteRepo, "/xxx/yyy/1/yyy-1-asdoc.zip"), "111".getBytes()); + FileUtil.writeToFile(new File(remoteRepo, "/xxx/yyy/1/yyy-1-asdoc.zip.sha1"), + "6216f8a75fd5bb3d5f22b6f9958cdede3fc086c2 xxx/yyy/1/yyy-1-asdoc.zip".getBytes()); + + FileUtil.writeToFile(new File(remoteRepo, "/xxx/yyy/1/yyy-1-javadoc.jar"), "111".getBytes()); + FileUtil.writeToFile(new File(remoteRepo, "/xxx/yyy/1/yyy-1-javadoc.jar.sha1"), + "6216f8a75fd5bb3d5f22b6f9958cdede3fc086c2 xxx/yyy/1/yyy-1-javadoc.jar".getBytes()); + + importProject("test" + + "project" + + "1" + + "swf" + + + "" + + " " + + " xxx" + + " yyy" + + " 1" + + " swc" + + " " + + "" + + + "" + + " " + + " " + + " org.sonatype.flexmojos" + + " flexmojos-maven-plugin" + + " 3.5.0" + + " true" + + " " + + " " + + ""); + + File sources = new File(getRepositoryPath(), "/xxx/yyy/1/yyy-1-sources.jar"); + File asdoc = new File(getRepositoryPath(), "/xxx/yyy/1/yyy-1-asdoc.zip"); + File javadoc = new File(getRepositoryPath(), "/xxx/yyy/1/yyy-1-javadoc.jar"); + + assertFalse(sources.exists()); + assertFalse(asdoc.exists()); + assertFalse(javadoc.exists()); + + downloadArtifacts(); + + assertTrue(sources.exists()); + assertTrue(asdoc.exists()); + assertFalse(javadoc.exists()); + } + public void testDownloadingPlugins() throws Exception { importProject("test" + "project" + diff --git a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java index 3f94e53655f2..044731e6bf0b 100644 --- a/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java +++ b/plugins/maven/src/test/java/org/jetbrains/idea/maven/importing/DependenciesImportingTest.java @@ -1500,6 +1500,8 @@ public class DependenciesImportingTest extends MavenImportingTestCase { } public void testCustomSourcesAndJavadocPaths() throws Exception { + if (!checkUltimate()) return; + importProject("test" + "project" + "1" +