1 17 package org.apache.geronimo.webservices.builder; 18 19 import java.io.File ; 20 import java.io.IOException ; 21 import java.util.Collection ; 22 import java.util.ArrayList ; 23 import java.util.Map ; 24 import java.util.Iterator ; 25 import java.net.URI ; 26 import java.net.URISyntaxException ; 27 28 import org.apache.geronimo.testsupport.TestSupport; 29 30 import org.apache.xmlbeans.XmlObject; 31 import org.apache.xmlbeans.XmlOptions; 32 import org.apache.xmlbeans.SchemaTypeSystem; 33 import org.apache.xmlbeans.XmlBeans; 34 import org.apache.xmlbeans.XmlException; 35 import org.apache.xmlbeans.SchemaTypeLoader; 36 import org.apache.geronimo.common.DeploymentException; 37 import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil; 38 import org.apache.geronimo.webservices.builder.SchemaInfoBuilder; 39 40 43 public class ParsingTest 44 extends TestSupport 45 { 46 private SchemaInfoBuilder schemaInfoBuilder; 47 48 public void testSchema1() throws Exception { 49 File schema1 = new File (BASEDIR, "src/test/resources/schema/schema1.xsd"); 50 log.debug("SCHEMA 1"); 51 Map map = parse(schema1); 52 assertEquals(13, map.size()); 53 } 54 55 public void testSchema2() throws Exception { 56 File schema1 = new File (BASEDIR, "src/test/resources/schema/schema2.xsd"); 57 log.debug("SCHEMA 2"); 58 Map map = parse(schema1); 59 assertEquals(4, map.size()); 60 } 61 62 public void testSchema3() throws Exception { 63 File schema1 = new File (BASEDIR, "src/test/resources/schema/schema3.xsd"); 64 log.debug("SCHEMA 3"); 65 Map map = parse(schema1); 66 assertEquals(3, map.size()); 67 } 68 69 private Map parse(File schema1) throws IOException , XmlException, DeploymentException, URISyntaxException { 70 XmlObject xmlObject = XmlBeansUtil.parse(schema1.toURL(), getClass().getClassLoader()); 71 Collection errors = new ArrayList (); 72 XmlOptions xmlOptions = new XmlOptions(); 73 xmlOptions.setErrorListener(errors); 74 XmlObject[] schemas = new XmlObject[] {xmlObject}; 75 SchemaTypeLoader schemaTypeLoader = XmlBeans.loadXsd(new XmlObject[] {}); 76 SchemaTypeSystem schemaTypeSystem; 77 try { 78 schemaTypeSystem = XmlBeans.compileXsd(schemas, schemaTypeLoader, xmlOptions); 79 if (errors.size() > 0) { 80 throw new DeploymentException("Could not compile schema type system: errors: " + errors); 81 } 82 } catch (XmlException e) { 83 throw new DeploymentException("Could not compile schema type system", e); 84 } 85 schemaInfoBuilder = new SchemaInfoBuilder(null, new URI (""), schemaTypeSystem); 86 Map map = schemaInfoBuilder.getSchemaTypeKeyToSchemaTypeMap(); 87 for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) { 88 Map.Entry entry = (Map.Entry ) iterator.next(); 89 log.debug(entry.getKey() + " --> " + entry.getValue()); 90 } 91 return map; 92 } 93 94 public void testElementToTypeMapping() throws Exception { 95 File schema1 = new File (BASEDIR, "src/test/resources/schema/schema4.xsd"); 96 log.debug("SCHEMA 4"); 97 Map map = parse(schema1); 98 assertEquals(3, map.size()); 99 Map elements = schemaInfoBuilder.getElementToTypeMap(); 100 log.debug("ELEMENT MAP"); 101 log.debug(elements); 102 assertEquals(1, elements.size()); 103 } 104 105 public void testAnyElements() throws Exception { 106 File schema1 = new File (BASEDIR, "src/test/resources/schema/schema5.xsd"); 107 log.debug("SCHEMA 5"); 108 Map map = parse(schema1); 109 assertEquals(8, map.size()); 110 Map elements = schemaInfoBuilder.getElementToTypeMap(); 111 log.debug("ELEMENT MAP"); 112 log.debug(elements); 113 assertEquals(4, elements.size()); 114 } 115 116 } 117 | Popular Tags |