PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/bundles/plugins-trunk/XML/test/xml/gui/VFSFileTextFieldTest.java

#
Java | 259 lines | 180 code | 60 blank | 19 comment | 0 complexity | a540cb9b01566992aff44f85f57e3173 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * VFSFileTextFieldTest.java
  3. * :folding=explicit:collapseFolds=1:
  4. *
  5. * Copyright (C) 2010 Eric Le Lay
  6. *
  7. * The XML plugin is licensed under the GNU General Public License, with
  8. * the following exception:
  9. *
  10. * "Permission is granted to link this code with software released under
  11. * the Apache license version 1.1, for example used by the Xerces XML
  12. * parser package."
  13. */
  14. package xml.gui;
  15. // {{{ jUnit imports
  16. import java.util.concurrent.TimeUnit;
  17. import org.junit.*;
  18. import static org.junit.Assert.*;
  19. import static org.junit.Assume.*;
  20. import org.fest.swing.fixture.*;
  21. import org.fest.swing.core.*;
  22. import org.fest.swing.data.TableCell;
  23. import org.fest.swing.finder.*;
  24. import org.fest.swing.edt.*;
  25. import org.fest.swing.timing.*;
  26. import org.fest.swing.core.matcher.JButtonMatcher;
  27. import static org.fest.assertions.Assertions.*;
  28. import org.gjt.sp.jedit.testframework.Log;
  29. import static org.gjt.sp.jedit.testframework.TestUtils.*;
  30. import static org.gjt.sp.jedit.testframework.EBFixture.*;
  31. import org.gjt.sp.jedit.testframework.PluginOptionsFixture;
  32. import org.gjt.sp.jedit.testframework.TestUtils;
  33. // }}}
  34. import org.gjt.sp.jedit.jEdit;
  35. import org.gjt.sp.jedit.EBMessage;
  36. import org.gjt.sp.jedit.textarea.JEditTextArea;
  37. import org.gjt.sp.jedit.Buffer;
  38. import java.io.*;
  39. import java.util.regex.Pattern;
  40. import javax.swing.text.*;
  41. import javax.swing.*;
  42. import java.awt.event.KeyEvent;
  43. import java.awt.event.InputEvent;
  44. import org.gjt.sp.jedit.gui.CompletionPopup;
  45. /**
  46. * unit tests for VFSFileTextField
  47. * $Id: VFSFileTextFieldTest.java 21325 2012-03-11 11:03:44Z kerik-sf $
  48. */
  49. public class VFSFileTextFieldTest{
  50. private static File testData;
  51. @BeforeClass
  52. public static void setUpjEdit() throws IOException{
  53. TestUtils.beforeClass();
  54. testData = new File(System.getProperty("test_data")).getCanonicalFile();
  55. assertTrue(testData.exists());
  56. }
  57. @AfterClass
  58. public static void tearDownjEdit() {
  59. TestUtils.afterClass();
  60. }
  61. @Test
  62. public void testEnabledDisabled() throws IOException{
  63. final VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
  64. selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
  65. final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
  66. frame.show();
  67. frame.textBox("xml.translate.output.prompt").requireEnabled();
  68. frame.button("xml.translate.output.select").requireEnabled();
  69. GuiActionRunner.execute(new GuiTask(){
  70. protected void executeInEDT(){
  71. selector.setEnabled(false);
  72. }
  73. });
  74. frame.textBox("xml.translate.output.prompt").requireDisabled();
  75. frame.button("xml.translate.output.select").requireDisabled();
  76. GuiActionRunner.execute(new GuiTask(){
  77. protected void executeInEDT(){
  78. selector.setEnabled(true);
  79. }
  80. });
  81. frame.textBox("xml.translate.output.prompt").requireEnabled();
  82. frame.button("xml.translate.output.select").requireEnabled();
  83. frame.close();
  84. }
  85. @Test
  86. public void testAPI() throws IOException{
  87. final File f = new File(testData, "simple/actions.xml");
  88. final VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
  89. selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
  90. final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
  91. frame.show();
  92. GuiActionRunner.execute(new GuiTask(){
  93. protected void executeInEDT(){
  94. selector.setFile(jEdit.getProperty("xml.translate.output.browse.prompt"));
  95. }
  96. });
  97. assertFalse(selector.isFileDefined());
  98. GuiActionRunner.execute(new GuiTask(){
  99. protected void executeInEDT(){
  100. selector.setFile(f.getPath());
  101. }
  102. });
  103. frame.textBox("xml.translate.output.prompt").requireText(f.getPath());
  104. assertTrue(selector.isFileDefined());
  105. frame.close();
  106. }
  107. @Test
  108. public void testOpenFile(){
  109. final File f = new File(testData, "simple/actions.xml");
  110. VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
  111. selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
  112. assumeTrue(!view().getBuffer().getPath().equals(f.getPath()));
  113. final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
  114. frame.show();
  115. GuiActionRunner.execute(new GuiTask(){
  116. protected void executeInEDT(){
  117. frame.textBox("xml.translate.output.prompt").targetCastedTo(JTextComponent.class).setText(f.getPath());
  118. }
  119. });
  120. frame.textBox("xml.translate.output.prompt").showPopupMenu().menuItemWithPath("Open file").click();
  121. assertEquals(f.getPath(),view().getBuffer().getPath());
  122. frame.close();
  123. jEdit.closeBuffer(view(),view().getBuffer());
  124. }
  125. @Test
  126. public void testSelectSource(){
  127. final File xml = new File(testData, "simple/actions.xml");
  128. File xsd = new File(testData, "simple/actions.xsd");
  129. VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
  130. selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
  131. final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
  132. frame.show();
  133. GuiActionRunner.execute(new GuiTask(){
  134. protected void executeInEDT(){
  135. frame.textBox("xml.translate.output.prompt").targetCastedTo(JTextComponent.class).setText(xml.getPath());
  136. }
  137. });
  138. frame.textBox("xml.translate.output.prompt").showPopupMenu().menuItemWithPath("Select destination").click();
  139. DialogFixture browseDialog = findDialogByTitle("File Browser - Open");
  140. Pause.pause(1000);
  141. browseDialog.button("up").click();
  142. Pause.pause(1000);
  143. browseDialog.table("file").cell(
  144. browseDialog.table("file").cell(xsd.getParentFile().getName())).doubleClick();
  145. Pause.pause(1000);
  146. browseDialog.table("file").selectCell(
  147. browseDialog.table("file").cell(xsd.getName()));
  148. browseDialog.button("ok").click();
  149. frame.textBox("xml.translate.output.prompt").requireText(xsd.getPath());
  150. frame.button("xml.translate.output.select").click();
  151. browseDialog = findDialogByTitle("File Browser - Open");
  152. Pause.pause(1000);
  153. browseDialog.button("up").click();
  154. Pause.pause(1000);
  155. browseDialog.table("file").cell(
  156. browseDialog.table("file").cell(xml.getParentFile().getName())).doubleClick();
  157. Pause.pause(1000);
  158. browseDialog.table("file").selectCell(
  159. browseDialog.table("file").cell(xml.getName()));
  160. browseDialog.button("ok").click();
  161. frame.textBox("xml.translate.output.prompt").requireText(xml.getPath());
  162. frame.close();
  163. jEdit.closeBuffer(view(),view().getBuffer());
  164. }
  165. @Test
  166. public void testEnterNotEverywhere(){
  167. final File f = new File(testData, "simple/actions.xml");
  168. File xsd = new File(testData, "simple/actions.xsd");
  169. VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
  170. selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
  171. assumeTrue(!view().getBuffer().getPath().equals(f.getPath()));
  172. final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
  173. frame.show();
  174. GuiActionRunner.execute(new GuiTask(){
  175. protected void executeInEDT(){
  176. frame.textBox("xml.translate.output.prompt").targetCastedTo(JTextComponent.class).setText(f.getPath());
  177. }
  178. });
  179. frame.textBox("xml.translate.output.prompt").pressAndReleaseKeys(KeyEvent.VK_ENTER);
  180. assertEquals(f.getPath(),view().getBuffer().getPath());
  181. TestUtils.openFile(xsd.getPath());
  182. frame.close();
  183. new Thread(){
  184. public void run(){
  185. action("goto-line");
  186. }}.start();
  187. Pause.pause(1000);
  188. final DialogFixture browseDialog = findDialogByTitle("Go To Line");
  189. GuiActionRunner.execute(new GuiTask(){
  190. protected void executeInEDT(){
  191. browseDialog.textBox().targetCastedTo(JTextComponent.class).setText("2");
  192. }
  193. });
  194. browseDialog.textBox().pressAndReleaseKeys(KeyEvent.VK_ENTER);
  195. assertEquals(xsd.getPath(),view().getBuffer().getPath());
  196. jEdit.closeBuffer(view(),view().getBuffer());
  197. jEdit.closeBuffer(view(),view().getBuffer());
  198. }
  199. }