PageRenderTime 380ms CodeModel.GetById 364ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/XML/test/xml/parser/SchemaToCompletionTest.java

#
Java | 138 lines | 101 code | 18 blank | 19 comment | 0 complexity | b0fe4282bef72f0453dcf5cd815f335e MD5 | raw file
  1/*
  2 * RelaxNGCompletionTest.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.parser;
 15
 16// {{{ jUnit imports 
 17import java.util.concurrent.TimeUnit;
 18
 19import org.junit.*;
 20import static org.junit.Assert.*;
 21
 22import org.fest.swing.fixture.*;
 23import org.fest.swing.core.*;
 24import org.fest.swing.finder.*;
 25import org.fest.swing.edt.*;
 26import org.fest.swing.timing.*;
 27
 28import static org.fest.assertions.Assertions.*;
 29
 30import org.gjt.sp.jedit.testframework.Log;
 31import org.gjt.sp.jedit.testframework.TestUtils;
 32
 33import static xml.XMLTestUtils.*;
 34// }}}
 35
 36import java.io.*;
 37import java.net.*;
 38import java.util.*;
 39
 40import xml.completion.*;
 41import xml.completion.ElementDecl.AttributeDecl;
 42
 43/**
 44 * $Id: SchemaToCompletionTest.java 18330 2010-08-11 19:53:08Z kerik-sf $
 45 */
 46public class SchemaToCompletionTest{
 47	private static File testData;
 48
 49    @BeforeClass
 50    public static void setUpjEdit() throws IOException{
 51        TestUtils.beforeClass();
 52        testData = new File(System.getProperty("test_data")).getCanonicalFile();
 53        assertTrue(testData.exists());
 54    }
 55
 56    @AfterClass
 57    public static void tearDownjEdit() {
 58        TestUtils.afterClass();
 59    }
 60
 61    @Test
 62    public void testParentRef(){
 63    	File f = new File(testData,"parentRef/actual_table.rng");
 64		
 65    	Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
 66		assertEquals(1,rng.size());
 67		assertTrue(rng.containsKey(""));
 68		CompletionInfo info = rng.get("");
 69		assertEquals(1,info.elementHash.size());
 70		assertThat(info.elementHash.keySet()).containsOnly("doc");
 71		ElementDecl doc = info.elementHash.get("doc");
 72		assertThat(doc.content).contains("table","p");
 73		ElementDecl em = doc.elementHash.get("p").elementHash.get("em");
 74		// true loop in the model mirroring the loop in the schema
 75		assertSame(em, em.elementHash.get("em"));
 76		ElementDecl td = doc.elementHash.get("table").elementHash.get("tr").elementHash.get("td");
 77		assertThat(td.content).containsOnly("em");
 78    }
 79    
 80    @Test
 81    public void testRelaxNG(){
 82    	File f = new File(testData,"../xml/dtds/relaxng.rng");
 83		
 84    	Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
 85		assertEquals(1,rng.size());
 86		assertTrue(rng.containsKey("http://relaxng.org/ns/structure/1.0"));
 87		CompletionInfo info = rng.get("http://relaxng.org/ns/structure/1.0");
 88		assertThat(info.elementHash.keySet()).contains("element");
 89		ElementDecl element = info.elementHash.get("element");
 90		assertThat(element.content).contains("choice");
 91		assertTrue(element.attributeHash.containsKey("name"));
 92		assertTrue(element.attributeHash.containsKey("ns"));
 93		AttributeDecl a = element.attributeHash.get("name");
 94		assertEquals("QName",a.type);
 95    }
 96
 97    @Test
 98    public void testLocate(){
 99    	File f = new File(testData,"../xml/dtds/locate.rng");
100		
101    	Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
102		assertEquals(1,rng.size());
103		assertTrue(rng.containsKey("http://thaiopensource.com/ns/locating-rules/1.0"));
104		CompletionInfo info = rng.get("http://thaiopensource.com/ns/locating-rules/1.0");
105		assertThat(info.elementHash.keySet()).containsOnly("locatingRules");
106		ElementDecl locatingRules = info.elementHash.get("locatingRules");
107		assertTrue(locatingRules.attributeHash.containsKey("base"));
108		assertThat(locatingRules.content).contains("include");
109		ElementDecl include = locatingRules.elementHash.get("include");
110		assertTrue(include.attributeHash.containsKey("base"));
111		AttributeDecl base = include.attributeHash.get("base");
112		assertEquals("http://www.w3.org/XML/1998/namespace",base.namespace);
113		assertEquals("anyURI",base.type);
114		assertFalse(base.required);
115		AttributeDecl rules = include.attributeHash.get("rules");
116		assertEquals("",rules.namespace);
117		assertEquals("anyURI",rules.type);
118		assertTrue(rules.required);
119	}
120	@Test
121	public void testOptionalRef(){
122    	File f = new File(testData,"optionalRef/schema.rng");
123		
124    	Map<String,CompletionInfo> rng = SchemaToCompletion.rngSchemaToCompletionInfo(null,f.getPath(),null,null);
125		assertEquals(1,rng.size());
126		assertTrue(rng.containsKey(""));
127		CompletionInfo info = rng.get("");
128		assertThat(info.elementHash.keySet()).containsOnly("doc");
129		ElementDecl doc = info.elementHash.get("doc");
130		assertTrue(doc.attributeHash.containsKey("inline"));
131		assertFalse(doc.getAttribute("inline").required);
132		assertThat(doc.content).contains("needsinline");
133		ElementDecl e = doc.elementHash.get("needsinline");
134		assertTrue(e.attributeHash.containsKey("inline"));
135		AttributeDecl inline = e.attributeHash.get("inline");
136		assertTrue(inline.required);
137    }
138}