Search in sources :

Example 1 with TestData

use of com.theoryinpractice.testng.model.TestData in project intellij-community by JetBrains.

the class TestNGTestDiscoveryRunnableState method createSearchingForTestsTask.

@Override
public SearchingForTestsTask createSearchingForTestsTask() {
    return new SearchingForTestsTask(myServerSocket, getConfiguration(), myTempFile) {

        @Override
        protected void search() throws CantRunException {
            myClasses.clear();
            final TestData data = getConfiguration().getPersistantData();
            final Pair<String, String> position = data.TEST_OBJECT.equals(TestType.SOURCE.getType()) ? Pair.create(data.getMainClassName(), data.getMethodName()) : null;
            final Set<String> patterns = TestDiscoverySearchHelper.search(getProject(), position, data.getChangeList(), getConfiguration().getFrameworkPrefix());
            final Module module = getConfiguration().getConfigurationModule().getModule();
            final GlobalSearchScope searchScope = module != null ? GlobalSearchScope.moduleWithDependenciesScope(module) : GlobalSearchScope.projectScope(getProject());
            TestNGTestPattern.fillTestObjects(myClasses, patterns, TestSearchScope.MODULE_WITH_DEPENDENCIES, getConfiguration(), searchScope);
        }

        @Override
        protected void onFound() {
            super.onFound();
            writeClassesPerModule(myClasses);
        }
    };
}
Also used : SearchingForTestsTask(com.theoryinpractice.testng.configuration.SearchingForTestsTask) TestData(com.theoryinpractice.testng.model.TestData) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module)

Example 2 with TestData

use of com.theoryinpractice.testng.model.TestData in project intellij-community by JetBrains.

the class TestNGConfigurationType method isConfigurationByLocation.

public boolean isConfigurationByLocation(RunConfiguration runConfiguration, Location location) {
    TestNGConfiguration config = (TestNGConfiguration) runConfiguration;
    TestData testobject = config.getPersistantData();
    if (testobject == null)
        return false;
    else {
        final PsiElement element = location.getPsiElement();
        final TestNGTestObject testNGTestObject = TestNGTestObject.fromConfig(config);
        if (testNGTestObject != null && testNGTestObject.isConfiguredByElement(element)) {
            final Module configurationModule = config.getConfigurationModule().getModule();
            if (Comparing.equal(location.getModule(), configurationModule))
                return true;
            final Module predefinedModule = ((TestNGConfiguration) RunManagerEx.getInstanceEx(location.getProject()).getConfigurationTemplate(myFactory).getConfiguration()).getConfigurationModule().getModule();
            return Comparing.equal(predefinedModule, configurationModule);
        } else {
            return false;
        }
    }
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) TestNGTestObject(com.theoryinpractice.testng.model.TestNGTestObject) Module(com.intellij.openapi.module.Module) PsiElement(com.intellij.psi.PsiElement)

Example 3 with TestData

use of com.theoryinpractice.testng.model.TestData in project intellij-community by JetBrains.

the class DetectClassesToRunTest method doTestMethodConfiguration.

private void doTestMethodConfiguration(PsiClass aClass, PsiClass secondaryClass, PsiMethod configMethod, PsiMethod... expectedMethods) throws CantRunException {
    final TestNGConfiguration configuration = new TestNGConfiguration("testOne", getProject(), TestNGConfigurationType.getInstance().getConfigurationFactories()[0]);
    final TestData data = configuration.getPersistantData();
    data.TEST_OBJECT = TestType.METHOD.getType();
    data.METHOD_NAME = "testOne";
    data.setScope(TestSearchScope.SINGLE_MODULE);
    configuration.setModule(data.setMainClass(aClass));
    final TestNGTestObject testObject = TestNGTestObject.fromConfig(configuration);
    assertNotNull(testObject);
    final LinkedHashMap<PsiClass, Map<PsiMethod, List<String>>> classes = new LinkedHashMap<>();
    testObject.fillTestObjects(classes);
    assertContainsElements(classes.keySet(), aClass);
    final Map<PsiMethod, List<String>> methods = classes.get(aClass);
    assertContainsElements(methods.keySet(), expectedMethods);
    if (secondaryClass != null) {
        final Map<PsiMethod, List<String>> configMethods = classes.get(secondaryClass);
        assertTrue(configMethods != null);
        assertTrue(configMethods.containsKey(configMethod));
    }
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) PsiMethod(com.intellij.psi.PsiMethod) TestNGTestObject(com.theoryinpractice.testng.model.TestNGTestObject) PsiClass(com.intellij.psi.PsiClass) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with TestData

use of com.theoryinpractice.testng.model.TestData in project intellij-community by JetBrains.

the class AbstractTestNGPatternConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final LinkedHashSet<String> classes = new LinkedHashSet<>();
    final PsiElement element = checkPatterns(context, classes);
    if (element == null) {
        return false;
    }
    sourceElement.set(element);
    final TestData data = configuration.getPersistantData();
    data.setPatterns(classes);
    data.TEST_OBJECT = TestType.PATTERN.getType();
    data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
    configuration.setGeneratedName();
    setupConfigurationParamName(configuration, context.getLocation());
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TestData(com.theoryinpractice.testng.model.TestData) PsiElement(com.intellij.psi.PsiElement)

Example 5 with TestData

use of com.theoryinpractice.testng.model.TestData in project intellij-community by JetBrains.

the class AbstractTestNGPackageConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(TestNGConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final PsiElement element = context.getPsiLocation();
    PsiPackage aPackage = JavaRuntimeConfigurationProducerBase.checkPackage(element);
    if (aPackage == null) {
        return false;
    }
    final Location location = context.getLocation();
    if (location == null) {
        return false;
    }
    if (!LocationUtil.isJarAttached(location, aPackage, TestNGUtil.TEST_ANNOTATION_FQN)) {
        return false;
    }
    final TestData data = configuration.data;
    data.PACKAGE_NAME = aPackage.getQualifiedName();
    data.TEST_OBJECT = TestType.PACKAGE.getType();
    data.setScope(setupPackageConfiguration(context, configuration, data.getScope()));
    configuration.setGeneratedName();
    sourceElement.set(aPackage);
    return true;
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) PsiPackage(com.intellij.psi.PsiPackage) PsiElement(com.intellij.psi.PsiElement) Location(com.intellij.execution.Location)

Aggregations

TestData (com.theoryinpractice.testng.model.TestData)8 TestNGTestObject (com.theoryinpractice.testng.model.TestNGTestObject)4 PsiClass (com.intellij.psi.PsiClass)3 PsiElement (com.intellij.psi.PsiElement)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Module (com.intellij.openapi.module.Module)2 ExecutionException (com.intellij.execution.ExecutionException)1 Location (com.intellij.execution.Location)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiPackage (com.intellij.psi.PsiPackage)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 SearchingForTestsTask (com.theoryinpractice.testng.configuration.SearchingForTestsTask)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 NonNls (org.jetbrains.annotations.NonNls)1