[Carbon-dev] svn commit r43561 - in trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test: java/org/wso2/carbon/dataservices/test/sql java/org/wso2/carbon/dataservices/test/sql/mysql java/org/wso2/carbon/dataservices/test/util resources/test-dbs resources/xsd

anjana at wso2.com anjana at wso2.com
Mon Aug 17 05:37:27 PDT 2009


Author: anjana
Date: Mon Aug 17 05:37:26 2009
New Revision: 43561
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=43561

Log:
* added several data manipulation test cases and added support for validating the structure of the resultant messages of data services service call results .. and created stubs for further tests ..

Added:
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractInputMappingServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractNestedQueryServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractResourceServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractStoredProcedureServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLDMLService.dbs
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/customers.xsd
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/order_count.xsd
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/products.xsd
Modified:
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractBasicServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractDMLServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLBasicTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLDMLServiceTest.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/util/TestUtils.java
   trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLBasicService.dbs

Modified: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractBasicServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractBasicServiceTest.java?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractBasicServiceTest.java	(original)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractBasicServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -25,7 +25,7 @@
 public abstract class AbstractBasicServiceTest extends DataServiceBaseTestCase {
 
 	private String epr = null;
-
+	
 	public AbstractBasicServiceTest(String testName, String serviceName) {
 		super(testName);
 		this.epr = this.baseEpr + serviceName;
@@ -35,38 +35,50 @@
 	 * Test with a simple select statement with the given fields.
 	 */
 	protected void basicSelectWithFields() {
-		System.out.println("\n###########################################");
-		System.out.println("Testing service : " + this.epr);
-		System.out.println("###########################################");
+		TestUtils.showMessage(this.epr + " - basicSelectWithFields");
 		try {
 			OMElement result = TestUtils.callOperation(this.epr,
 					"select_op_given_fields", null);
-			assertNotNull(result);
+			assertTrue(TestUtils.validateResultStructure(result, TestUtils.CUSTOMER_XSD_PATH));
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
 		}
-		assertTrue(true);
-		System.out.println("SUCCESS");
 	}
 
 	/**
 	 * Test with a simple select statement with all fields.
 	 */
 	protected void basicSelectAll() {
-		System.out.println("\n###########################################");
-		System.out.println("Testing service : " + this.epr);
-		System.out.println("###########################################");
+		TestUtils.showMessage(this.epr + " - basicSelectAll");
 		try {
 			OMElement result = TestUtils.callOperation(this.epr,
 					"select_op_all_fields", null);
-			assertNotNull(result);
+			assertTrue(TestUtils.validateResultStructure(result, TestUtils.PRODUCTS_XSD_PATH));
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
 		}
 		assertTrue(true);
-		System.out.println("SUCCESS");
+	}
+
+	/**
+	 * Test with a simple select statement to get a row count.
+	 */
+	protected void basicSelectCount() {
+		TestUtils.showMessage(this.epr + " - basicSelectCount");
+		try {
+			OMElement result = TestUtils.callOperation(this.epr,
+					"select_op_count", null);
+			assertTrue(TestUtils.validateResultStructure(result, TestUtils.ORDER_COUNT_XSD_PATH));
+			String val = TestUtils.getFirstValue(result,
+					"/Orders/OrderDetails/orderDetailsCount",
+					TestUtils.DEFAULT_DS_WS_NAMESPACE);
+			assertTrue(Integer.parseInt(val) > 0);	
+		} catch (Exception e) {
+			e.printStackTrace();
+			fail(e.getMessage());
+		}
 	}
 
 }

Modified: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractDMLServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractDMLServiceTest.java?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractDMLServiceTest.java	(original)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractDMLServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -1,6 +1,26 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.sql;
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.axiom.om.OMElement;
 import org.wso2.carbon.dataservices.test.DataServiceBaseTestCase;
+import org.wso2.carbon.dataservices.test.util.TestUtils;
 
 public abstract class AbstractDMLServiceTest extends DataServiceBaseTestCase {
 
@@ -13,22 +33,96 @@
 		super(testName);
 		this.epr = this.baseEpr + serviceName;
 	}
-	
-	protected void insertDataSmall() {
-		System.out.println("\n###########################################");
-		System.out.println("Testing service : " + this.epr);
-		System.out.println("###########################################");
+
+	private int selectDataCount(String id) throws Exception {
+		Map<String, String> params = new HashMap<String, String>();
+		params.put("customerNumber", id);
+		OMElement result = TestUtils.callOperation(this.epr,
+				"select_count_id_op", params);
+		String val = TestUtils.getFirstValue(result,
+				"/Customers/CustomerDetails/customerCount",
+				TestUtils.DEFAULT_DS_WS_NAMESPACE);
+		return Integer.parseInt(val);
+	}
+
+	private Map<String, String> selectData(String id) throws Exception {
+		Map<String, String> params = new HashMap<String, String>();
+		params.put("customerNumber", id);
+		OMElement result = TestUtils.callOperation(this.epr,
+				"select_data_op", params);
+		Map<String, String> data = new HashMap<String, String>();
+		data.put("customerNumber", TestUtils.getFirstValue(result,
+				"/Customers/Customer/customerNumber",
+				TestUtils.DEFAULT_DS_WS_NAMESPACE));
+		data.put("customerName", TestUtils.getFirstValue(result,
+				"/Customers/Customer/customerName",
+				TestUtils.DEFAULT_DS_WS_NAMESPACE));
+		data.put("contactLastName", TestUtils.getFirstValue(result,
+				"/Customers/Customer/contactLastName",
+				TestUtils.DEFAULT_DS_WS_NAMESPACE));
+		data.put("phone", TestUtils.getFirstValue(result,
+				"/Customers/Customer/phone",
+				TestUtils.DEFAULT_DS_WS_NAMESPACE));
+		data.put("city", TestUtils.getFirstValue(result,
+				"/Customers/Customer/city", 
+				TestUtils.DEFAULT_DS_WS_NAMESPACE));
+		return data;
+	}
+
+	private void deleteData(String id) throws Exception {
+		Map<String, String> params = new HashMap<String, String>();
+		params.put("customerNumber", id);
+		// TODO: Fix exception occuring "org.apache.axis2.AxisFault: The input stream for an incoming message is null"
 		try {
-			/* OMElement result = TestUtils.callOperation(this.epr,
-					"insert_data_small", null);
-			assertNotNull(result); */
+			assertNotNull(TestUtils.callOperation(this.epr, "delete_data_op",
+					params));
+		} catch (Exception e) {
+			// ignore for now
+		}
+	}
+
+	private void insertData(Map<String, String> params) throws Exception {
+        // TODO: Fix exception occuring "org.apache.axis2.AxisFault: The input stream for an incoming message is null"
+		try {
+			assertNotNull(TestUtils.callOperation(this.epr, "insert_data_op",
+					params));
+		} catch (Exception e) {
+			// ignore for now
+		}
+	}
+
+	/**
+	 * Data Manipulation Test. Steps:- 
+	 * > Delete record with the given id - remove any previous left over data, from a failed test perhaps. 
+	 * > Insert record - insert a new record. 
+	 * > Select record - select the just inserted record and checks if the data has been insert properly. 
+	 * > Delete record - delete the earlier added record.
+	 * > Select record count - select the number of records with the earlier deleted id, to check to see if the delete
+	 * operation was successful.
+	 */
+	protected void doDMLOperations() {
+		TestUtils.showMessage(this.epr + " - doDMLOperations");
+		Map<String, String> params = new HashMap<String, String>();
+		params.put("customerNumber", "450001");
+		params.put("customerName", "Will Smith");
+		params.put("contactLastName", "Silva");
+		params.put("phone", "+9400123456");
+		params.put("city", "Colombo");
+		try {
+			deleteData(params.get("customerNumber"));
+			insertData(params);
+			Map insertedValues = selectData(params.get("customerNumber"));
+			for (String key : params.keySet()) {
+				assertTrue(params.get(key).equals(insertedValues.get(key)));
+			}
+			deleteData(params.get("customerNumber"));
+			int count = selectDataCount(params.get("customerNumber"));
+			assertTrue(count == 0);
 		} catch (Exception e) {
 			e.printStackTrace();
 			fail(e.getMessage());
 		}
 		assertTrue(true);
-		System.out.println("SUCCESS");
 	}
 
-
 }

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractInputMappingServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractInputMappingServiceTest.java?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractInputMappingServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.sql;
+
+import org.wso2.carbon.dataservices.test.DataServiceBaseTestCase;
+
+public abstract class AbstractInputMappingServiceTest extends DataServiceBaseTestCase {
+
+	/**
+	 * Class to represent input mappings test cases.
+	 */
+	private String epr = null;
+
+	public AbstractInputMappingServiceTest(String testName, String serviceName) {
+		super(testName);
+		this.epr = this.baseEpr + serviceName;
+	}
+
+	
+}
\ No newline at end of file

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractNestedQueryServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractNestedQueryServiceTest.java?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractNestedQueryServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.sql;
+
+import org.wso2.carbon.dataservices.test.DataServiceBaseTestCase;
+
+public abstract class AbstractNestedQueryServiceTest extends DataServiceBaseTestCase {
+
+	/**
+	 * Class to represent nested sql query test cases.
+	 */
+	private String epr = null;
+
+	public AbstractNestedQueryServiceTest(String testName, String serviceName) {
+		super(testName);
+		this.epr = this.baseEpr + serviceName;
+	}
+
+	
+}

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractResourceServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractResourceServiceTest.java?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractResourceServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.sql;
+
+import org.wso2.carbon.dataservices.test.DataServiceBaseTestCase;
+
+public abstract class AbstractResourceServiceTest extends DataServiceBaseTestCase {
+
+	/**
+	 * Class to represent resource request test cases.
+	 */
+	private String epr = null;
+
+	public AbstractResourceServiceTest(String testName, String serviceName) {
+		super(testName);
+		this.epr = this.baseEpr + serviceName;
+	}
+
+	
+}
\ No newline at end of file

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractStoredProcedureServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractStoredProcedureServiceTest.java?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/AbstractStoredProcedureServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.sql;
+
+import org.wso2.carbon.dataservices.test.DataServiceBaseTestCase;
+
+public abstract class AbstractStoredProcedureServiceTest extends DataServiceBaseTestCase {
+
+	/**
+	 * Class to represent stored procedure test cases.
+	 */
+	private String epr = null;
+
+	public AbstractStoredProcedureServiceTest(String testName, String serviceName) {
+		super(testName);
+		this.epr = this.baseEpr + serviceName;
+	}
+
+	
+}
\ No newline at end of file

Modified: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLBasicTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLBasicTest.java?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLBasicTest.java	(original)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLBasicTest.java	Mon Aug 17 05:37:26 2009
@@ -30,5 +30,9 @@
 	public void testMysqlBasicSelectAll() {
 		this.basicSelectAll();
 	}
+	
+	public void testMysqlBasicSelectCount() {
+		this.basicSelectCount();
+	}
 
 }

Modified: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLDMLServiceTest.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLDMLServiceTest.java?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLDMLServiceTest.java	(original)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/sql/mysql/MySQLDMLServiceTest.java	Mon Aug 17 05:37:26 2009
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.sql.mysql;
 
 import org.wso2.carbon.dataservices.test.sql.AbstractDMLServiceTest;
@@ -8,8 +23,8 @@
 		super(testName, "MySQLDMLService");
 	}
 	
-	public void testInsertDataSmall() {
-		this.insertDataSmall();
+	public void testDMLOperations() {
+		this.doDMLOperations();
 	}
 	
 }

Modified: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/util/TestUtils.java
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/util/TestUtils.java?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/util/TestUtils.java	(original)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/java/org/wso2/carbon/dataservices/test/util/TestUtils.java	Mon Aug 17 05:37:26 2009
@@ -1,17 +1,51 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.wso2.carbon.dataservices.test.util;
 
+import java.io.FileInputStream;
+import java.io.StringReader;
 import java.util.Map;
 
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
 
 public class TestUtils {
 
+	private static final String XSD_SCHEMA = "http://www.w3.org/2001/XMLSchema";
+
+	public static String DEFAULT_DS_WS_NAMESPACE = "http://ws.wso2.org/dataservice";
+
+	public static final String CUSTOMER_XSD_PATH = "./src/test/resources/xsd/customers.xsd";
+
+	public static final String PRODUCTS_XSD_PATH = "./src/test/resources/xsd/products.xsd";
+
+	public static final String ORDER_COUNT_XSD_PATH = "./src/test/resources/xsd/order_count.xsd";
+
 	/**
 	 * Calls an operation of a target web service with the given parameters and
 	 * returns the result.
@@ -56,4 +90,49 @@
 		return method;
 	}
 
+	/**
+	 * prints out the given message
+	 * 
+	 * @param msg
+	 *            message to be printed
+	 */
+	public static void showMessage(String msg) {
+		System.out.println("\n###########################################");
+		System.out.println("Testing service : " + msg);
+		System.out.println("###########################################");
+	}
+
+	public static String getFirstValue(OMElement el, String path, String ns)
+			throws Exception {
+		AXIOMXPath xpathe = formatXPath(path, ns);
+		return ((OMElement) xpathe.selectSingleNode(el)).getText();
+	}
+
+	private static AXIOMXPath formatXPath(String path, String ns)
+			throws Exception {
+		if (!path.startsWith("//")) {
+			path = "/" + path;
+		}
+		path = path.substring(0, 1) + path.substring(1).replaceAll("/", "/ns:");
+		AXIOMXPath xpathe = new AXIOMXPath(path);
+		xpathe.addNamespace("ns", ns);
+		return xpathe;
+	}
+
+	public static boolean validateResultStructure(OMElement result,
+			String schemaPath) throws Exception {
+		SchemaFactory fac = SchemaFactory.newInstance(XSD_SCHEMA);
+		Source source = new StreamSource(new FileInputStream(schemaPath));
+		Schema schema = fac.newSchema(source);
+		Validator validator = schema.newValidator();
+		try {
+			validator.validate(new StreamSource(new StringReader(result
+					.toString())));
+		} catch (Exception e) {
+			System.out.println("validateResultStructure:" + e.getMessage());
+			return false;
+		}
+		return true;
+	}
+
 }

Modified: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLBasicService.dbs
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLBasicService.dbs?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLBasicService.dbs	(original)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLBasicService.dbs	Mon Aug 17 05:37:26 2009
@@ -8,7 +8,7 @@
       <property name="org.wso2.ws.dataservice.maxpoolsize">100</property>
    </config>
 
-   <!-- Query and Operation for plain SELECT with given fields test  -->
+   <!-- Query and Operation for a plain SELECT with given fields test  -->
    <query id="select_query_given_fields">
       <sql>SELECT customerNumber, customerName, contactLastName, phone, city FROM Customers</sql>
 
@@ -26,7 +26,7 @@
       </call-query>
    </operation>
    
-   <!-- Query and Operation for plain SELECT with all fields test  -->
+   <!-- Query and Operation for a plain SELECT with all fields test  -->
    <query id="select_query_all_fields">
       <sql>SELECT * FROM Products</sql>
 
@@ -43,6 +43,19 @@
       </call-query>
    </operation>
    
+   <!-- Query and Operation for a SELECT COUNT -->
+   <query id="select_query_count">
+      <sql>SELECT COUNT(*) as orderDetailsCount FROM OrderDetails</sql>
+
+      <result element="Orders" rowName="OrderDetails">
+         <element name="orderDetailsCount" column="orderDetailsCount" />
+      </result>
+   </query>
+
+   <operation name="select_op_count">
+      <call-query href="select_query_count">
+      </call-query>
+   </operation>
    
 </data>
 

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLDMLService.dbs
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLDMLService.dbs?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/test-dbs/MySQLDMLService.dbs	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,78 @@
+<data name="MySQLDMLService">
+   <config>
+      <property name="org.wso2.ws.dataservice.driver">com.mysql.jdbc.Driver</property>
+      <property name="org.wso2.ws.dataservice.protocol">jdbc:mysql://localhost:3306/DSTestDB?autoReconnect=true</property>
+      <property name="org.wso2.ws.dataservice.user">datauser</property>
+      <property name="org.wso2.ws.dataservice.password">wso2</property>
+      <property name="org.wso2.ws.dataservice.minpoolsize">2</property>
+      <property name="org.wso2.ws.dataservice.maxpoolsize">100</property>
+   </config>
+
+  <!-- Query and Operation for INSERT test -->
+   <query id="insert_data_query">
+      <sql>INSERT INTO Customers (customerNumber,customerName,contactLastName,phone,city) values(?,?,?,?,?)</sql>
+      <param name="customerNumber" sqlType="INTEGER" />
+      <param name="customerName" sqlType="STRING" />
+      <param name="contactLastName" sqlType="STRING" />
+      <param name="phone" sqlType="STRING" />
+      <param name="city" sqlType="STRING" />          
+   </query>
+
+   <operation name="insert_data_op">
+      <call-query href="insert_data_query">
+        <with-param name="customerNumber" query-param="customerNumber" />
+        <with-param name="customerName" query-param="customerName" />
+        <with-param name="contactLastName" query-param="contactLastName" />
+        <with-param name="phone" query-param="phone" />
+        <with-param name="city" query-param="city" />                              
+      </call-query>
+   </operation>
+   
+   <!-- Query and Operation for DELETE test -->
+   <query id="delete_data_query">
+      <sql>DELETE FROM Customers WHERE customerNumber=?</sql>
+      <param name="customerNumber" sqlType="INTEGER" />      
+   </query>
+
+   <operation name="delete_data_op">
+      <call-query href="delete_data_query">
+        <with-param name="customerNumber" query-param="customerNumber" />
+      </call-query>
+   </operation>
+   
+   <!-- Query and Operation for SELECT with a given id test -->
+   <query id="select_data_query">
+      <sql>SELECT * FROM Customers WHERE customerNumber=?</sql>
+      <param name="customerNumber" sqlType="INTEGER" />
+      <result element="Customers" rowName="Customer">
+         <element name="customerNumber" column="customerNumber" />
+         <element name="customerName" column="customerName" />
+         <element name="contactLastName" column="contactLastName" />
+         <element name="phone" column="phone" />
+         <element name="city" column="city" />
+      </result>
+   </query>
+
+   <operation name="select_data_op">
+      <call-query href="select_data_query">
+        <with-param name="customerNumber" query-param="customerNumber" />
+      </call-query>
+   </operation>
+   
+   <!-- Query and Operation for a SELECT COUNT with a given id -->
+   <query id="select_count_id_query">
+      <sql>SELECT COUNT(*) as customerCount FROM Customers WHERE customerNumber=?</sql>
+      <param name="customerNumber" sqlType="INTEGER" />
+      <result element="Customers" rowName="CustomerDetails">
+         <element name="customerCount" column="customerCount" />
+      </result>
+   </query>
+
+   <operation name="select_count_id_op">
+      <call-query href="select_count_id_query">
+        <with-param name="customerNumber" query-param="customerNumber" />
+      </call-query>
+   </operation>
+   
+</data>
+

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/customers.xsd
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/customers.xsd?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/customers.xsd	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ws.wso2.org/dataservice" xmlns="http://ws.wso2.org/dataservice" elementFormDefault="qualified">
+
+<xs:element name="Customers">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element name="Customer" maxOccurs="unbounded">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="customerNumber" type="xs:string"/>
+            <xs:element name="customerName" type="xs:string"/>
+            <xs:element name="contactLastName" type="xs:string"/>
+            <xs:element name="phone" type="xs:string"/>
+            <xs:element name="city" type="xs:string"/>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>
\ No newline at end of file

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/order_count.xsd
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/order_count.xsd?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/order_count.xsd	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ws.wso2.org/dataservice" elementFormDefault="qualified">
+
+<xs:element name="Orders">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element name="OrderDetails">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="orderDetailsCount" type="xs:string"/>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>
\ No newline at end of file

Added: trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/products.xsd
URL: http://wso2.org/svn/browse/wso2/trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/products.xsd?pathrev=43561
==============================================================================
--- (empty file)
+++ trunk/carbon-components/data-services/org.wso2.carbon.dataservices.core/src/test/resources/xsd/products.xsd	Mon Aug 17 05:37:26 2009
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ws.wso2.org/dataservice" elementFormDefault="qualified">
+
+<xs:element name="Products">
+  <xs:complexType>
+    <xs:sequence>
+      <xs:element name="Product" maxOccurs="unbounded">
+        <xs:complexType>
+          <xs:sequence>
+            <xs:element name="productCode" type="xs:string"/>
+            <xs:element name="productName" type="xs:string"/>
+            <xs:element name="quantityInStock" type="xs:string"/>
+            <xs:element name="buyPrice" type="xs:string"/>
+          </xs:sequence>
+        </xs:complexType>
+      </xs:element>
+    </xs:sequence>
+  </xs:complexType>
+</xs:element>
+
+</xs:schema>
\ No newline at end of file



More information about the Carbon-dev mailing list