/plugins/maven/src/test/java/org/jetbrains/idea/maven/tasks/MavenShortcutsManagerTest.java

https://bitbucket.org/nbargnesi/idea · Java · 217 lines · 157 code · 45 blank · 15 comment · 0 complexity · 9b7d43bcaf0739acd7af72a1a362ace6 MD5 · raw file

  1. /*
  2. * Copyright 2000-2009 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.jetbrains.idea.maven.tasks;
  17. import com.intellij.openapi.actionSystem.ActionManager;
  18. import com.intellij.openapi.command.WriteCommandAction;
  19. import com.intellij.openapi.vfs.VirtualFile;
  20. import org.jetbrains.idea.maven.MavenImportingTestCase;
  21. import java.util.Arrays;
  22. import java.util.List;
  23. public class MavenShortcutsManagerTest extends MavenImportingTestCase {
  24. private MavenShortcutsManager myShortcutsManager;
  25. @Override
  26. protected void setUp() throws Exception {
  27. super.setUp();
  28. myShortcutsManager = MavenShortcutsManager.getInstance(myProject);
  29. myShortcutsManager.doInit();
  30. initProjectsManager(true);
  31. }
  32. public void testRefreshingActionsOnImport() throws Exception {
  33. assertTrue(getProjectActions().isEmpty());
  34. VirtualFile p1 = createModulePom("p1", "<groupId>test</groupId>" +
  35. "<artifactId>p1</artifactId>" +
  36. "<version>1</version>");
  37. VirtualFile p2 = createModulePom("p2", "<groupId>test</groupId>" +
  38. "<artifactId>p2</artifactId>" +
  39. "<version>1</version>");
  40. importProjects(p1, p2);
  41. assertKeymapContains(p1, "clean");
  42. assertKeymapContains(p2, "clean");
  43. }
  44. public void testRefreshingOnProjectRead() throws Exception {
  45. importProject("<groupId>test</groupId>" +
  46. "<artifactId>project</artifactId>" +
  47. "<version>1</version>");
  48. assertKeymapContains(myProjectPom, "clean");
  49. importProject("<groupId>test</groupId>" +
  50. "<artifactId>project</artifactId>" +
  51. "<version>1</version>" +
  52. "<build>" +
  53. " <plugins>" +
  54. " <plugin>" +
  55. " <groupId>org.apache.maven.plugins</groupId>" +
  56. " <artifactId>maven-surefire-plugin</artifactId>" +
  57. " </plugin>" +
  58. " </plugins>" +
  59. "</build>");
  60. assertKeymapContains(myProjectPom, "clean");
  61. }
  62. public void testRefreshingOnPluginResolve() throws Exception {
  63. importProject("<groupId>test</groupId>" +
  64. "<artifactId>project</artifactId>" +
  65. "<version>1</version>");
  66. assertKeymapDoesNotContain(myProjectPom, "org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test");
  67. importProject("<groupId>test</groupId>" +
  68. "<artifactId>project</artifactId>" +
  69. "<version>1</version>" +
  70. "<build>" +
  71. " <plugins>" +
  72. " <plugin>" +
  73. " <groupId>org.apache.maven.plugins</groupId>" +
  74. " <artifactId>maven-surefire-plugin</artifactId>" +
  75. " <version>2.4.3</version>" +
  76. " </plugin>" +
  77. " </plugins>" +
  78. "</build>");
  79. resolvePlugins();
  80. assertKeymapContains(myProjectPom, "org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test");
  81. }
  82. public void testActionWhenSeveralSimilarPlugins() throws Exception {
  83. importProject("<groupId>test</groupId>" +
  84. "<artifactId>project</artifactId>" +
  85. "<version>1</version>");
  86. importProject("<groupId>test</groupId>" +
  87. "<artifactId>project</artifactId>" +
  88. "<version>1</version>" +
  89. "<build>" +
  90. " <plugins>" +
  91. " <plugin>" +
  92. " <groupId>org.apache.maven.plugins</groupId>" +
  93. " <artifactId>maven-surefire-plugin</artifactId>" +
  94. " <version>2.4.3</version>" +
  95. " </plugin>" +
  96. " <plugin>" +
  97. " <groupId>org.apache.maven.plugins</groupId>" +
  98. " <artifactId>maven-surefire-plugin</artifactId>" +
  99. " <version>2.4.3</version>" +
  100. " </plugin>" +
  101. " </plugins>" +
  102. "</build>");
  103. resolvePlugins();
  104. assertKeymapContains(myProjectPom, "org.apache.maven.plugins:maven-surefire-plugin:2.4.3:test");
  105. }
  106. public void testRefreshingOnProjectAddition() throws Exception {
  107. importProject("<groupId>test</groupId>" +
  108. "<artifactId>project</artifactId>" +
  109. "<version>1</version>");
  110. VirtualFile m = createModulePom("module", "<groupId>test</groupId>" +
  111. "<artifactId>module</artifactId>" +
  112. "<version>1</version>");
  113. assertKeymapDoesNotContain(m, "clean");
  114. createProjectPom("<groupId>test</groupId>" +
  115. "<artifactId>project</artifactId>" +
  116. "<version>1</version>" +
  117. "<modules>" +
  118. " <module>module</module>" +
  119. "</modules>");
  120. waitForReadingCompletion();
  121. assertKeymapContains(m, "clean");
  122. }
  123. public void testDeletingActionOnProjectRemoval() throws Exception {
  124. final VirtualFile p1 = createModulePom("p1", "<groupId>test</groupId>" +
  125. "<artifactId>p1</artifactId>" +
  126. "<version>1</version>");
  127. VirtualFile p2 = createModulePom("p2", "<groupId>test</groupId>" +
  128. "<artifactId>p2</artifactId>" +
  129. "<version>1</version>");
  130. importProjects(p1, p2);
  131. assertKeymapContains(p1, "clean");
  132. assertKeymapContains(p2, "clean");
  133. new WriteCommandAction.Simple(myProject) {
  134. @Override
  135. protected void run() throws Throwable {
  136. p1.delete(this);
  137. }
  138. }.execute().throwException();
  139. waitForReadingCompletion();
  140. assertKeymapDoesNotContain(p1, "clean");
  141. assertKeymapContains(p2, "clean");
  142. }
  143. public void testRefreshingActionsOnChangingIgnoreFlag() throws Exception {
  144. VirtualFile p1 = createModulePom("p1", "<groupId>test</groupId>" +
  145. "<artifactId>p1</artifactId>" +
  146. "<version>1</version>");
  147. VirtualFile p2 = createModulePom("p2", "<groupId>test</groupId>" +
  148. "<artifactId>p2</artifactId>" +
  149. "<version>1</version>");
  150. importProjects(p1, p2);
  151. assertKeymapContains(p1, "clean");
  152. assertKeymapContains(p2, "clean");
  153. myProjectsManager.setIgnoredState(Arrays.asList(myProjectsManager.findProject(p1)), true);
  154. assertKeymapDoesNotContain(p1, "clean");
  155. assertKeymapContains(p2, "clean");
  156. myProjectsManager.setIgnoredState(Arrays.asList(myProjectsManager.findProject(p1)), false);
  157. assertKeymapContains(p1, "clean");
  158. assertKeymapContains(p2, "clean");
  159. }
  160. private void assertKeymapContains(VirtualFile pomFile, String goal) {
  161. String id = myShortcutsManager.getActionId(pomFile.getPath(), goal);
  162. assertContain(getProjectActions(), id);
  163. }
  164. private void assertKeymapDoesNotContain(VirtualFile pomFile, String goal) {
  165. String id = myShortcutsManager.getActionId(pomFile.getPath(), goal);
  166. assertDoNotContain(getProjectActions(), id);
  167. }
  168. private List<String> getProjectActions() {
  169. String prefix = MavenKeymapExtension.getActionPrefix(myProject, null);
  170. return Arrays.asList(ActionManager.getInstance().getActionIds(prefix));
  171. }
  172. }