PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/test/xml/translate/TrangGUITest.java

#
Java | 180 lines | 115 code | 45 blank | 20 comment | 0 complexity | 7af59783de4d67f78886f8651824c5d2 MD5 | raw file
  1/*
  2 * TrangGUITest.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.translate;
 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.Buffer;
 44
 45import java.io.*;
 46import java.util.*;
 47import javax.swing.text.JTextComponent;
 48
 49
 50
 51/**
 52 * unit tests for TrangTranslator
 53 * $Id: TrangGUITest.java 21325 2012-03-11 11:03:44Z kerik-sf $
 54 */
 55public class TrangGUITest{
 56	private static File testData;
 57	
 58    @BeforeClass
 59    public static void setUpjEdit() throws IOException{
 60        TestUtils.beforeClass();
 61        testData = new File(System.getProperty("test_data")).getCanonicalFile();
 62        assertTrue(testData.exists());
 63    }
 64    
 65    @AfterClass
 66    public static void tearDownjEdit() {
 67        TestUtils.afterClass();
 68    }
 69        
 70    @Test
 71    public void testDTDToXSD() throws IOException{
 72    	final File in = new File(testData,"../xml/dtds/oasis-catalog.dtd");
 73    	final File out = new File(testData,"../xml/dtds/oasis-catalog.xsd");
 74    	final File out2 = new File(testData,"../xml/dtds/xml.xsd");
 75    	
 76    	Buffer b = openFile(in.getPath());
 77    	
 78		GuiActionRunner.execute(new GuiTask(){
 79				protected void executeInEDT(){
 80					action("xml-trang-translate");
 81				}
 82		});
 83    	
 84		DialogFixture f = findDialogByTitle("Trang GUI");
 85		
 86		
 87		f.textBox("xml.translate.input.prompt").requireText(in.getPath());
 88		f.comboBox("input-type").requireSelection("dtd");
 89		
 90		f.checkBox("inline-attlist").requireVisible().requireNotSelected();
 91		
 92		f.textBox("xml.translate.output.prompt").requireText(in.getPath());
 93		f.comboBox("output-type").requireSelection("dtd");
 94		
 95		f.comboBox("output-type").selectItem("xsd");
 96		f.checkBox("disable-abstract-elements").requireVisible().requireNotSelected();
 97		f.checkBox("inline-attlist").requireVisible().requireSelected();
 98		
 99		f.textBox("xml.translate.output.prompt").requireText(out.getPath());
100		
101    	ClickT clickT = new ClickT(Option.OK);
102    	clickT.start();
103
104		f.button(JButtonMatcher.withText("OK")).click();
105		
106		clickT.waitForClick();
107		
108    	Buffer outB = jEdit.getBuffer(out.getPath());
109    	assertNotNull(outB);
110    	//inline-attlist
111    	assertFalse(outB.getText(0,outB.getLength())
112    		.contains("<xs:attributeGroup ref=\"ns1:attlist.rewriteURI\"/>"));
113    	
114		GuiActionRunner.execute(new GuiTask(){
115				protected void executeInEDT(){
116					action("xml-trang-translate");
117				}
118		});
119
120    	Pause.pause(1000);
121    	f = new DialogFixture(robot(),robot().finder().findByType(TrangGUI.class));
122
123		f.comboBox("output-type").selectItem("xsd");
124		f.checkBox("inline-attlist").uncheck();
125		
126		clickT = new ClickT(Option.OK);
127    	clickT.start();
128		f.button(JButtonMatcher.withText("OK")).click();
129		clickT.waitForClick();
130    	
131    	assertTrue(outB.getText(0,outB.getLength())
132    		.contains("<xs:attributeGroup ref=\"ns1:attlist.rewriteURI\"/>"));
133
134    	close(view(),outB);
135    	outB = jEdit.getBuffer(out2.getPath());
136    	assertNotNull(outB);
137    	close(view(),outB);
138    	close(view(),b);
139    }
140    
141    @Test
142    public void testInputFormatChange() throws IOException{
143    	final File in1 = new File(testData,"rnc/actions.xml").getCanonicalFile();
144    	final File in2 = new File(testData,"rnc/actions.rnc").getCanonicalFile();
145    	
146    	Buffer b = openFile(in1.getPath());
147    	
148		GuiActionRunner.execute(new GuiTask(){
149				protected void executeInEDT(){
150					action("xml-trang-translate");
151				}
152		});
153    	
154		final DialogFixture f = findDialogByTitle("Trang GUI");
155		
156		
157		f.textBox("xml.translate.input.prompt").requireText(in1.getPath());
158		f.comboBox("input-type").requireSelection("xml");
159		
160		f.button("xml.translate.input.select").click();
161		
162		DialogFixture browseDialog = findDialogByTitle("File Browser - Open");
163		Pause.pause(1000);
164		browseDialog.button("up").click();
165		Pause.pause(1000);
166		browseDialog.table("file").cell(
167			browseDialog.table("file").cell(in1.getParentFile().getName())).doubleClick();
168		Pause.pause(1000);
169		browseDialog.table("file").selectCell(
170			browseDialog.table("file").cell(in2.getName()));
171		browseDialog.button("ok").click();
172
173		Pause.pause(500);
174		f.comboBox("input-type").requireSelection("rnc");
175
176    	f.close();
177    	
178    	close(view(),b);
179    }
180}