Search in sources :

Example 1 with TestNGTestObject

use of com.theoryinpractice.testng.model.TestNGTestObject 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 2 with TestNGTestObject

use of com.theoryinpractice.testng.model.TestNGTestObject 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 3 with TestNGTestObject

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

the class TestNGConfiguration method checkConfiguration.

@Override
public void checkConfiguration() throws RuntimeConfigurationException {
    final TestNGTestObject testObject = TestNGTestObject.fromConfig(this);
    if (testObject != null) {
        testObject.checkConfiguration();
    }
    JavaRunConfigurationExtensionManager.checkConfigurationIsValid(this);
    ProgramParametersUtil.checkWorkingDirectoryExist(this, getProject(), getConfigurationModule().getModule());
    JavaParametersUtil.checkAlternativeJRE(this);
//TODO add various checks here
}
Also used : TestNGTestObject(com.theoryinpractice.testng.model.TestNGTestObject)

Example 4 with TestNGTestObject

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

the class DetectClassesToRunTest method doTestClassConfiguration.

private void doTestClassConfiguration(PsiClass aClass) throws CantRunException {
    final TestNGConfiguration configuration = new TestNGConfiguration("TestA", getProject(), TestNGConfigurationType.getInstance().getConfigurationFactories()[0]);
    final TestData data = configuration.getPersistantData();
    data.TEST_OBJECT = TestType.CLASS.getType();
    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);
    assertEquals(1, classes.size());
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) TestNGTestObject(com.theoryinpractice.testng.model.TestNGTestObject) PsiClass(com.intellij.psi.PsiClass) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with TestNGTestObject

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

the class DetectClassesToRunTest method doTestPackageConfiguration.

private void doTestPackageConfiguration(PsiClass... containingClasses) throws CantRunException {
    final TestNGConfiguration configuration = new TestNGConfiguration("p", getProject(), TestNGConfigurationType.getInstance().getConfigurationFactories()[0]);
    final TestData data = configuration.getPersistantData();
    data.TEST_OBJECT = TestType.PACKAGE.getType();
    data.PACKAGE_NAME = "p";
    data.setScope(TestSearchScope.WHOLE_PROJECT);
    final TestNGTestObject testObject = TestNGTestObject.fromConfig(configuration);
    assertNotNull(testObject);
    final LinkedHashMap<PsiClass, Map<PsiMethod, List<String>>> classes = new LinkedHashMap<>();
    testObject.fillTestObjects(classes);
    assertContainsElements(classes.keySet(), containingClasses);
    for (PsiClass psiClass : containingClasses) {
        assertEmpty(classes.get(psiClass).keySet());
    }
}
Also used : TestData(com.theoryinpractice.testng.model.TestData) TestNGTestObject(com.theoryinpractice.testng.model.TestNGTestObject) PsiClass(com.intellij.psi.PsiClass) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TestNGTestObject (com.theoryinpractice.testng.model.TestNGTestObject)5 TestData (com.theoryinpractice.testng.model.TestData)4 PsiClass (com.intellij.psi.PsiClass)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 Module (com.intellij.openapi.module.Module)1 PsiElement (com.intellij.psi.PsiElement)1 PsiMethod (com.intellij.psi.PsiMethod)1 List (java.util.List)1