use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-community by JetBrains.
the class ConfigurationsTest method testCreateFromContext.
@Test
public void testCreateFromContext() {
final Project project = myProjectFixture.getProject();
final PsiClass psiClass = findTestClass(project);
final TestNGInClassConfigurationProducer producer = new TestNGInClassConfigurationProducer();
final MapDataContext dataContext = new MapDataContext();
dataContext.put(CommonDataKeys.PROJECT, project);
dataContext.put(LangDataKeys.MODULE, ModuleUtil.findModuleForPsiElement(psiClass));
dataContext.put(Location.DATA_KEY, PsiLocation.fromPsiElement(psiClass));
final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
assert fromContext != null;
final RunnerAndConfigurationSettings config = fromContext.getConfigurationSettings();
final RunConfiguration runConfiguration = config.getConfiguration();
Assert.assertTrue(runConfiguration instanceof TestNGConfiguration);
TestNGConfigurationType t = (TestNGConfigurationType) runConfiguration.getType();
Assert.assertTrue(t.isConfigurationByLocation(runConfiguration, new PsiLocation(project, psiClass)));
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-community by JetBrains.
the class PyTestCase method createRunConfigurationFromContext.
/**
* Creates run configuration from right click menu
*
* @param fixture test fixture
* @param expectedClass expected class of run configuration
* @param <C> expected class of run configuration
* @return configuration (if created) or null (otherwise)
*/
@Nullable
public static <C extends RunConfiguration> C createRunConfigurationFromContext(@NotNull final CodeInsightTestFixture fixture, @NotNull final Class<C> expectedClass) {
final DataContext context = DataManager.getInstance().getDataContext(fixture.getEditor().getComponent());
for (final RunConfigurationProducer<?> producer : RunConfigurationProducer.EP_NAME.getExtensions()) {
final ConfigurationFromContext fromContext = producer.createConfigurationFromContext(ConfigurationContext.getFromContext(context));
if (fromContext == null) {
continue;
}
final C result = PyUtil.as(fromContext.getConfiguration(), expectedClass);
if (result != null) {
return result;
}
}
return null;
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-plugins by JetBrains.
the class CfmlRunConfigurationTest method getDefaultCfmlRunConfiguration.
public CfmlRunConfiguration getDefaultCfmlRunConfiguration() throws IOException {
final Project project = myFixture.getProject();
final Editor editor = openCfmFileInEditor(indexCfm);
final Presentation presentation = getPresentationForRunAction(editor);
assert editor != null;
final DataContext dataContext = DataManager.getInstance().getDataContext(editor.getComponent());
TestCase.assertEquals("Run 'index.cfm'", presentation.getText());
final ConfigurationContext configurationContext = ConfigurationContext.getFromContext(dataContext);
final List<RunConfigurationProducer<?>> producers = RunConfigurationProducer.getProducers(project);
List<ConfigurationFromContext> configs = new ArrayList<>();
for (RunConfigurationProducer<?> producer : producers) {
final ConfigurationFromContext configurationFromContext = producer.createConfigurationFromContext(configurationContext);
if (configurationFromContext != null)
configs.add(configurationFromContext);
}
TestCase.assertEquals(true, configs.size() == 1);
final ConfigurationFromContext defaultConfigurationFromContext = configs.get(0);
final RunConfiguration configuration = defaultConfigurationFromContext.getConfiguration();
TestCase.assertNotNull(configuration);
UsefulTestCase.assertInstanceOf(configuration, CfmlRunConfiguration.class);
return (CfmlRunConfiguration) configuration;
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij-plugins by JetBrains.
the class JstdAssertionFrameworkLineMarkerProvider method execute.
private static void execute(@NotNull Executor executor, @NotNull final PsiElement element) {
Project project = element.getProject();
Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
if (editor == null) {
return;
}
DataContext dataContext = createDataContext(editor, element);
RunConfigurationProducer jstdOriginalProducer = getJstdRunConfigurationProducer();
ConfigurationContext context = ConfigurationContext.getFromContext(dataContext);
boolean created = false;
RunnerAndConfigurationSettings configuration = jstdOriginalProducer.findExistingConfiguration(context);
if (configuration == null) {
created = true;
ConfigurationFromContext fromContext = jstdOriginalProducer.createConfigurationFromContext(context);
if (fromContext != null) {
configuration = fromContext.getConfigurationSettings();
} else {
return;
}
}
execute(project, executor, configuration, created);
}
use of com.intellij.execution.actions.ConfigurationFromContext in project intellij by bazelbuild.
the class BlazeBuildFileRunConfigurationProducerTest method testProducedWhenInsideFuncallExpression.
@Test
public void testProducedWhenInsideFuncallExpression() {
PsiFile buildFile = workspace.createPsiFile(new WorkspacePath("java/com/google/test/BUILD"), "java_test(name='unit_tests'");
StringLiteral nameString = PsiUtils.findFirstChildOfClassRecursive(buildFile, StringLiteral.class);
assertThat(nameString).isNotNull();
ConfigurationContext context = createContextFromPsi(nameString);
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.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//java/com/google/test:unit_tests"));
assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Aggregations