Search in sources :

Example 1 with TestNGConfiguration

use of com.theoryinpractice.testng.configuration.TestNGConfiguration in project intellij-community by JetBrains.

the class TestNGConsoleProperties method initScope.

@NotNull
@Override
protected GlobalSearchScope initScope() {
    final TestNGConfiguration configuration = getConfiguration();
    final String testObject = configuration.getPersistantData().TEST_OBJECT;
    if (TestType.CLASS.getType().equals(testObject) || TestType.METHOD.getType().equals(testObject)) {
        return super.initScope();
    } else {
        final SourceScope sourceScope = configuration.getPersistantData().getScope().getSourceScope(configuration);
        return sourceScope != null ? sourceScope.getGlobalSearchScope() : GlobalSearchScope.allScope(getProject());
    }
}
Also used : SourceScope(com.intellij.execution.testframework.SourceScope) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TestNGConfiguration

use of com.theoryinpractice.testng.configuration.TestNGConfiguration in project intellij-community by JetBrains.

the class TestClassBrowser method getFilter.

public ClassFilter.ClassFilterWithScope getFilter() throws MessageInfoException {
    TestNGConfiguration config = new TestNGConfiguration("<no-name>", getProject(), TestNGConfigurationType.getInstance().getConfigurationFactories()[0]);
    editor.applyEditorTo(config);
    GlobalSearchScope scope = getSearchScope(config.getModules());
    if (scope == null) {
        scope = GlobalSearchScope.allScope(getProject());
    }
    return new TestClassFilter(scope, getProject(), false);
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) TestClassFilter(com.theoryinpractice.testng.model.TestClassFilter)

Example 3 with TestNGConfiguration

use of com.theoryinpractice.testng.configuration.TestNGConfiguration in project intellij-community by JetBrains.

the class RerunFailedTestsAction method getRunProfile.

@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    final TestNGConfiguration configuration = (TestNGConfiguration) myConsoleProperties.getConfiguration();
    final List<AbstractTestProxy> failedTests = getFailedTests(configuration.getProject());
    return new MyRunProfile(configuration) {

        @Override
        @NotNull
        public Module[] getModules() {
            return configuration.getModules();
        }

        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
            return new TestNGRunnableState(env, configuration) {

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

                        @Override
                        protected void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes) throws CantRunException {
                            final HashMap<PsiClass, Map<PsiMethod, List<String>>> fullClassList = ContainerUtil.newHashMap();
                            super.fillTestObjects(fullClassList);
                            for (final PsiClass aClass : fullClassList.keySet()) {
                                if (!ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

                                    @Override
                                    public Boolean compute() {
                                        return TestNGUtil.hasTest(aClass);
                                    }
                                })) {
                                    classes.put(aClass, fullClassList.get(aClass));
                                }
                            }
                            final GlobalSearchScope scope = getConfiguration().getConfigurationModule().getSearchScope();
                            final Project project = getConfiguration().getProject();
                            for (final AbstractTestProxy proxy : failedTests) {
                                ApplicationManager.getApplication().runReadAction(() -> includeFailedTestWithDependencies(classes, scope, project, proxy));
                            }
                        }
                    };
                }
            };
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiMethod(com.intellij.psi.PsiMethod) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) PsiClass(com.intellij.psi.PsiClass) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) Executor(com.intellij.execution.Executor) TestNGRunnableState(com.theoryinpractice.testng.configuration.TestNGRunnableState) SearchingForTestsTask(com.theoryinpractice.testng.configuration.SearchingForTestsTask) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Module(com.intellij.openapi.module.Module) Computable(com.intellij.openapi.util.Computable)

Example 4 with TestNGConfiguration

use of com.theoryinpractice.testng.configuration.TestNGConfiguration in project kotlin by JetBrains.

the class KotlinTestNgConfigurationProducer method onFirstRun.

@Override
public void onFirstRun(ConfigurationFromContext configuration, ConfigurationContext context, Runnable startRunnable) {
    KtNamedDeclaration declarationToRun = getDeclarationToRun(configuration.getSourceElement());
    final PsiNamedElement lightElement = CollectionsKt.firstOrNull(LightClassUtilsKt.toLightElements(declarationToRun));
    // Copied from TestNGInClassConfigurationProducer.onFirstRun()
    if (lightElement instanceof PsiMethod || lightElement instanceof PsiClass) {
        PsiMethod psiMethod;
        PsiClass containingClass;
        if (lightElement instanceof PsiMethod) {
            psiMethod = (PsiMethod) lightElement;
            containingClass = psiMethod.getContainingClass();
        } else {
            psiMethod = null;
            containingClass = (PsiClass) lightElement;
        }
        InheritorChooser inheritorChooser = new InheritorChooser() {

            @Override
            protected void runForClasses(List<PsiClass> classes, PsiMethod method, ConfigurationContext context, Runnable performRunnable) {
                ((TestNGConfiguration) context.getConfiguration().getConfiguration()).bePatternConfiguration(classes, method);
                super.runForClasses(classes, method, context, performRunnable);
            }

            @Override
            protected void runForClass(PsiClass aClass, PsiMethod psiMethod, ConfigurationContext context, Runnable performRunnable) {
                if (lightElement instanceof PsiMethod) {
                    Project project = psiMethod.getProject();
                    MethodLocation methodLocation = new MethodLocation(project, psiMethod, PsiLocation.fromPsiElement(aClass));
                    ((TestNGConfiguration) context.getConfiguration().getConfiguration()).setMethodConfiguration(methodLocation);
                } else {
                    ((TestNGConfiguration) context.getConfiguration().getConfiguration()).setClassConfiguration(aClass);
                }
                super.runForClass(aClass, psiMethod, context, performRunnable);
            }
        };
        if (inheritorChooser.runMethodInAbstractClass(context, startRunnable, psiMethod, containingClass, new Condition<PsiClass>() {

            @Override
            public boolean value(PsiClass aClass) {
                return aClass.hasModifierProperty(PsiModifier.ABSTRACT) && TestNGUtil.hasTest(aClass);
            }
        }))
            return;
    }
    super.onFirstRun(configuration, context, startRunnable);
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) TestNGConfiguration(com.theoryinpractice.testng.configuration.TestNGConfiguration) InheritorChooser(com.intellij.execution.junit.InheritorChooser) Project(com.intellij.openapi.project.Project) List(java.util.List) MethodLocation(com.intellij.execution.junit2.info.MethodLocation)

Aggregations

TestNGConfiguration (com.theoryinpractice.testng.configuration.TestNGConfiguration)4 Project (com.intellij.openapi.project.Project)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 NotNull (org.jetbrains.annotations.NotNull)2 Executor (com.intellij.execution.Executor)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 InheritorChooser (com.intellij.execution.junit.InheritorChooser)1 MethodLocation (com.intellij.execution.junit2.info.MethodLocation)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 AbstractTestProxy (com.intellij.execution.testframework.AbstractTestProxy)1 SourceScope (com.intellij.execution.testframework.SourceScope)1 Module (com.intellij.openapi.module.Module)1 Computable (com.intellij.openapi.util.Computable)1 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1 SearchingForTestsTask (com.theoryinpractice.testng.configuration.SearchingForTestsTask)1 TestNGRunnableState (com.theoryinpractice.testng.configuration.TestNGRunnableState)1 TestClassFilter (com.theoryinpractice.testng.model.TestClassFilter)1 List (java.util.List)1