/bundles/plugins-trunk/XML/test/xml/CopyXPathTest.java

# · Java · 247 lines · 134 code · 64 blank · 49 comment · 0 complexity · 0daa23a45e8fca0b1674cbe8098b4ac2 MD5 · raw file

  1. /*
  2. * CopyXPathTest.java
  3. * :folding=explicit:collapseFolds=1:
  4. *
  5. * Copyright (C) 2009 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;
  15. // {{{ jUnit imports
  16. import java.util.concurrent.TimeUnit;
  17. import org.junit.*;
  18. import static org.junit.Assert.*;
  19. import org.fest.swing.fixture.*;
  20. import org.fest.swing.core.*;
  21. import org.fest.swing.finder.*;
  22. import org.fest.swing.edt.*;
  23. import org.fest.swing.timing.*;
  24. import static org.fest.assertions.Assertions.*;
  25. import org.gjt.sp.jedit.testframework.Log;
  26. import static xml.XMLTestUtils.*;
  27. import static org.gjt.sp.jedit.testframework.EBFixture.*;
  28. import org.gjt.sp.jedit.testframework.TestUtils;
  29. import static org.gjt.sp.jedit.testframework.TestUtils.*;
  30. // }}}
  31. import org.gjt.sp.jedit.jEdit;
  32. import org.gjt.sp.jedit.EBMessage;
  33. import org.gjt.sp.jedit.textarea.JEditTextArea;
  34. import org.gjt.sp.jedit.Buffer;
  35. import org.gjt.sp.jedit.Registers;
  36. import java.io.*;
  37. import java.awt.event.KeyEvent;
  38. import java.awt.event.InputEvent;
  39. import org.gjt.sp.jedit.gui.CompletionPopup;
  40. /**
  41. * Various tests for the XMLActions actions
  42. * $Id: CopyXPathTest.java 21320 2012-03-11 10:35:05Z kerik-sf $
  43. */
  44. public class CopyXPathTest{
  45. private static File testData;
  46. @BeforeClass
  47. public static void setUpjEdit() throws IOException{
  48. TestUtils.beforeClass();
  49. testData = new File(System.getProperty("test_data")).getCanonicalFile();
  50. assertTrue(testData.exists());
  51. }
  52. @AfterClass
  53. public static void tearDownjEdit() {
  54. TestUtils.afterClass();
  55. }
  56. /**
  57. * same namespace, no prefix : easy !
  58. */
  59. @Test
  60. public void testCopyXPathNoPrefix(){
  61. File xml = new File(testData,"dtd/actions.xml");
  62. TestUtils.openFile(xml.getPath());
  63. // wait for end of parsing
  64. doInBetween(new Runnable(){
  65. public void run(){
  66. action("sidekick-parse",1);
  67. }},
  68. messageOfClassCondition(sidekick.SideKickUpdate.class),
  69. 10000);
  70. Registers.getRegister('$').setValue("NULL");
  71. // before the root element
  72. gotoPositionAndWait(22);
  73. action("xml-copy-xpath");
  74. assertEquals("NULL",Registers.getRegister('$').toString());
  75. // go into the ACTIONS element
  76. gotoPositionAndWait(151);
  77. action("xml-copy-xpath");
  78. assertEquals("/ACTIONS",Registers.getRegister('$').toString());
  79. // go into the second ACTION element
  80. gotoPositionAndWait(325);
  81. action("xml-copy-xpath");
  82. assertEquals("/ACTIONS/ACTION[2]",Registers.getRegister('$').toString());
  83. Registers.getRegister('$').setValue("NULL");
  84. // after the closing tag of the root element
  85. gotoPositionAndWait(431);
  86. action("xml-copy-xpath");
  87. assertEquals("NULL",Registers.getRegister('$').toString());
  88. }
  89. /**
  90. * some tests are failing for now...
  91. */
  92. @Test
  93. public void testCopyXPathWithPrefix(){
  94. File xml = new File(testData,"with_prefix/test.xml");
  95. TestUtils.openFile(xml.getPath());
  96. // wait for end of parsing
  97. doInBetween(new Runnable(){
  98. public void run(){
  99. action("sidekick-parse",1);
  100. }},
  101. messageOfClassCondition(sidekick.SideKickUpdate.class),
  102. 10000);
  103. // go into the b:created element
  104. gotoPositionAndWait(161);
  105. GuiActionRunner.execute(new GuiTask(){
  106. protected void executeInEDT(){
  107. action("xml-copy-xpath");
  108. }
  109. });
  110. assertEquals("/a:document/b:created[1]",Registers.getRegister('$').toString());
  111. // go into the first trap
  112. gotoPositionAndWait(511);
  113. GuiActionRunner.execute(new GuiTask(){
  114. protected void executeInEDT(){
  115. action("xml-copy-xpath");
  116. }
  117. });
  118. assertTrue(Registers.getRegister('$').toString().startsWith("/a:document/"));
  119. assertNotSame("/a:document/a:trap[1]",Registers.getRegister('$').toString());
  120. // go into the 2nd trap
  121. gotoPositionAndWait(774);
  122. GuiActionRunner.execute(new GuiTask(){
  123. protected void executeInEDT(){
  124. action("xml-copy-xpath");
  125. }
  126. });
  127. assertEquals("/a:document/a:trap[1]",Registers.getRegister('$').toString());
  128. // go into the 3rd trap
  129. gotoPositionAndWait(1018);
  130. GuiActionRunner.execute(new GuiTask(){
  131. protected void executeInEDT(){
  132. action("xml-copy-xpath");
  133. }
  134. });
  135. assertEquals("/a:document/a:trap[2]",Registers.getRegister('$').toString());
  136. }
  137. /**
  138. * no exception : only a beep, please !
  139. */
  140. @Test
  141. public void testTextFile(){
  142. File xml = new File(testData,"rnc/actions.rnc");
  143. TestUtils.openFile(xml.getPath());
  144. // wait for end of parsing
  145. parseAndWait();
  146. // set the register to a known value
  147. Registers.getRegister('$').setValue("NULL");
  148. // go into the b:created element
  149. gotoPositionAndWait(161);
  150. ClickT clickT = new ClickT(Option.OK);
  151. clickT.start();
  152. action("xml-copy-xpath");
  153. clickT.waitForClick();
  154. assertEquals("NULL",Registers.getRegister('$').toString());
  155. }
  156. /**
  157. */
  158. @Test
  159. public void testHtmlFile(){
  160. File xml = new File(testData,"html/well_formed.html");
  161. TestUtils.openFile(xml.getPath());
  162. // wait for end of parsing
  163. parseAndWait();
  164. // go into the doctype
  165. gotoPositionAndWait(62);
  166. action("xml-copy-xpath");
  167. assertEquals("NULL",Registers.getRegister('$').toString());
  168. // go into the html
  169. gotoPositionAndWait(117);
  170. action("xml-copy-xpath");
  171. Pause.pause(500);
  172. assertEquals("/html",Registers.getRegister('$').toString());
  173. // go into the css, right into @import, which is a CSS node
  174. gotoPositionAndWait(300);
  175. action("xml-copy-xpath");
  176. // style turns to uppercase in sidekick
  177. assertEquals("/html/head[1]/STYLE[1]",Registers.getRegister('$').toString());
  178. // go into the body (second link)
  179. gotoPositionAndWait(659);
  180. action("xml-copy-xpath");
  181. assertEquals("/html/body[1]/div[2]/p[2]/a[1]",Registers.getRegister('$').toString());
  182. }
  183. }