PageRenderTime 195ms CodeModel.GetById 172ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

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

#
Java | 259 lines | 180 code | 60 blank | 19 comment | 0 complexity | a540cb9b01566992aff44f85f57e3173 MD5 | raw file
  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 */
 14package xml.gui;
 15
 16// {{{ jUnit imports 
 17import java.util.concurrent.TimeUnit;
 18
 19import org.junit.*;
 20import static org.junit.Assert.*;
 21import static org.junit.Assume.*;
 22
 23import org.fest.swing.fixture.*;
 24import org.fest.swing.core.*;
 25import org.fest.swing.data.TableCell;
 26import org.fest.swing.finder.*;
 27import org.fest.swing.edt.*;
 28import org.fest.swing.timing.*;
 29import org.fest.swing.core.matcher.JButtonMatcher;
 30
 31import static org.fest.assertions.Assertions.*;
 32
 33import org.gjt.sp.jedit.testframework.Log;
 34
 35import static org.gjt.sp.jedit.testframework.TestUtils.*;
 36import static org.gjt.sp.jedit.testframework.EBFixture.*;
 37import org.gjt.sp.jedit.testframework.PluginOptionsFixture;
 38import org.gjt.sp.jedit.testframework.TestUtils;
 39
 40// }}}
 41
 42import org.gjt.sp.jedit.jEdit;
 43import org.gjt.sp.jedit.EBMessage;
 44import org.gjt.sp.jedit.textarea.JEditTextArea;
 45import org.gjt.sp.jedit.Buffer;
 46
 47import java.io.*;
 48import java.util.regex.Pattern;
 49import javax.swing.text.*;
 50import javax.swing.*;
 51
 52import java.awt.event.KeyEvent;
 53import java.awt.event.InputEvent;
 54import org.gjt.sp.jedit.gui.CompletionPopup;
 55
 56/**
 57 * unit tests for VFSFileTextField
 58 * $Id: VFSFileTextFieldTest.java 21325 2012-03-11 11:03:44Z kerik-sf $
 59 */
 60public class VFSFileTextFieldTest{
 61	private static File testData;
 62	
 63    @BeforeClass
 64    public static void setUpjEdit() throws IOException{
 65        TestUtils.beforeClass();
 66        testData = new File(System.getProperty("test_data")).getCanonicalFile();
 67        assertTrue(testData.exists());
 68    }
 69    
 70    @AfterClass
 71    public static void tearDownjEdit() {
 72        TestUtils.afterClass();
 73    }
 74    
 75    @Test
 76    public void testEnabledDisabled() throws IOException{
 77    	
 78    	final VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
 79    	selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
 80    	
 81    	final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
 82    	frame.show();
 83    	
 84		frame.textBox("xml.translate.output.prompt").requireEnabled();
 85		frame.button("xml.translate.output.select").requireEnabled();
 86		
 87		GuiActionRunner.execute(new GuiTask(){
 88				protected void executeInEDT(){
 89					selector.setEnabled(false);
 90				}
 91		});
 92		frame.textBox("xml.translate.output.prompt").requireDisabled();
 93		frame.button("xml.translate.output.select").requireDisabled();
 94		
 95		GuiActionRunner.execute(new GuiTask(){
 96				protected void executeInEDT(){
 97					selector.setEnabled(true);
 98				}
 99		});
100		frame.textBox("xml.translate.output.prompt").requireEnabled();
101		frame.button("xml.translate.output.select").requireEnabled();
102
103		frame.close();
104    }
105    
106    
107    @Test
108    public void testAPI() throws IOException{
109    	final File f = new File(testData, "simple/actions.xml");
110    	
111    	final VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
112    	selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
113    	
114    	final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
115    	frame.show();
116    	
117		GuiActionRunner.execute(new GuiTask(){
118				protected void executeInEDT(){
119					selector.setFile(jEdit.getProperty("xml.translate.output.browse.prompt"));
120				}
121		});
122		
123		assertFalse(selector.isFileDefined());
124		
125		GuiActionRunner.execute(new GuiTask(){
126				protected void executeInEDT(){
127					selector.setFile(f.getPath());
128				}
129		});
130		frame.textBox("xml.translate.output.prompt").requireText(f.getPath());
131		assertTrue(selector.isFileDefined());
132
133		frame.close();
134    }
135
136    @Test
137    public void testOpenFile(){
138    	final File f = new File(testData, "simple/actions.xml");
139    	VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
140    	selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
141    	
142		assumeTrue(!view().getBuffer().getPath().equals(f.getPath()));
143
144    	final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
145    	frame.show();
146    	
147		GuiActionRunner.execute(new GuiTask(){
148				protected void executeInEDT(){
149					frame.textBox("xml.translate.output.prompt").targetCastedTo(JTextComponent.class).setText(f.getPath());
150				}
151		});
152		
153		frame.textBox("xml.translate.output.prompt").showPopupMenu().menuItemWithPath("Open file").click();
154		
155		assertEquals(f.getPath(),view().getBuffer().getPath());
156		
157		frame.close();
158		jEdit.closeBuffer(view(),view().getBuffer());
159    }
160    
161    @Test
162    public void testSelectSource(){
163    	final File xml = new File(testData, "simple/actions.xml");
164    	File xsd = new File(testData, "simple/actions.xsd");
165    	VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
166    	selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
167    	final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
168     	frame.show();
169   	
170		GuiActionRunner.execute(new GuiTask(){
171				protected void executeInEDT(){
172					frame.textBox("xml.translate.output.prompt").targetCastedTo(JTextComponent.class).setText(xml.getPath());
173				}
174		});
175
176		frame.textBox("xml.translate.output.prompt").showPopupMenu().menuItemWithPath("Select destination").click();
177		
178		DialogFixture browseDialog = findDialogByTitle("File Browser - Open");
179		Pause.pause(1000);
180		browseDialog.button("up").click();
181		Pause.pause(1000);
182		browseDialog.table("file").cell(
183			browseDialog.table("file").cell(xsd.getParentFile().getName())).doubleClick();
184		Pause.pause(1000);
185		browseDialog.table("file").selectCell(
186			browseDialog.table("file").cell(xsd.getName()));
187		browseDialog.button("ok").click();
188
189		frame.textBox("xml.translate.output.prompt").requireText(xsd.getPath());
190		
191		
192		frame.button("xml.translate.output.select").click();
193		
194		browseDialog = findDialogByTitle("File Browser - Open");
195		Pause.pause(1000);
196		browseDialog.button("up").click();
197		Pause.pause(1000);
198		browseDialog.table("file").cell(
199			browseDialog.table("file").cell(xml.getParentFile().getName())).doubleClick();
200		Pause.pause(1000);
201		browseDialog.table("file").selectCell(
202			browseDialog.table("file").cell(xml.getName()));
203		browseDialog.button("ok").click();
204
205		frame.textBox("xml.translate.output.prompt").requireText(xml.getPath());
206		
207		frame.close();
208		jEdit.closeBuffer(view(),view().getBuffer());
209    }
210
211    @Test
212    public void testEnterNotEverywhere(){
213    	final File f = new File(testData, "simple/actions.xml");
214    	File xsd = new File(testData, "simple/actions.xsd");
215
216    	VFSFileTextField selector = new VFSFileTextField(view(),"xml.translate.output");
217    	selector.setBorder(BorderFactory.createEmptyBorder(20,20,20,20));
218    	
219		assumeTrue(!view().getBuffer().getPath().equals(f.getPath()));
220
221    	final FrameFixture frame = new FrameFixture(TestUtils.robot(),Containers.frameFor(selector));
222    	frame.show();
223    	
224		GuiActionRunner.execute(new GuiTask(){
225				protected void executeInEDT(){
226					frame.textBox("xml.translate.output.prompt").targetCastedTo(JTextComponent.class).setText(f.getPath());
227				}
228		});
229		
230		frame.textBox("xml.translate.output.prompt").pressAndReleaseKeys(KeyEvent.VK_ENTER);
231		
232		assertEquals(f.getPath(),view().getBuffer().getPath());
233		
234		TestUtils.openFile(xsd.getPath());
235
236		
237		frame.close();
238		new Thread(){
239			public void run(){
240				action("goto-line");
241		}}.start();
242		Pause.pause(1000);
243		final DialogFixture browseDialog = findDialogByTitle("Go To Line");
244		
245		GuiActionRunner.execute(new GuiTask(){
246				protected void executeInEDT(){
247					browseDialog.textBox().targetCastedTo(JTextComponent.class).setText("2");
248				}
249		});
250		
251		browseDialog.textBox().pressAndReleaseKeys(KeyEvent.VK_ENTER);
252		
253		assertEquals(xsd.getPath(),view().getBuffer().getPath());
254		
255		jEdit.closeBuffer(view(),view().getBuffer());
256		jEdit.closeBuffer(view(),view().getBuffer());
257    }
258
259}