add codeInsight to testng.xml (IDEA-67651; IDEA-67649)

This commit is contained in:
anna
2011-06-07 21:35:00 +04:00
parent 273085d9b5
commit d90aeb4ab4
4 changed files with 181 additions and 0 deletions
+1
View File
@@ -14,6 +14,7 @@
<inspectionToolProvider implementation="com.theoryinpractice.testng.inspection.TestNGInspectionsToolProvider"/>
<configurationType implementation="com.theoryinpractice.testng.configuration.TestNGConfigurationType"/>
<psi.referenceContributor language="JAVA" implementation="com.theoryinpractice.testng.TestNGReferenceContributor"/>
<psi.referenceContributor language="XML" implementation="com.theoryinpractice.testng.TestNGSuiteReferenceContributor"/>
<intentionAction>
<className>com.theoryinpractice.testng.intention.TestNGOrderEntryFix</className>
</intentionAction>
@@ -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());
}
}
@@ -0,0 +1,17 @@
<suite>
<suite-files>
<suite-file path="/subPack/test-unit.xml"/>
<suite-file path="/<error descr="Cannot resolve file 'test-unit.xml'">test-unit.xml</error>"/>
</suite-files>
<test>
<method-selectors>
<method-selector>
<selector-class name="<error descr="Cannot resolve class 'foo'">foo</error>"/>
</method-selector>
</method-selectors>
<classes>
<class name="<error descr="Cannot resolve class 'foo'">foo</error>"/>
<class name="o.MyTest"/>
</classes>
</test>
</suite>
@@ -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", "<suite>" +
"<test>" +
"<classes></classes>" +
"</test>" +
"</suite>");
myFixture.testHighlighting("testng.xml");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
});
}
@Override
protected String getBasePath() {
return PluginPathManager.getPluginHomePathRelative("testng") + "/testData/references";
}
}