Java Code Examples for com.intellij.execution.actions.ConfigurationContext#getConfigurationsFromContext()

The following examples show how to use com.intellij.execution.actions.ConfigurationContext#getConfigurationsFromContext() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlazeBuildFileRunConfigurationProducerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testTestSuiteMacroNameRecognized() {
  PsiFile buildFile =
      workspace.createPsiFile(
          new WorkspacePath("java/com/google/test/BUILD"),
          "random_junit4_test_suites(name='gen_tests'");

  FuncallExpression target =
      PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class);
  ConfigurationContext context = createContextFromPsi(target);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).hasSize(1);

  ConfigurationFromContext fromContext = configurations.get(0);
  assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
  assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);

  BlazeCommandRunConfiguration config =
      (BlazeCommandRunConfiguration) fromContext.getConfiguration();
  assertThat(config.getTargets())
      .containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:gen_tests"));
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
 
Example 2
Source File: BlazeBuildFileRunConfigurationProducerTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testProducedFromFuncallExpression() {
  PsiFile buildFile =
      workspace.createPsiFile(
          new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");

  FuncallExpression target =
      PsiUtils.findFirstChildOfClassRecursive(buildFile, FuncallExpression.class);
  assertThat(target).isNotNull();

  ConfigurationContext context = createContextFromPsi(target);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).hasSize(1);

  ConfigurationFromContext fromContext = configurations.get(0);
  assertThat(fromContext.isProducedBy(BlazeBuildFileRunConfigurationProducer.class)).isTrue();
  assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);

  BlazeCommandRunConfiguration config =
      (BlazeCommandRunConfiguration) fromContext.getConfiguration();
  assertThat(config.getTargets())
      .containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
 
Example 3
Source File: AllInPackageTestContextProviderTest.java    From intellij with Apache License 2.0 6 votes vote down vote up
@Test
public void testProducedFromPsiDirectory() {
  setProjectView(
      "directories:", "  java/com/google/test", "targets:", "  //java/com/google/test:lib");
  PsiDirectory directory =
      workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
  workspace.createPsiFile(
      new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");

  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:all"));
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
 
Example 4
Source File: PyBinaryContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testProducedFromPyFile() {
  PsiFile pyFile =
      createAndIndexFile(
          new WorkspacePath("py/bin/main.py"),
          "def main():",
          "  return",
          "if __name__ == '__main__':",
          "  main()");

  workspace.createFile(new WorkspacePath("py/bin/BUILD"), "py_binary(name = 'main')");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("py_binary")
                  .setLabel("//py/bin:main")
                  .addSource(sourceRoot("py/bin/main.py"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(pyFile);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).hasSize(1);

  ConfigurationFromContext fromContext = configurations.get(0);
  assertThat(fromContext.isProducedBy(BinaryContextRunConfigurationProducer.class)).isTrue();
  assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);

  BlazeCommandRunConfiguration config =
      (BlazeCommandRunConfiguration) fromContext.getConfiguration();
  assertThat(config.getTargets())
      .containsExactly(TargetExpression.fromStringSafe("//py/bin:main"));
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
 
Example 5
Source File: GoBinaryContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void contextProducedFromLibraryGoFileIsBinaryTarget() {
  PsiFile goFile =
      createAndIndexFile(new WorkspacePath("foo/bar/main.go"), "package main", "func main() {}");

  MockBlazeProjectDataBuilder builder =
      MockBlazeProjectDataBuilder.builder(workspaceRoot)
          .setTargetMap(
              TargetMapBuilder.builder()
                  .addTarget(
                      TargetIdeInfo.builder()
                          .setKind("go_library")
                          .setLabel("//foo/bar:library")
                          .addSource(sourceRoot("foo/bar/main.go")))
                  .addTarget(
                      TargetIdeInfo.builder()
                          .setKind("go_binary")
                          .setLabel("//foo/bar:main")
                          .addDependency("//foo/bar:library"))
                  .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(goFile);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).isNotNull();
  assertThat(configurations).hasSize(1);

  ConfigurationFromContext fromContext = configurations.get(0);
  assertThat(fromContext.isProducedBy(BinaryContextRunConfigurationProducer.class)).isTrue();
  assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);

  BlazeCommandRunConfiguration config =
      (BlazeCommandRunConfiguration) fromContext.getConfiguration();
  assertThat(config.getTargets())
      .containsExactly(TargetExpression.fromStringSafe("//foo/bar:main"));
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
 
Example 6
Source File: OldJavascriptTestContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static ConfigurationFromContext getConfigurationFromContext(
    ConfigurationContext context) {
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).isNotNull();
  assertThat(configurations).hasSize(1);
  return configurations.get(0);
}
 
Example 7
Source File: BlazeGoTestConfigurationProducerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testProducedFromGoFile() {
  PsiFile goFile =
      createAndIndexFile(
          new WorkspacePath("foo/bar/foo_test.go"),
          "package foo",
          "import \"testing\"",
          "func TestFoo(t *testing.T) {}");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("go_test")
                  .setLabel("//foo/bar:foo_test")
                  .addSource(sourceRoot("foo/bar/foo_test.go"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(goFile);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).isNotNull();
  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("//foo/bar:foo_test"));
  assertThat(getTestFilterContents(config)).isNull();
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
 
Example 8
Source File: GoBinaryContextProviderTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void contextProducedFromBinaryGoFileIsBinaryTarget() {
  PsiFile goFile =
      createAndIndexFile(new WorkspacePath("foo/bar/main.go"), "package main", "func main() {}");

  MockBlazeProjectDataBuilder builder =
      MockBlazeProjectDataBuilder.builder(workspaceRoot)
          .setTargetMap(
              TargetMapBuilder.builder()
                  .addTarget(
                      TargetIdeInfo.builder()
                          .setKind("go_binary")
                          .setLabel("//foo/bar:main")
                          .addSource(sourceRoot("foo/bar/main.go")))
                  .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(goFile);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).isNotNull();
  assertThat(configurations).hasSize(1);

  ConfigurationFromContext fromContext = configurations.get(0);
  assertThat(fromContext.isProducedBy(BinaryContextRunConfigurationProducer.class)).isTrue();
  assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);

  BlazeCommandRunConfiguration config =
      (BlazeCommandRunConfiguration) fromContext.getConfiguration();
  assertThat(config.getTargets())
      .containsExactly(TargetExpression.fromStringSafe("//foo/bar:main"));
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.RUN);
}
 
Example 9
Source File: BlazePyTestConfigurationProducerTest.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Test
public void testProducedFromPyFile() {
  PsiFile pyFile =
      createAndIndexFile(
          new WorkspacePath("py/test/unittest.py"),
          "class UnitTest(googletest.TestCase):",
          "  def testSomething():",
          "    return");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("py_test")
                  .setLabel("//py/test:unittests")
                  .addSource(sourceRoot("py/test/unittest.py"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(pyFile);
  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("//py/test:unittests"));
  assertThat(getTestFilterContents(config)).isNull();
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
  assertThat(config.getName()).isEqualTo("Blaze test unittest.py");
}
 
Example 10
Source File: BlazePyTestConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromTestCaseWithNamedParametersTupleAndUnderscores() {
  PsiFile pyFile =
      createAndIndexFile(
          new WorkspacePath("py/test/unittest.py"),
          "class UnitTest(parameterized.TestCase):",
          "  @parameterized.named_parameters(",
          "    ('First', 1),",
          "    ('_Second', 100),", // intentional underscore
          "  )",
          "  def test_something(self, value):",
          "    return");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("py_test")
                  .setLabel("//py/test:unittests")
                  .addSource(sourceRoot("py/test/unittest.py"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
  assertThat(function).isNotNull();

  ConfigurationContext context = createContextFromPsi(function);
  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("//py/test:unittests"));
  assertThat(getTestFilterContents(config))
      .isEqualTo(
          "--test_filter=\"UnitTest.test_something_First UnitTest.test_something_Second\"");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
  assertThat(config.getName()).isEqualTo("Blaze test UnitTest.test_something (unittest.py)");
}
 
Example 11
Source File: BlazePyTestConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromTestCase() {
  PsiFile pyFile =
      createAndIndexFile(
          new WorkspacePath("py/test/unittest.py"),
          "class UnitTest(googletest.TestCase):",
          "  def testSomething():",
          "    return");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("py_test")
                  .setLabel("//py/test:unittests")
                  .addSource(sourceRoot("py/test/unittest.py"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
  assertThat(function).isNotNull();

  ConfigurationContext context = createContextFromPsi(function);
  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("//py/test:unittests"));
  assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=UnitTest.testSomething");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
  assertThat(config.getName()).isEqualTo("Blaze test UnitTest.testSomething (unittest.py)");
}
 
Example 12
Source File: BlazePyTestConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromTestCaseWithEmptyParametersList() {
  PsiFile pyFile =
      createAndIndexFile(
          new WorkspacePath("py/test/unittest.py"),
          "class UnitTest(parameterized.TestCase):",
          "  @parameterized.parameters()",
          "  def testSomething(self, value):",
          "    return");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("py_test")
                  .setLabel("//py/test:unittests")
                  .addSource(sourceRoot("py/test/unittest.py"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
  assertThat(function).isNotNull();

  ConfigurationContext context = createContextFromPsi(function);
  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("//py/test:unittests"));
  assertThat(getTestFilterContents(config)).isNull();
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
  assertThat(config.getName()).isEqualTo("Blaze test UnitTest.testSomething (unittest.py)");
}
 
Example 13
Source File: MultipleJavaClassesTestContextProviderTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromDirectoryWithNestedTests() throws Exception {
  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);
}
 
Example 14
Source File: MultipleJavaClassesTestContextProviderTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromDirectory() throws Exception {
  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("java_test")
                  .setLabel("//java/com/google/test:TestClass")
                  .addSource(sourceRoot("java/com/google/test/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/TestClass.java"),
      "package com.google.test;",
      "@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: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);
}
 
Example 15
Source File: BlazeJavaTestMethodConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromPsiMethod() {
  // Arrange
  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 class TestClass {",
          "  @org.junit.Test",
          "  public void testMethod1() {}",
          "}");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("java_test")
                  .setLabel("//java/com/google/test:TestClass")
                  .addSource(sourceRoot("java/com/google/test/TestClass.java"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
  PsiMethod method = PsiUtils.findFirstChildOfClassRecursive(javaFile, PsiMethod.class);

  // Act
  ConfigurationContext context = createContextFromPsi(method);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  ConfigurationFromContext fromContext = configurations.get(0);

  // Assert
  assertThat(configurations).hasSize(1);
  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:TestClass"));
  assertThat(getTestFilterContents(config))
      .isEqualTo("--test_filter=com.google.test.TestClass#testMethod1$");
  assertThat(config.getName()).isEqualTo("Blaze test TestClass.testMethod1");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);

  BlazeCommandRunConfigurationCommonState state =
      config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
  assertThat(state.getBlazeFlagsState().getRawFlags()).contains(BlazeFlags.DISABLE_TEST_SHARDING);
}
 
Example 16
Source File: BlazeScalaTestClassConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testScalaTestProducedFromPsiClass() {
  PsiFile file =
      createAndIndexFile(
          WorkspacePath.createIfValid("scala/com/google/test/TestClass.scala"),
          "package com.google.test {",
          "  class TestClass extends org.scalatest.FlatSpec {",
          "    \"this test\" should \"pass\" in {}",
          "  }",
          "}",
          "package org.scalatest {",
          "  trait FlatSpec extends Suite",
          "  trait Suite",
          "}");
  assertThat(file).isInstanceOf(ScalaFile.class);
  ScalaFile scalaFile = (ScalaFile) file;
  PsiClass[] classes = scalaFile.getClasses();
  assertThat(classes).isNotEmpty();
  PsiClass testClass = classes[0];

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("scala_test")
                  .setLabel("//scala/com/google/test:TestClass")
                  .addSource(sourceRoot("scala/com/google/test/TestClass.scala"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(testClass);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).isNotNull();
  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("//scala/com/google/test:TestClass"));
  assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass");
  assertThat(config.getName()).isEqualTo("Blaze test TestClass");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
 
Example 17
Source File: BlazeJavaAbstractTestCaseConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testConfigurationCreatedFromAbstractClass() {
  workspace.createPsiDirectory(new WorkspacePath("java/com/google/test"));
  PsiFile abstractClassFile =
      createAndIndexFile(
          new WorkspacePath("java/com/google/test/AbstractTestCase.java"),
          "package com.google.test;",
          "public abstract class AbstractTestCase {}");

  createAndIndexFile(
      new WorkspacePath("java/com/google/test/TestClass.java"),
      "package com.google.test;",
      "import com.google.test.AbstractTestCase;",
      "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)",
      "public class TestClass extends AbstractTestCase {",
      "  @org.junit.Test",
      "  public void testMethod1() {}",
      "  @org.junit.Test",
      "  public void testMethod2() {}",
      "}");

  PsiClass javaClass = ((PsiClassOwner) abstractClassFile).getClasses()[0];
  assertThat(javaClass).isNotNull();

  ConfigurationContext context = createContextFromPsi(abstractClassFile);
  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 AbstractTestCase");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("java_test")
                  .setLabel("//java/com/google/test:TestClass")
                  .addSource(sourceRoot("java/com/google/test/TestClass.java"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  BlazeJavaAbstractTestCaseConfigurationProducer.chooseSubclass(
      fromContext, context, EmptyRunnable.INSTANCE);

  assertThat(blazeConfig.getTargets())
      .containsExactly(TargetExpression.fromStringSafe("//java/com/google/test:TestClass"));
  assertThat(getTestFilterContents(blazeConfig))
      .isEqualTo(BlazeFlags.TEST_FILTER + "=com.google.test.TestClass#");
}
 
Example 18
Source File: BlazePyTestConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromTestCaseWithParametersList() {
  PsiFile pyFile =
      createAndIndexFile(
          new WorkspacePath("py/test/unittest.py"),
          "class UnitTest(parameterized.TestCase):",
          "  @parameterized.parameters([1,100])",
          "  def testSomething(self, value):",
          "    return");

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("py_test")
                  .setLabel("//py/test:unittests")
                  .addSource(sourceRoot("py/test/unittest.py"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
  assertThat(function).isNotNull();

  ConfigurationContext context = createContextFromPsi(function);
  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("//py/test:unittests"));
  assertThat(getTestFilterContents(config))
      .isEqualTo("--test_filter=\"UnitTest.testSomething0 UnitTest.testSomething1\"");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
  assertThat(config.getName()).isEqualTo("Blaze test UnitTest.testSomething (unittest.py)");
}
 
Example 19
Source File: BlazeJavaTestClassConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testProducedFromPsiFile() {
  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 class TestClass {",
          "  @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:TestClass")
                  .addSource(sourceRoot("java/com/google/test/TestClass.java"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(javaFile);
  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:TestClass"));
  assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
  assertThat(config.getName()).isEqualTo("Blaze test TestClass");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
 
Example 20
Source File: BlazeScalaTestClassConfigurationProducerTest.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Test
public void testJunitTestProducedFromPsiClass() {
  PsiFile file =
      createAndIndexFile(
          new WorkspacePath("scala/com/google/test/TestClass.scala"),
          "package com.google.test {",
          "  class TestClass {",
          "    @org.junit.Test",
          "    def testMethod() {}",
          "  }",
          "}",
          "package org.junit { trait Test }");
  assertThat(file).isInstanceOf(ScalaFile.class);
  ScalaFile scalaFile = (ScalaFile) file;
  PsiClass[] classes = scalaFile.getClasses();
  assertThat(classes).isNotEmpty();
  PsiClass testClass = classes[0];

  MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
  builder.setTargetMap(
      TargetMapBuilder.builder()
          .addTarget(
              TargetIdeInfo.builder()
                  .setKind("scala_junit_test")
                  .setLabel("//scala/com/google/test:TestClass")
                  .addSource(sourceRoot("scala/com/google/test/TestClass.scala"))
                  .build())
          .build());
  registerProjectService(
      BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));

  ConfigurationContext context = createContextFromPsi(testClass);
  List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
  assertThat(configurations).isNotNull();
  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("//scala/com/google/test:TestClass"));
  assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=com.google.test.TestClass#");
  assertThat(config.getName()).isEqualTo("Blaze test TestClass");
  assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}