Author: sagara Date: Wed Jun 13 06:08:14 2012 New Revision: 1349648 URL: http://svn.apache.org/viewvc?rev=1349648&view=rev Log: AXIS2-5335 - applying patch for codegen module.
Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generated.xsd (with props) axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema1.xsd (with props) axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema2.xsd (with props) axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema3.xsd (with props) axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/sampleSchema1.xsd (with props) axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/schemaIncludes.xsd (with props) axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/CodeGenConfigurationTest.java (with props) axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/XMLSchemaTest.java (with props) axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/ axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/SchemaWriterTest.java (with props) Modified: axis/axis2/java/core/trunk/modules/codegen/pom.xml axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java Modified: axis/axis2/java/core/trunk/modules/codegen/pom.xml URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/pom.xml?rev=1349648&r1=1349647&r2=1349648&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/pom.xml (original) +++ axis/axis2/java/core/trunk/modules/codegen/pom.xml Wed Jun 13 06:08:14 2012 @@ -77,6 +77,11 @@ <artifactId>jaxws-rt</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>xmlunit</groupId> + <artifactId>xmlunit</artifactId> + <scope>test</scope> + </dependency> </dependencies> <url>http://axis.apache.org/axis2/java/core/</url> <scm> Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generated.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generated.xsd?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generated.xsd (added) +++ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generated.xsd Wed Jun 13 06:08:14 2012 @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- + ~ 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. + --> + +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3schools.com" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.w3schools.com"> + <xs:element name="note"> + <xs:complexType> + <xs:sequence> + <xs:element name="to" type="xs:string"/> + <xs:element name="from" type="xs:string"/> + <xs:element name="heading" type="xs:string"/> + <xs:element name="body" type="xs:string"/> + </xs:sequence> + </xs:complexType> + </xs:element> +</xs:schema> Propchange: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generated.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema1.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema1.xsd?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema1.xsd (added) +++ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema1.xsd Wed Jun 13 06:08:14 2012 @@ -0,0 +1,62 @@ +<!-- + ~ 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. + --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://test2.com" xmlns:tns="http://test.com" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test.com"> + <xsd:import namespace="http://test2.com"/> + <xsd:element name="testElement6" type="ns0:testComplexType2"/> + <xsd:element name="testElement1"> + <xsd:complexType> + <xsd:sequence/> + </xsd:complexType> + </xsd:element> + <xsd:complexType name="testComplexType2"> + <xsd:sequence/> + </xsd:complexType> +</xsd:schema> +<!-- + ~ 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. + --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://test2.com" xmlns:tns="http://test.com" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test.com"> + <xsd:import namespace="http://test2.com"/> + <xsd:element name="testElement6" type="ns0:testComplexType2"/> + <xsd:element name="testElement1"> + <xsd:complexType> + <xsd:sequence/> + </xsd:complexType> + </xsd:element> + <xsd:complexType name="testComplexType2"> + <xsd:sequence/> + </xsd:complexType> +</xsd:schema> Propchange: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema1.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema2.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema2.xsd?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema2.xsd (added) +++ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema2.xsd Wed Jun 13 06:08:14 2012 @@ -0,0 +1,48 @@ +<!-- + ~ 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. + --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://test2.com" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test2.com"> + <xsd:complexType name="testComplexType2"> + <xsd:sequence/> + </xsd:complexType> +</xsd:schema> +<!-- + ~ 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. + --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://test2.com" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test2.com"> + <xsd:complexType name="testComplexType2"> + <xsd:sequence/> + </xsd:complexType> +</xsd:schema> Propchange: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema2.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema3.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema3.xsd?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema3.xsd (added) +++ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema3.xsd Wed Jun 13 06:08:14 2012 @@ -0,0 +1,66 @@ +<!-- + ~ 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. + --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://test.com" xmlns:tns="http://test1.com" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test1.com"> + <xsd:import namespace="http://test.com"/> + <xsd:element name="testElement5" type="ns1:testComplexType2"/> + <xsd:element name="testElement4" type="tns:testComplexType1"/> + <xsd:element name="testElement3" type="xsd:string"/> + <xsd:element name="testElement2"> + <xsd:complexType> + <xsd:sequence/> + </xsd:complexType> + </xsd:element> + <xsd:complexType name="testComplexType1"> + <xsd:sequence/> + </xsd:complexType> +</xsd:schema> +<!-- + ~ 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. + --> + +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://test.com" xmlns:tns="http://test1.com" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://test1.com"> + <xsd:import namespace="http://test.com"/> + <xsd:element name="testElement5" type="ns1:testComplexType2"/> + <xsd:element name="testElement4" type="tns:testComplexType1"/> + <xsd:element name="testElement3" type="xsd:string"/> + <xsd:element name="testElement2"> + <xsd:complexType> + <xsd:sequence/> + </xsd:complexType> + </xsd:element> + <xsd:complexType name="testComplexType1"> + <xsd:sequence/> + </xsd:complexType> +</xsd:schema> Propchange: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/generatedSchema3.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/sampleSchema1.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/sampleSchema1.xsd?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/sampleSchema1.xsd (added) +++ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/sampleSchema1.xsd Wed Jun 13 06:08:14 2012 @@ -0,0 +1,76 @@ +<?xml version="1.0"?> + +<!-- + ~ 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. + --> + +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" +targetNamespace="http://www.w3schools.com" +xmlns="http://www.w3schools.com" +elementFormDefault="qualified"> + +<xs:element name="note"> + <xs:complexType> + <xs:sequence> + <xs:element name="to" type="xs:string"/> + <xs:element name="from" type="xs:string"/> + <xs:element name="heading" type="xs:string"/> + <xs:element name="body" type="xs:string"/> + </xs:sequence> + </xs:complexType> +</xs:element> + +</xs:schema> +<?xml version="1.0"?> + +<!-- + ~ 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. + --> + +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" +targetNamespace="http://www.w3schools.com" +xmlns="http://www.w3schools.com" +elementFormDefault="qualified"> + +<xs:element name="note"> + <xs:complexType> + <xs:sequence> + <xs:element name="to" type="xs:string"/> + <xs:element name="from" type="xs:string"/> + <xs:element name="heading" type="xs:string"/> + <xs:element name="body" type="xs:string"/> + </xs:sequence> + </xs:complexType> +</xs:element> + +</xs:schema> Propchange: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/sampleSchema1.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/schemaIncludes.xsd URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/schemaIncludes.xsd?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/schemaIncludes.xsd (added) +++ axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/schemaIncludes.xsd Wed Jun 13 06:08:14 2012 @@ -0,0 +1,62 @@ +<!-- + ~ 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. + --> + + +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:ord="http://www.w3schools.com"> + <xs:import namespace="http://www.w3schools.com" + schemaLocation="test-resources/schemas/custom_schemas/sampleSchema1.xsd"/> + <xs:element name="envelope" type="EnvelopeType"/> + <xs:complexType name="EnvelopeType"> + <xs:sequence> + <xs:element ref="ord:order" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> +</xs:schema> +<!-- + ~ 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. + --> + + +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:ord="http://www.w3schools.com"> + <xs:import namespace="http://www.w3schools.com" + schemaLocation="test-resources/schemas/custom_schemas/sampleSchema1.xsd"/> + <xs:element name="envelope" type="EnvelopeType"/> + <xs:complexType name="EnvelopeType"> + <xs:sequence> + <xs:element ref="ord:order" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> +</xs:schema> Propchange: axis/axis2/java/core/trunk/modules/codegen/test-resources/schemas/custom_schemas/schemaIncludes.xsd ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/CodeGenConfigurationTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/CodeGenConfigurationTest.java?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/CodeGenConfigurationTest.java (added) +++ axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/CodeGenConfigurationTest.java Wed Jun 13 06:08:14 2012 @@ -0,0 +1,132 @@ +/* + * 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.wsdl.codegen; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.axis2.description.AxisService; +import org.apache.axis2.wsdl.codegen.XMLSchemaTest; +import org.apache.axis2.util.CommandLineOption; +import org.apache.ws.commons.schema.XmlSchema; +import org.junit.Test; + +public class CodeGenConfigurationTest extends XMLSchemaTest{ + + protected AxisService service; + private ArrayList<XmlSchema> schemas; + + @Override + protected void setUp() throws Exception { + service = new AxisService(); + schemas = new ArrayList<XmlSchema>(); + loadSampleSchemaFile(schemas); + service.addSchema(schemas); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + service=null; + schemas=null; + + super.tearDown(); + } + + @Test + public void testGetSchemaListForAllServices(){ + Map<String, CommandLineOption> optionMap = new HashMap<String, CommandLineOption>(); + CodeGenConfiguration configuration = new CodeGenConfiguration(optionMap); + configuration.addAxisService(service); + List<XmlSchema> list=configuration.getSchemaListForAllServices(); + assertEquals(schemas.get(0), list.get(0)); + } + + +} +/* + * 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.wsdl.codegen; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.axis2.description.AxisService; +import org.apache.axis2.wsdl.codegen.XMLSchemaTest; +import org.apache.axis2.util.CommandLineOption; +import org.apache.ws.commons.schema.XmlSchema; +import org.junit.Test; + +public class CodeGenConfigurationTest extends XMLSchemaTest{ + + protected AxisService service; + private ArrayList<XmlSchema> schemas; + + @Override + protected void setUp() throws Exception { + service = new AxisService(); + schemas = new ArrayList<XmlSchema>(); + loadSampleSchemaFile(schemas); + service.addSchema(schemas); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + service=null; + schemas=null; + + super.tearDown(); + } + + @Test + public void testGetSchemaListForAllServices(){ + Map<String, CommandLineOption> optionMap = new HashMap<String, CommandLineOption>(); + CodeGenConfiguration configuration = new CodeGenConfiguration(optionMap); + configuration.addAxisService(service); + List<XmlSchema> list=configuration.getSchemaListForAllServices(); + assertEquals(schemas.get(0), list.get(0)); + } + + +} Propchange: axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/CodeGenConfigurationTest.java ------------------------------------------------------------------------------ svn:eol-style = native Added: axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/XMLSchemaTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/XMLSchemaTest.java?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/XMLSchemaTest.java (added) +++ axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/XMLSchemaTest.java Wed Jun 13 06:08:14 2012 @@ -0,0 +1,310 @@ +/* + * 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.wsdl.codegen; + +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; + } + + + +} +/* + * 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.wsdl.codegen; + +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/codegen/test/org/apache/axis2/wsdl/codegen/XMLSchemaTest.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java?rev=1349648&r1=1349647&r2=1349648&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java (original) +++ axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/schema/AxisServiceTopElementSchemaGeneratorTest.java Wed Jun 13 06:08:14 2012 @@ -19,16 +19,85 @@ package org.apache.axis2.wsdl.codegen.schema; -import junit.framework.TestCase; -import org.apache.axis2.namespace.Constants; - -import javax.xml.namespace.QName; +import java.util.ArrayList; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; +import javax.xml.namespace.QName; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.context.OperationContext; +import org.apache.axis2.context.ServiceContext; +import org.apache.axis2.description.AxisMessage; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.namespace.Constants; +import org.apache.axis2.wsdl.codegen.XMLSchemaTest; +import org.apache.ws.commons.schema.XmlSchema; +import org.apache.ws.commons.schema.XmlSchemaElement; +import org.junit.Test; + +public class AxisServiceTopElementSchemaGeneratorTest extends XMLSchemaTest { + + + private AxisService service; + private ArrayList<XmlSchema> schemas; + private AxisServiceTopElementSchemaGenerator generator; + private Map schemaMap; + private Set topElements; + + @Override + protected void setUp() throws Exception { + service = new AxisService(); + schemas = new ArrayList<XmlSchema>(); + loadSampleSchemaFile(schemas); + service.addSchema(schemas); + generator = new AxisServiceTopElementSchemaGenerator(null); + + topElements = new HashSet(); + + TopElement topElement; + + topElement = new TopElement(new QName("http://test.com", "testElement1")); + topElements.add(topElement); + topElement = new TopElement(new QName("http://test1.com", "testElement2")); + topElements.add(topElement); + topElement = new TopElement(new QName("http://test1.com", "testElement3")); + topElement.setTypeQName(new QName(Constants.URI_2001_SCHEMA_XSD, "string")); + topElements.add(topElement); + + topElement = new TopElement(new QName("http://test1.com", "testElement4")); + topElement.setTypeQName(new QName("http://test1.com", "testComplexType1")); + topElements.add(topElement); + + topElement = new TopElement(new QName("http://test1.com", "testElement5")); + topElement.setTypeQName(new QName("http://test.com", "testComplexType2")); + topElements.add(topElement); + + topElement = new TopElement(new QName("http://test.com", "testElement6")); + topElement.setTypeQName(new QName("http://test2.com", "testComplexType2")); + topElements.add(topElement); + + schemaMap = generator.getSchemaMap(topElements); + generator.getXmlSchemaList(schemaMap); + + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + service = null; + generator = null; + schemaMap.clear(); + topElements = null; + super.tearDown(); + } -public class AxisServiceTopElementSchemaGeneratorTest extends TestCase { public void testSchemaGeneration() throws Exception { @@ -66,4 +135,139 @@ public class AxisServiceTopElementSchema // ((org.apache.ws.commons.schema.XmlSchema)aXmlSchemaList).write(System.out); // } } + + @Test + public void testGetSchemaMap(){ + schemaMap = generator.getSchemaMap(topElements); + org.apache.axis2.wsdl.codegen.schema.XmlSchema schema=(org.apache.axis2.wsdl.codegen.schema.XmlSchema)schemaMap.get("http://test.com"); + TopElement topElement = new TopElement(new QName("http://test.com", "testElement1")); + assertTrue(schemaMap.size()==3); + assertEquals(schema.getTargetNamespace(), "http://test.com"); + } + + @Test + public void testGetTopElements() throws Exception { + AxisOperation axisOperation = new AxisOperation() { + + @Override + public void setRemainingPhasesInFlow(ArrayList list) { + } + + @Override + public void setPhasesOutFlow(ArrayList list) { + } + + @Override + public AxisService getAxisService() { + return service; + } + + @Override + public void setPhasesOutFaultFlow(ArrayList list) { + + } + + @Override + public void setPhasesInFaultFlow(ArrayList list) { + } + + @Override + public ArrayList getRemainingPhasesInFlow() { + return null; + } + + @Override + public ArrayList getPhasesOutFlow() { + return null; + } + + @Override + public ArrayList getPhasesOutFaultFlow() { + return null; + } + + @Override + public ArrayList getPhasesInFaultFlow() { + return null; + } + + @Override + public AxisMessage getMessage(String label) { + return null; + } + + @Override + public OperationClient createClient(ServiceContext sc, Options options) { + return null; + } + + @Override + public void addMessageContext(MessageContext msgContext, OperationContext opContext) + throws AxisFault { + } + + @Override + public void addMessage(AxisMessage message, String label) { + } + + @Override + public void addFaultMessageContext(MessageContext msgContext, OperationContext opContext) + throws AxisFault { + + } + }; + axisOperation.setName(new QName("http://www.w3schools.com", "tset")); + AxisMessage axisMessage = new AxisMessage(); + axisMessage.setParent(axisOperation); + axisMessage.setElementQName(new QName("http://www.w3schools.com", "note")); + axisOperation.addChild("message",axisMessage); + service.addOperation(axisOperation); + generator = new AxisServiceTopElementSchemaGenerator(service); + Set set=generator.getTopElements(); + boolean found=false; + TopElement element=null; + for (Object object : set) { + element=(TopElement)object; + if(element.getElementQName().equals(new QName("http://www.w3schools.com", "note"))){ + found=true; + } + } + assertTrue(found); + } + + @Test + public void testGetSchemaElement() throws Exception { + generator = new AxisServiceTopElementSchemaGenerator(service); + XmlSchemaElement element=generator.getSchemaElement(new QName("http://www.w3schools.com","note")); + assertNotNull(element); + assertEquals(element.getName(), "note"); + + } + + @Test + public void testGetXmlSchemaList() throws Exception { + Map map = generator.getSchemaMap(topElements); + List xmlSchemaList = generator.getXmlSchemaList(map); + int i = 0; + for (Object object : xmlSchemaList) { + i++; + XmlSchema schema = (XmlSchema) object; + // compare with initially generated ones + String s = schemaToString(schema); + s=s.replaceAll("<xsd:element name=\"testElement6\" type=\".*:testComplexType2\"/>", + "<xsd:element name=\"testElement6\" type=\"ns0:testComplexType2\"/>"); + + s=s.replaceAll("<xsd:element name=\"testElement5\" type=\".*:testComplexType2\"/>", + "<xsd:element name=\"testElement5\" type=\"ns1:testComplexType2\"/>"); + + String s1=readXMLfromSchemaFile(customDirectoryLocation + "generatedSchema" + i + ".xsd"); + + assertNotNull(s); + + + } + } + + + } Added: axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/SchemaWriterTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/SchemaWriterTest.java?rev=1349648&view=auto ============================================================================== --- axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/SchemaWriterTest.java (added) +++ axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/SchemaWriterTest.java Wed Jun 13 06:08:14 2012 @@ -0,0 +1,87 @@ +/* + * 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.wsdl.codegen.writer; + +import java.io.File; + +import org.apache.axis2.wsdl.codegen.XMLSchemaTest; +import org.apache.ws.commons.schema.XmlSchema; +import org.junit.Test; + +public class SchemaWriterTest extends XMLSchemaTest{ + private SchemaWriter writer; + + + @Override + protected void setUp() throws Exception { + writer=new SchemaWriter(new File(customDirectoryLocation)); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + writer=null; + super.tearDown(); + } + + @Test + public void testWriteSchema() throws Exception{ + XmlSchema schema=loadSingleSchemaFile(1); + writer.writeSchema(schema, "generated.xsd"); + String s1=readXMLfromSchemaFile(customDirectoryLocation+"generated.xsd"); + String s2=readXMLfromSchemaFile(customDirectoryLocation+"sampleSchema1.xsd"); + assertSimilarXML(s1, s2); + + } +} +package org.apache.axis2.wsdl.codegen.writer; + +import java.io.File; + +import org.apache.axis2.wsdl.codegen.XMLSchemaTest; +import org.apache.ws.commons.schema.XmlSchema; +import org.junit.Test; + +public class SchemaWriterTest extends XMLSchemaTest{ + private SchemaWriter writer; + + + @Override + protected void setUp() throws Exception { + writer=new SchemaWriter(new File(customDirectoryLocation)); + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + writer=null; + super.tearDown(); + } + + @Test + public void testWriteSchema() throws Exception{ + XmlSchema schema=loadSingleSchemaFile(1); + writer.writeSchema(schema, "generated.xsd"); + String s1=readXMLfromSchemaFile(customDirectoryLocation+"generated.xsd"); + String s2=readXMLfromSchemaFile(customDirectoryLocation+"sampleSchema1.xsd"); + assertSimilarXML(s1, s2); + + } +} Propchange: axis/axis2/java/core/trunk/modules/codegen/test/org/apache/axis2/wsdl/codegen/writer/SchemaWriterTest.java ------------------------------------------------------------------------------ svn:eol-style = native