Search in sources :

Example 21 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazeJavaTestClassConfigurationProducerTest method testProducedFromPsiClassWithInnerTestClass.

@Test
public void testProducedFromPsiClassWithInnerTestClass() throws Throwable {
    PsiFile javaFile = createAndIndexFile(new WorkspacePath("java/com/google/test/OuterClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.Suite.class)", "@org.junit.runners.Suite.SuiteClasses({OuterClass.InnerClass.class})", "public class OuterClass {", "  @org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "  public static class InnerClass {", "    @org.junit.Test", "    public void testMethod1() {}", "    @org.junit.Test", "    public void testMethod2() {}", "  }", "}");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:OuterClass").addSource(sourceRoot("java/com/google/test/OuterClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
    assertThat(javaClass).isNotNull();
    ConfigurationContext context = createContextFromPsi(javaClass);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:OuterClass"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=\"com.google.test.OuterClass#|com.google.test.OuterClass.InnerClass#\"");
    assertThat(config.getName()).isEqualTo("Blaze test OuterClass");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 22 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class MultipleJavaClassesTestContextProviderTest method testNotProducedFromDirectoryWithoutTests.

@Test
public void testNotProducedFromDirectoryWithoutTests() {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_binary").setLabel("//java/com/google/other:BinaryClass").addSource(sourceRoot("java/com/google/other/BinaryClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/other"));
    ConfigurationContext context = createContextFromPsi(directory);
    ConfigurationFromContext fromContext = new TestContextRunConfigurationProducer().createConfigurationFromContext(context);
    assertThat(fromContext).isNotNull();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/other/...:all"));
    assertThat(getTestFilterContents(config)).isNull();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiDirectory(com.intellij.psi.PsiDirectory) TestContextRunConfigurationProducer(com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 23 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class MultipleJavaClassesTestContextProviderTest method testProducedFromDirectoryWithNestedTests.

@Test
public void testProducedFromDirectoryWithNestedTests() throws Throwable {
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test/sub:TestClass").addSource(sourceRoot("java/com/google/test/sub/TestClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PsiDirectory directory = workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
    createAndIndexFile(new WorkspacePath("java/com/google/test/sub/TestClass.java"), "package com.google.test.sub;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    ConfigurationContext context = createContextFromPsi(directory);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(TestContextRunConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTargets()).containsExactly(TargetExpression.fromStringSafe("//java/com/google/test/sub:TestClass"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test");
    assertThat(config.getName()).isEqualTo("Blaze test all in directory 'test'");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PsiDirectory(com.intellij.psi.PsiDirectory) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 24 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazeJavaAbstractTestCaseConfigurationProducerTest method testIgnoreAbstractTestClassWithNoTestSubclasses.

@Test
public void testIgnoreAbstractTestClassWithNoTestSubclasses() throws Throwable {
    PsiFile javaFile = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public abstract class TestClass {", "  @org.junit.Test", "  public void testMethod1() {}", "  @org.junit.Test", "  public void testMethod2() {}", "}");
    PsiClass javaClass = ((PsiClassOwner) javaFile).getClasses()[0];
    assertThat(javaClass).isNotNull();
    ConfigurationContext context = createContextFromPsi(javaClass);
    ConfigurationFromContext fromContext = new BlazeJavaAbstractTestCaseConfigurationProducer().createConfigurationFromContext(context);
    assertThat(fromContext).isNull();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) Test(org.junit.Test)

Example 25 with ConfigurationFromContext

use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.

the class BlazeJavaAbstractTestCaseConfigurationProducerTest method testHandlesNonAbstractClassWithTestSubclass.

@Test
public void testHandlesNonAbstractClassWithTestSubclass() throws Throwable {
    workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
    PsiFile superClassFile = createAndIndexFile(new WorkspacePath("java/com/google/test/NonAbstractSuperClassTestCase.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class NonAbstractSuperClassTestCase {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "import com.google.test.NonAbstractSuperClassTestCase;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass extends NonAbstractSuperClassTestCase {", "  @org.junit.Test", "  public void anotherTestMethod() {}", "}");
    PsiClass javaClass = ((PsiClassOwner) superClassFile).getClasses()[0];
    assertThat(javaClass).isNotNull();
    ConfigurationContext context = createContextFromPsi(superClassFile);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazeJavaAbstractTestCaseConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getSourceElement()).isEqualTo(javaClass);
    RunConfiguration config = fromContext.getConfiguration();
    assertThat(config).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) config;
    assertThat(blazeConfig.getTargets()).isEmpty();
    assertThat(blazeConfig.getName()).isEqualTo("Choose subclass for NonAbstractSuperClassTestCase");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)76 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)69 Test (org.junit.Test)61 PsiFile (com.intellij.psi.PsiFile)56 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)54 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)50 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)38 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)38 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)13 PsiClass (com.intellij.psi.PsiClass)13 PsiDirectory (com.intellij.psi.PsiDirectory)10 PyFunction (com.jetbrains.python.psi.PyFunction)8 PsiElement (com.intellij.psi.PsiElement)6 TestContextRunConfigurationProducer (com.google.idea.blaze.base.run.producers.TestContextRunConfigurationProducer)4 DataContext (com.intellij.openapi.actionSystem.DataContext)4 Project (com.intellij.openapi.project.Project)4 FuncallExpression (com.google.idea.blaze.base.lang.buildfile.psi.FuncallExpression)3 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)3 BallerinaApplicationConfiguration (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationConfiguration)3 BallerinaApplicationRunConfigurationProducer (org.ballerinalang.plugins.idea.runconfig.application.BallerinaApplicationRunConfigurationProducer)3