From d90aeb4ab40c47c5c80b67688424e8f2d7772dfc Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 7 Jun 2011 21:33:29 +0400 Subject: [PATCH] add codeInsight to testng.xml (IDEA-67651; IDEA-67649) --- plugins/testng/src/META-INF/plugin.xml | 1 + .../TestNGSuiteReferenceContributor.java | 68 +++++++++++++ plugins/testng/testData/references/testng.xml | 17 ++++ .../referenceContributor/TestNGSuiteTest.java | 95 +++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java create mode 100644 plugins/testng/testData/references/testng.xml create mode 100644 plugins/testng/testSources/com/theoryinpractice/testng/referenceContributor/TestNGSuiteTest.java diff --git a/plugins/testng/src/META-INF/plugin.xml b/plugins/testng/src/META-INF/plugin.xml index 37bd6dc007fe..c32931a4f68f 100644 --- a/plugins/testng/src/META-INF/plugin.xml +++ b/plugins/testng/src/META-INF/plugin.xml @@ -14,6 +14,7 @@ + com.theoryinpractice.testng.intention.TestNGOrderEntryFix diff --git a/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java b/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java new file mode 100644 index 000000000000..755995a87faf --- /dev/null +++ b/plugins/testng/src/com/theoryinpractice/testng/TestNGSuiteReferenceContributor.java @@ -0,0 +1,68 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.theoryinpractice.testng; + +import com.intellij.patterns.XmlAttributeValuePattern; +import com.intellij.psi.PsiReferenceContributor; +import com.intellij.psi.PsiReferenceRegistrar; +import com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider; +import com.intellij.psi.impl.source.resolve.reference.impl.providers.PathListReferenceProvider; +import org.testng.IMethodSelector; + +import static com.intellij.patterns.XmlPatterns.*; + +/** + * User: anna + */ +public class TestNGSuiteReferenceContributor extends PsiReferenceContributor { + private static XmlAttributeValuePattern ourTestClassPattern = + xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("class") + .withParent(xmlTag().withName("classes") + .withParent(xmlTag().withName("test").withParent(xmlTag().withName("suite")))))); + + private static XmlAttributeValuePattern ourListenerClassPattern = + xmlAttributeValue(xmlAttribute("class-name").withParent(xmlTag().withName("listener") + .withParent(xmlTag().withName("listeners") + .withParent(xmlTag().withName("suite"))))); + + private static XmlAttributeValuePattern ourMethodSelectorPattern = + xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("selector-class") + .withParent(xmlTag().withName("method-selector") + .withParent(xmlTag().withName("method-selectors") + .withParent( + xmlTag().withName(string().oneOf("suite", "test"))))))); + + private static XmlAttributeValuePattern ourPackagePattern = + xmlAttributeValue(xmlAttribute("name").withParent(xmlTag().withName("package") + .withParent(xmlTag().withName("packages") + .withParent(xmlTag().withName("suite"))))); + + private static XmlAttributeValuePattern ourSuiteFilePattern = + xmlAttributeValue(xmlAttribute("path").withParent(xmlTag().withName("suite-file") + .withParent(xmlTag().withName("suite-files") + .withParent(xmlTag().withName("suite"))))); + + public void registerReferenceProviders(PsiReferenceRegistrar registrar) { + registrar.registerReferenceProvider(ourTestClassPattern, new JavaClassReferenceProvider()); + registrar.registerReferenceProvider(ourListenerClassPattern, new JavaClassReferenceProvider()); + + final JavaClassReferenceProvider methodSelectorProvider = new JavaClassReferenceProvider(); + methodSelectorProvider.setOption(JavaClassReferenceProvider.EXTEND_CLASS_NAMES, new String[]{IMethodSelector.class.getName()}); + registrar.registerReferenceProvider(ourMethodSelectorPattern, methodSelectorProvider); + + registrar.registerReferenceProvider(ourSuiteFilePattern, new PathListReferenceProvider()); + } +} diff --git a/plugins/testng/testData/references/testng.xml b/plugins/testng/testData/references/testng.xml new file mode 100644 index 000000000000..315c5f35a334 --- /dev/null +++ b/plugins/testng/testData/references/testng.xml @@ -0,0 +1,17 @@ + + + + test-unit.xml"/> + + + + + foo"/> + + + + foo"/> + + + + \ No newline at end of file diff --git a/plugins/testng/testSources/com/theoryinpractice/testng/referenceContributor/TestNGSuiteTest.java b/plugins/testng/testSources/com/theoryinpractice/testng/referenceContributor/TestNGSuiteTest.java new file mode 100644 index 000000000000..707632099246 --- /dev/null +++ b/plugins/testng/testSources/com/theoryinpractice/testng/referenceContributor/TestNGSuiteTest.java @@ -0,0 +1,95 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.theoryinpractice.testng.referenceContributor; + +import com.intellij.openapi.application.PluginPathManager; +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import com.intellij.util.ArrayUtil; +import com.intellij.util.ui.UIUtil; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * User: anna + * Date: Sep 3, 2010 + */ +@Test +public class TestNGSuiteTest extends LightCodeInsightFixtureTestCase { + @BeforeMethod + @Override + protected void setUp() throws Exception { + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + try { + TestNGSuiteTest.super.setUp(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + @AfterMethod + @Override + protected void tearDown() throws Exception { + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + try { + TestNGSuiteTest.super.tearDown(); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + public void testNothing(){} + + public void testTestNGSuiteFile() throws Throwable { + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + try { + myFixture.addClass("package org.testng.annotations; public @interface DataProvider {}"); + myFixture.addClass("package org.testng.annotations; public @interface Test {}"); + myFixture.addClass("package o; @Test public class MyTest { public void testMe(){} }"); + myFixture.addFileToProject("subPack/test-unit.xml", "" + + "" + + "" + + "" + + ""); + myFixture.testHighlighting("testng.xml"); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + }); + } + + @Override + protected String getBasePath() { + return PluginPathManager.getPluginHomePathRelative("testng") + "/testData/references"; + } + + +}