Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #24 from madhawa-gunasekara/regex-tests
Browse files Browse the repository at this point in the history
Adding regex test cases
  • Loading branch information
lankavitharana committed Sep 14, 2015
2 parents e0de75b + fbd3461 commit 8ec78ef
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* 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.dss.integration.test.services;

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.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.test.utils.axis2client.AxisServiceClient;
import org.wso2.dss.integration.test.DSSIntegrationTest;

import javax.xml.namespace.QName;
import javax.xml.xpath.XPathExpressionException;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import static org.testng.Assert.assertNotNull;

/**
* This class has been written to verify the functionality of the regex support in RDBMS.
*/
public class RegexTestCase extends DSSIntegrationTest {

private final OMFactory factory = OMAbstractFactory.getOMFactory();
private final OMNamespace omNs = factory.createOMNamespace("http://ws.wso2.org/dataservice/samples/rdbms_sample",
"ns1");
private final String serviceName = "RegexTest";

@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {

super.init();
List<File> sqlFileLis = new ArrayList<>();
sqlFileLis.add(selectSqlFile("RegexTable.sql"));
deployService(serviceName, createArtifact(
getResourceLocation() + File.separator + "dbs" + File.separator + "rdbms" +
File.separator + "h2" + File.separator + "RegexTest.dbs", sqlFileLis));

}

@AfterClass(alwaysRun = true)
public void destroy() throws Exception {
deleteService(serviceName);
cleanup();
}

@Test(groups = "wso2.dss", description = "Invoking select operation to verify regex support with sequence operators")
public void performRegexTestWithSequenceOperators() throws AxisFault, XPathExpressionException {
OMElement payload = factory.createOMElement("select_regex1", omNs);
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName),
"select_regex1");
boolean id = "1".equals(result.getFirstElement().getFirstChildWithName(
new QName("http://ws.wso2.org/dataservice/samples/rdbms_sample", "studentNumber")).getText());
Assert.assertTrue(id, "Regex sequence operators testing is failed.");
}

@Test(groups = "wso2.dss", description = "Invoking select operation to verify regex support with bracket expressions")
public void performRegexTestWithBracketExpressions() throws AxisFault, XPathExpressionException {
OMElement payload = factory.createOMElement("select_regex2", omNs);
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName),
"select_regex2");
assertNotNull(result);
Assert.assertEquals(result.getLocalName(), "Entries");
}

@Test(groups = "wso2.dss", description = "Invoking select operation to verify regex support with character classes")
public void performRegexTestWithCharacterClasses() throws AxisFault, XPathExpressionException {
OMElement payload = factory.createOMElement("select_regex3", omNs);
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName),
"select_regex3");
boolean id = "5".equals(result.getFirstElement().getFirstChildWithName(
new QName("http://ws.wso2.org/dataservice/samples/rdbms_sample", "Count")).getText());
Assert.assertTrue(id, "Regex character class testing is failed.");
}

@Test(groups = "wso2.dss", description = "Invoking select operation to verify regex support with nameparams and bracket expressions")
public void performRegexTestWithBracketExpressionsAndNameParams() throws AxisFault, XPathExpressionException {
OMElement payload = factory.createOMElement("select_regex5", omNs);
OMElement queryElement = factory.createOMElement("name", omNs);
queryElement.setText("name");
payload.addChild(queryElement);
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName),
"select_regex5");
assertNotNull("Response null " + result);
Assert.assertEquals(result.getLocalName(), "Entries");
}

@Test(groups = "wso2.dss", description = "Invoking select operation to verify regex support with nameparams and sequence operators")
public void performRegexTestWithSequenceOperatorsAndNameParams() throws AxisFault, XPathExpressionException {
OMElement payload = factory.createOMElement("select_regex4", omNs);
OMElement queryElement = factory.createOMElement("name", omNs);
queryElement.setText("name");
payload.addChild(queryElement);
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName),
"select_regex4");
boolean name = "Madhawa Gunasekara".equals(result.getFirstElement().getFirstChildWithName(
new QName("http://ws.wso2.org/dataservice/samples/rdbms_sample", "name")).getText());
Assert.assertTrue(name, "Regex bracket expressions testing with nameparams is failed");
}

@Test(groups = "wso2.dss", description = "Invoking insert operation to verify regex support")
public void performInsertQueryWithQMarks() throws XPathExpressionException, AxisFault {
OMElement payload = factory.createOMElement("insert", omNs);
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "insert");
boolean name = "SUCCESSFUL".equals(result.getText());
Assert.assertTrue(name, "insert query testing with question marks is failed");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!--
~ Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~
~ 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.
-->

<data name="RegexTest" serviceNamespace="http://ws.wso2.org/dataservice/samples/rdbms_sample">
<config id="default">
<property name="org.wso2.ws.dataservice.driver">org.h2.Driver</property>
<property name="org.wso2.ws.dataservice.protocol">jdbc:h2:file:./samples/database/DATA_SERV_SAMP</property>
<property name="org.wso2.ws.dataservice.user">wso2ds</property>
<property name="org.wso2.ws.dataservice.password">wso2ds</property>
<property name="org.wso2.ws.dataservice.minpoolsize">1</property>
<property name="org.wso2.ws.dataservice.maxpoolsize">10</property>
<property name="org.wso2.ws.dataservice.autocommit">false</property>
<property name="org.wso2.ws.dataservice.validation_query">SELECT 1</property>
</config>
<query id="regex1" useConfig="default">
<sql>select studentNumber, name, country from Students where name Regexp '^Madha?';</sql>
<result element="Entries" rowName="Entry">
<element column="studentNumber" name="studentNumber" xsdType="string"/>
<element column="name" name="name" xsdType="string"/>
<element column="country" name="country" xsdType="string"/>
</result>
</query>
<query id="regex2" useConfig="default">
<sql>SELECT studentNumber, name, country from Students where name REGEXP '[[:&lt;:]]Madhawa[[:&gt;:]]';</sql>
<result element="Entries" rowName="Entry">
<element column="studentNumber" name="studentNumber" xsdType="string"/>
<element column="name" name="name" xsdType="string"/>
<element column="country" name="country" xsdType="string"/>
</result>
</query>
<query id="regex3" useConfig="default">
<sql>SELECT count(*) from Students where name REGEXP '[[:alnum:]]+';</sql>
<result element="Entries" rowName="Entry" useColumnNumbers="true">
<element column="1" name="Count" xsdType="string"/>
</result>
</query>
<query id="regex4" useConfig="default">
<sql>select :name from Students where name Regexp '^Madha?';</sql>
<result element="Entries" rowName="Entry">
<element column="name" name="name" xsdType="string"/>
</result>
<param name="name" sqlType="QUERY_STRING"/>
</query>
<query id="regex5" useConfig="default">
<sql>SELECT :name from Students where name REGEXP '[[:&lt;:]]Rajith[[:&gt;:]]';</sql>
<result element="Entries" rowName="Entry">
<element column="name" name="name" xsdType="string"/>
</result>
<param name="name" sqlType="QUERY_STRING"/>
</query>
<query id="insert" useConfig="default">
<sql>insert into Students values (006, '?', '?','?','?');</sql>
</query>
<operation name="select_regex1">
<call-query href="regex1"/>
</operation>
<operation name="select_regex2">
<call-query href="regex2"/>
</operation>
<operation name="insert" returnRequestStatus="true">
<call-query href="insert"/>
</operation>
<operation name="select_regex3">
<call-query href="regex3"/>
</operation>
<operation name="select_regex4">
<call-query href="regex4">
<with-param name="name" query-param="name"/>
</call-query>
</operation>
<operation name="select_regex5">
<call-query href="regex5">
<with-param name="name" query-param="name"/>
</call-query>
</operation>
</data>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS Students(
studentNumber INTEGER,
name VARCHAR(50),
phone VARCHAR(50),
state VARCHAR(50),
country VARCHAR(50)
);

CREATE UNIQUE INDEX students_pk ON Students ( studentNumber );


insert into Students values (001, 'Madhawa Gunasekara','0094719411002', 'CMB', 'LK');
insert into Students values (002, 'Madhawa Kasun','0094112956051', 'NY', 'US');
insert into Students values (003, 'Madhu Madhawa Aravindha','097774546546', 'NY', 'US');
insert into Students values (004, 'Rajith Vitharana','097774546546', 'NY', 'US');
insert into Students values (005, 'Anjana Fernando','097774546546', 'NY', 'US');

0 comments on commit 8ec78ef

Please sign in to comment.