You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sa...@apache.org on 2012/06/13 12:24:46 UTC
svn commit: r1349732 - in
/axis/axis2/java/core/trunk/modules/transport/http: ./
test-resources/schemas/ test-resources/schemas/custom_schemas/
test/org/apache/axis2/transport/http/
Author: sagara
Date: Wed Jun 13 10:24:46 2012
New Revision: 1349732
URL: http://svn.apache.org/viewvc?rev=1349732&view=rev
Log:
AXIS2-5335 - applying test cases patch for http module.
Added:
axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/
axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/
axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema.xsd (with props)
axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema1.xsd (with props)
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPWorkerTest.java (with props)
axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/XMLSchemaTest.java (with props)
Modified:
axis/axis2/java/core/trunk/modules/transport/http/pom.xml
Modified: axis/axis2/java/core/trunk/modules/transport/http/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/pom.xml?rev=1349732&r1=1349731&r2=1349732&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/transport/http/pom.xml Wed Jun 13 10:24:46 2012
@@ -117,5 +117,10 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
Added: axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema.xsd
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema.xsd?rev=1349732&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema.xsd (added)
+++ axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema.xsd Wed Jun 13 10:24:46 2012
@@ -0,0 +1,38 @@
+<?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/transport/http/test-resources/schemas/custom_schemas/sampleSchema.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Added: axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema1.xsd
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema1.xsd?rev=1349732&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema1.xsd (added)
+++ axis/axis2/java/core/trunk/modules/transport/http/test-resources/schemas/custom_schemas/sampleSchema1.xsd Wed Jun 13 10:24:46 2012
@@ -0,0 +1,31 @@
+<!--
+ ~ 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/sampleSchema.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/transport/http/test-resources/schemas/custom_schemas/sampleSchema1.xsd
------------------------------------------------------------------------------
svn:eol-style = native
Added: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPWorkerTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPWorkerTest.java?rev=1349732&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPWorkerTest.java (added)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPWorkerTest.java Wed Jun 13 10:24:46 2012
@@ -0,0 +1,242 @@
+/*
+ * 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.transport.http;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.transport.http.server.AxisHttpRequest;
+import org.apache.axis2.transport.http.server.AxisHttpResponse;
+import org.apache.http.Header;
+import org.apache.http.HeaderIterator;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.params.HttpParams;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.junit.Test;
+
+public class HTTPWorkerTest extends XMLSchemaTest {
+ protected AxisService service;
+ private ArrayList<XmlSchema> schemas;
+
+ private HTTPWorker httpWorker = new HTTPWorker();
+ private MessageContext messageContext = new MessageContext();
+ private ConfigurationContext configurationContext;
+ private ByteArrayOutputStream outputStream;
+
+ @Override
+ protected void setUp() throws Exception {
+ service = new AxisService();
+ outputStream = new ByteArrayOutputStream();
+ schemas = new ArrayList<XmlSchema>();
+ loadSampleSchemaFile(schemas);
+ service.addSchema(schemas);
+
+ AxisConfiguration axisConfiguration = new AxisConfiguration();
+ service.setName("test_service");
+ axisConfiguration.addChild(service);
+ axisConfiguration.addService(service);
+ configurationContext = new ConfigurationContext(axisConfiguration);
+ configurationContext.setServicePath("test_service");
+ configurationContext.setContextRoot("test/context");
+
+ messageContext.setConfigurationContext(configurationContext);
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ service = null;
+ schemas = null;
+ outputStream = null;
+ super.tearDown();
+ }
+
+ @Test
+ public void testService() throws Exception {
+ // THis method test if (HttpUtils.indexOfIngnoreCase(uri , "?xsd=") > 0)
+ // { section of the service method for xmlschema usage
+ httpWorker.service(new AxisHttpRequest() {
+
+ public void setParams(HttpParams arg0) {
+ }
+
+ public void setHeaders(Header[] arg0) {
+ }
+
+ public void setHeader(String arg0, String arg1) {
+ }
+
+ public void setHeader(Header arg0) {
+ }
+
+ public void removeHeaders(String arg0) {
+ }
+
+ public void removeHeader(Header arg0) {
+ }
+
+ public HeaderIterator headerIterator(String arg0) {
+ return null;
+ }
+
+ public HeaderIterator headerIterator() {
+ return null;
+ }
+
+ public ProtocolVersion getProtocolVersion() {
+ return null;
+ }
+
+ public HttpParams getParams() {
+ return null;
+ }
+
+ public Header getLastHeader(String arg0) {
+ return null;
+ }
+
+ public Header[] getHeaders(String arg0) {
+ return null;
+ }
+
+ public Header getFirstHeader(String arg0) {
+ return null;
+ }
+
+ public Header[] getAllHeaders() {
+ return null;
+ }
+
+ public boolean containsHeader(String arg0) {
+ return false;
+ }
+
+ public void addHeader(String arg0, String arg1) {
+ }
+
+ public void addHeader(Header arg0) {
+ }
+
+ public String getRequestURI() {
+ return "/test/context/test_service/test_service?xsd=sampleSchema";
+ }
+
+ public String getMethod() {
+ return HTTPConstants.HEADER_GET;
+ }
+
+ public InputStream getInputStream() {
+ return null;
+ }
+
+ public String getContentType() {
+ return null;
+ }
+ }, new AxisHttpResponse() {
+
+ public void setParams(HttpParams arg0) {
+ }
+
+ public void setHeaders(Header[] arg0) {
+ }
+
+ public void setHeader(String arg0, String arg1) {
+ }
+
+ public void setHeader(Header arg0) {
+ }
+
+ public void removeHeaders(String arg0) {
+ }
+
+ public void removeHeader(Header arg0) {
+ }
+
+ public HeaderIterator headerIterator(String arg0) {
+ return null;
+ }
+
+ public HeaderIterator headerIterator() {
+ return null;
+ }
+
+ public ProtocolVersion getProtocolVersion() {
+ return null;
+ }
+
+ public HttpParams getParams() {
+ return null;
+ }
+
+ public Header getLastHeader(String arg0) {
+ return null;
+ }
+
+ public Header[] getHeaders(String arg0) {
+ return null;
+ }
+
+ public Header getFirstHeader(String arg0) {
+ return null;
+ }
+
+ public Header[] getAllHeaders() {
+ return null;
+ }
+
+ public boolean containsHeader(String arg0) {
+ return false;
+ }
+
+ public void addHeader(String arg0, String arg1) {
+ }
+
+ public void addHeader(Header arg0) {
+ }
+
+ public void setStatus(int sc) {
+ }
+
+ public void setContentType(String contentType) {
+ }
+
+ public void sendError(int sc) {
+ }
+
+ public void sendError(int sc, String msg) {
+ }
+
+ public OutputStream getOutputStream() {
+ return outputStream;
+ }
+ }, messageContext);
+ // compare actual schema with schema from the response
+ assertSimilarXML(readXMLfromSchemaFile(customDirectoryLocation + "sampleSchema.xsd"),
+ outputStream.toString());
+
+ }
+
+}
Propchange: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/HTTPWorkerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/XMLSchemaTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/XMLSchemaTest.java?rev=1349732&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/XMLSchemaTest.java (added)
+++ axis/axis2/java/core/trunk/modules/transport/http/test/org/apache/axis2/transport/http/XMLSchemaTest.java Wed Jun 13 10:24:46 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.transport.http;
+
+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/transport/http/test/org/apache/axis2/transport/http/XMLSchemaTest.java
------------------------------------------------------------------------------
svn:eol-style = native