Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/ExtensionUtilityTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/ExtensionUtilityTest.java?rev=1351210&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/ExtensionUtilityTest.java (added) +++ axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/ExtensionUtilityTest.java Mon Jun 18 06:09:49 2012 @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + + +package org.apache.axis2.schema; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; + +import javax.xml.namespace.QName; + +import org.apache.axis2.description.AxisService; +import org.apache.axis2.util.CommandLineOption; +import org.apache.axis2.wsdl.codegen.CodeGenConfiguration; +import org.apache.axis2.wsdl.databinding.TypeMapper; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.w3c.dom.Document; + + + +public class ExtensionUtilityTest extends XMLSchemaTest { + + public void testInvoke() throws Exception{ + ArrayList<XmlSchema> schemas=new ArrayList<XmlSchema>(); + loadSampleSchemaFile(schemas); + AxisService service=new AxisService(); + service.addSchema(schemas); + CodeGenConfiguration configuration=new CodeGenConfiguration(new HashMap<String, CommandLineOption>()); + configuration.addAxisService(service); + ExtensionUtility.invoke(configuration); + TypeMapper mapper=configuration.getTypeMapper(); + assertEquals(mapper.getParameterName(new QName("//www.w3schools.com", "order")), "order"); + // assertEquals(mapper., actual) + ByteArrayOutputStream stream =new ByteArrayOutputStream(); + Document document=(Document)mapper.getTypeMappingObject(new QName("ColorType")); + XmlSchemaCollection schemaCol = new XmlSchemaCollection(); + XmlSchema schema = schemaCol.read(document, null); + schema.write(stream); + //writeToFile(customDirectoryLocation+"generated.xsd", stream.toString()); + assertSimilarXML(stream.toString(), readXMLfromSchemaFile(customDirectoryLocation+"generated.xsd")); + + + } + +}
Propchange: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/ExtensionUtilityTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/SchemaCompilerTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/SchemaCompilerTest.java?rev=1351210&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/SchemaCompilerTest.java (added) +++ axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/SchemaCompilerTest.java Mon Jun 18 06:09:49 2012 @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.schema; + +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.junit.Test; +import org.w3c.dom.Document; + +public class SchemaCompilerTest extends XMLSchemaTest{ + + private ArrayList<XmlSchema> schemas; + private SchemaCompiler schemaCompiler; + private HashMap<QName,String> processedElementMap; + + + @Override + protected void setUp() throws Exception { + schemas=new ArrayList<XmlSchema>(); + loadSampleSchemaFile(schemas); + schemaCompiler=new SchemaCompiler(null); + } + + @Override + protected void tearDown() throws Exception { + schemas=null; + super.tearDown(); + } + + @Test + public void testCompileSchema() throws Exception{ + Map map=schemaCompiler.getProcessedModelMap(); + schemaCompiler.compile(schemas); + processedElementMap=schemaCompiler.getProcessedElementMap(); + map=schemaCompiler.getProcessedModelMap(); + Iterator iterator=map.values().iterator(); + int i=0; + while (iterator.hasNext()) { + i++; + Document document= (Document) iterator.next(); + ByteArrayOutputStream stream=new ByteArrayOutputStream(); + XmlSchemaCollection schemaCol = new XmlSchemaCollection(); + XmlSchema schema = schemaCol.read(document, null); + schema.write(stream); + assertSimilarXML(stream.toString(), readXMLfromSchemaFile(customDirectoryLocation+"generated"+i+".xsd")); + + } + + } + + + + + + +} Propchange: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/SchemaCompilerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XMLSchemaTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XMLSchemaTest.java?rev=1351210&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XMLSchemaTest.java (added) +++ axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XMLSchemaTest.java Mon Jun 18 06:09:49 2012 @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.schema; + +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.InputStream; +import java.util.ArrayList; + +import javax.xml.transform.stream.StreamSource; + +import junit.framework.TestCase; + +import org.apache.axis2.util.XMLPrettyPrinter; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.custommonkey.xmlunit.Diff; + +public abstract class XMLSchemaTest extends TestCase { + + public final String XMLSchemaNameSpace = "xmlns:xs=\"http://www.w3.org/2001/XMLSchema\""; + + public final String CustomSchemaLocation = "test-resources" + + File.separator + "schemas" + File.separator + "custom_schemas" + + File.separator + "note.xsd"; + + public final String customDirectoryLocation = "test-resources" + + File.separator + "schemas" + File.separator + "custom_schemas" + + File.separator; + + public final String SampleSchemasDirectory = "test-resources" + + File.separator + "schemas" + File.separator + "custom_schemas" + + File.separator; + + public final String MappingFileLocation = "test-resources" + File.separator + + "schemas" + File.separator + "mapping_files" + File.separator + + "mapping1.txt"; + + public void assertSimilarXML(String XML1, String XML2) throws Exception { + Diff myDiff = new Diff(XML1, XML2); + assertTrue("XML similar " + myDiff.toString(), myDiff.similar()); + + } + + public void assertIdenticalXML(String XML1, String XML2) throws Exception { + Diff myDiff = new Diff(XML1, XML2); + assertTrue("XML similar " + myDiff.toString(), myDiff.identical()); + + } + + public void loadSampleSchemaFile(ArrayList<XmlSchema> schemas) throws Exception{ + XmlSchemaCollection xmlSchemaCollection = new XmlSchemaCollection(); + File file = null; + int i = 1; + + file = new File(SampleSchemasDirectory + "sampleSchema" + i + + ".xsd"); + while (file.exists()) { + InputStream is = new FileInputStream(file); + XmlSchemaCollection schemaCol = new XmlSchemaCollection(); + XmlSchema schema = schemaCol.read(new StreamSource(is), null); + schemas.add(schema); + i++; + file = new File(SampleSchemasDirectory + "sampleSchema" + i + + ".xsd"); + } + + } + + public XmlSchema loadSingleSchemaFile(int i) throws Exception{ + File file = new File(SampleSchemasDirectory + "sampleSchema" + i + + ".xsd"); + InputStream is = new FileInputStream(file); + XmlSchemaCollection schemaCol = new XmlSchemaCollection(); + XmlSchema schema = schemaCol.read(new StreamSource(is), null); + return schema; + } + + + public String readFile(String fileName) throws Exception { + File file = new File(fileName); + char[] buffer = null; + BufferedReader bufferedReader = new BufferedReader(new FileReader(file)); + buffer = new char[(int) file.length()]; + int i = 0; + int c = bufferedReader.read(); + while (c != -1) { + buffer[i++] = (char) c; + c = bufferedReader.read(); + } + return new String(buffer); + } + + public String readXMLfromSchemaFile(String path) throws Exception { + InputStream is = new FileInputStream(path); + XmlSchemaCollection schemaCol = new XmlSchemaCollection(); + XmlSchema schema = schemaCol.read(new StreamSource(is), null); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + schema.write(stream); + is.close(); + return stream.toString(); + } + + + public String readWSDLFromFile(String path) throws Exception { + File file=new File(path); + XMLPrettyPrinter.prettify(file); //this is used to correct unnecessary formatting in the file + return readFile(path); + } + + public void writeToFile(String path,String data) throws Exception{ + FileWriter fileWriter=new FileWriter(new File(path)); + fileWriter.write(data); + fileWriter.flush(); + fileWriter.close(); + } + + public String schemaToString(XmlSchema schema){ + ByteArrayOutputStream stream=new ByteArrayOutputStream(); + schema.write(stream); + return stream.toString(); + } + + public XmlSchema loadSingleSchemaFile(String path) throws Exception{ + File file = new File(path); + InputStream is = new FileInputStream(file); + XmlSchemaCollection schemaCol = new XmlSchemaCollection(); + XmlSchema schema = schemaCol.read(new StreamSource(is), null); + return schema; + } + + + +} Propchange: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XMLSchemaTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XSD2JavaTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XSD2JavaTest.java?rev=1351210&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XSD2JavaTest.java (added) +++ axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XSD2JavaTest.java Mon Jun 18 06:09:49 2012 @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.axis2.schema; + +import java.io.File; +import org.junit.Test; + +public class XSD2JavaTest extends XMLSchemaTest { + + @Test + public void testMain() throws Exception { + File file = null; + + for (int i = 0; i <= 4; i++) { + file = new File(SampleSchemasDirectory + "sampleSchema" + i + ".xsd"); + + if (file.exists()) { + XSD2Java.main(new String[] { SampleSchemasDirectory + "sampleSchema" + i + ".xsd", + SampleSchemasDirectory+"XSD2JAVA" + i }); + File temp=new File(SampleSchemasDirectory+"XSD2JAVA" + i ); + //checks whether XSD2Java executed successfully + assertTrue(temp.exists()); + } + } + + } +} Propchange: axis/axis2/java/core/trunk/modules/adb-codegen/test/org/apache/axis2/schema/XSD2JavaTest.java ------------------------------------------------------------------------------ svn:eol-style = native