This repository has been archived by the owner on Nov 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from madhawa-gunasekara/IntegrationTests
Integration tests for return generated keys and return updated row count
- Loading branch information
Showing
5 changed files
with
260 additions
and
0 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
...sts/src/test/java/org/wso2/dss/integration/test/services/ReturnGeneratedKeysTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.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.carbon.automation.test.utils.concurrency.test.ConcurrencyTest; | ||
import org.wso2.carbon.automation.test.utils.concurrency.test.exception.ConcurrencyTestFailedError; | ||
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; | ||
|
||
/** | ||
* This class performs tests, which related to Return Generated Keys. | ||
*/ | ||
public class ReturnGeneratedKeysTestCase extends DSSIntegrationTest { | ||
private final OMFactory factory = OMAbstractFactory.getOMFactory(); | ||
private final OMNamespace omNs = | ||
factory.createOMNamespace("http://ws.wso2.org/dataservice/samples/returnGeneratedKeysSample", "ns1"); | ||
private final String serviceName = "H2ReturnGeneratedKeysTest"; | ||
|
||
@BeforeClass(alwaysRun = true) | ||
public void serviceDeployment() throws Exception { | ||
super.init(); | ||
List<File> sqlFileLis = new ArrayList<>(); | ||
sqlFileLis.add(selectSqlFile("CreateTables.sql")); | ||
deployService(serviceName, createArtifact(getResourceLocation() + File.separator + "dbs" + File.separator + | ||
"rdbms" + File.separator + "h2" + File.separator + | ||
"H2ReturnGeneratedKeysTest.dbs", sqlFileLis)); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public void destroy() throws Exception { | ||
deleteService(serviceName); | ||
cleanup(); | ||
} | ||
|
||
@Test(groups = "wso2.dss", description = "Invoking insert operation with Return Generated Keys" , dependsOnMethods = "performConcurrencyTest") | ||
public void performInsertWithReturnGeneratedKeysTest() throws AxisFault, XPathExpressionException { | ||
OMElement payload = factory.createOMElement("insertBalance", omNs); | ||
OMElement queryElement = factory.createOMElement("balance", omNs); | ||
queryElement.setText("22.184"); | ||
payload.addChild(queryElement); | ||
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "insertBalance"); | ||
/* id should be 26 because concurrency test has been performed before this method */ | ||
boolean id = "26".equals(result.getFirstElement().getFirstChildWithName( | ||
new QName("http://ws.wso2.org/dataservice/samples/returnGeneratedKeysSample", "ID")).getText()); | ||
Assert.assertTrue(id, "Insert operation with return generated keys is failed"); | ||
} | ||
|
||
@Test(groups = "wso2.dss", description = "Concurrency Test for Return Generated Keys") | ||
public void performConcurrencyTest() throws ConcurrencyTestFailedError, InterruptedException, | ||
XPathExpressionException { | ||
ConcurrencyTest concurrencyTest = new ConcurrencyTest(5, 5); | ||
OMElement payload = factory.createOMElement("insertBalance", omNs); | ||
OMElement queryElement = factory.createOMElement("balance", omNs); | ||
queryElement.setText("144.184"); | ||
payload.addChild(queryElement); | ||
concurrencyTest.run(getServiceUrlHttp(serviceName), payload, "insertBalance"); | ||
} | ||
|
||
} |
95 changes: 95 additions & 0 deletions
95
...s/src/test/java/org/wso2/dss/integration/test/services/ReturnUpdatedRowCountTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* 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.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.carbon.automation.test.utils.concurrency.test.ConcurrencyTest; | ||
import org.wso2.carbon.automation.test.utils.concurrency.test.exception.ConcurrencyTestFailedError; | ||
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; | ||
|
||
/** | ||
* This class performs tests related to Return Updated Row Count. | ||
*/ | ||
public class ReturnUpdatedRowCountTestCase extends DSSIntegrationTest { | ||
private final OMFactory fac = OMAbstractFactory.getOMFactory(); | ||
private final OMNamespace omNs = | ||
fac.createOMNamespace("http://ws.wso2.org/dataservice/samples/returnUpdatedRowCountSample", "ns1"); | ||
private final String serviceName = "H2ReturnUpdatedRowCountTest"; | ||
|
||
@BeforeClass(alwaysRun = true) | ||
public void serviceDeployment() throws Exception { | ||
super.init(); | ||
List<File> sqlFileLis = new ArrayList<>(); | ||
sqlFileLis.add(selectSqlFile("CreateTables.sql")); | ||
sqlFileLis.add(selectSqlFile("Accounts.sql")); | ||
deployService(serviceName, createArtifact(getResourceLocation() + File.separator + "dbs" + File.separator + | ||
"rdbms" + File.separator + "h2" + File.separator + | ||
"H2ReturnUpdatedRowCountTest.dbs", sqlFileLis)); | ||
} | ||
|
||
@AfterClass(alwaysRun = true) | ||
public void destroy() throws Exception { | ||
deleteService(serviceName); | ||
cleanup(); | ||
} | ||
|
||
@Test(groups = "wso2.dss", description = "Invoking update operation with Return Updated Row Count") | ||
public void performUpdateWithReturnUpdatedRowCountTest() throws AxisFault, XPathExpressionException { | ||
OMElement payload = fac.createOMElement("update_Accounts", omNs); | ||
OMElement newBalanceElement = fac.createOMElement("newBalance", omNs); | ||
newBalanceElement.setText("22.184"); | ||
payload.addChild(newBalanceElement); | ||
OMElement oldBalanceElement = fac.createOMElement("oldBalance", omNs); | ||
oldBalanceElement.setText("10.2"); | ||
payload.addChild(oldBalanceElement); | ||
OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), | ||
"update_Accounts"); | ||
boolean id = "10".equals(result.getFirstElement().getFirstChildWithName( | ||
new QName("http://ws.wso2.org/dataservice/samples/returnUpdatedRowCountSample", "COUNT")).getText()); | ||
Assert.assertTrue(id, "Update operation with return update row count is failed"); | ||
} | ||
|
||
@Test(groups = "wso2.dss" , description = "Concurrency Test for Return Updated Row Count" , dependsOnMethods = "performUpdateWithReturnUpdatedRowCountTest") | ||
public void performConcurrencyTest() throws ConcurrencyTestFailedError, InterruptedException, | ||
XPathExpressionException { | ||
ConcurrencyTest concurrencyTest = new ConcurrencyTest(5, 5); | ||
OMElement payload = fac.createOMElement("update_Accounts", omNs); | ||
OMElement newBalanceElement = fac.createOMElement("newBalance", omNs); | ||
newBalanceElement.setText("22.184"); | ||
payload.addChild(newBalanceElement); | ||
OMElement oldBalanceElement = fac.createOMElement("oldBalance", omNs); | ||
oldBalanceElement.setText("10.2"); | ||
payload.addChild(oldBalanceElement); | ||
concurrencyTest.run(getServiceUrlHttp(serviceName), payload, "update_Accounts"); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...gration/tests/src/test/resources/artifacts/DSS/dbs/rdbms/h2/H2ReturnGeneratedKeysTest.dbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<data enableBatchRequests="true" name="H2ReturnGeneratedKeysTest" transports="http https local" baseURI="http://ws.wso2.org/dataservice/samples/returnGeneratedKeysSample"> | ||
<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"/> | ||
</config> | ||
<query id="insertBalanceQuery" returnGeneratedKeys="true" useConfig="default"> | ||
<sql>INSERT INTO Accounts (balance) values (:balance)</sql> | ||
<result element="GeneratedKeys" rowName="Entry" useColumnNumbers="true"> | ||
<element column="1" name="ID" xsdType="integer"/> | ||
</result> | ||
<param name="balance" sqlType="DOUBLE"/> | ||
</query> | ||
<operation name="insertBalance"> | ||
<call-query href="insertBalanceQuery"> | ||
<with-param name="balance" query-param="balance"/> | ||
</call-query> | ||
</operation> | ||
</data> |
42 changes: 42 additions & 0 deletions
42
...ation/tests/src/test/resources/artifacts/DSS/dbs/rdbms/h2/H2ReturnUpdatedRowCountTest.dbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!-- | ||
~ 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 enableBatchRequests="true" name="H2ReturnUpdatedRowCountTest" transports="http https local" baseURI="http://ws.wso2.org/dataservice/samples/returnUpdatedRowCountSample"> | ||
<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"/> | ||
</config> | ||
<query id="update_Accounts_query" returnUpdatedRowCount="true" useConfig="default"> | ||
<sql>UPDATE Accounts SET balance=:newBalance WHERE balance=:oldBalance</sql> | ||
<result element="UpdatedRowCount" rowName="Entry" useColumnNumbers="true"> | ||
<element column="1" name="COUNT" xsdType="integer"/> | ||
</result> | ||
<param name="newBalance" sqlType="DOUBLE"/> | ||
<param name="oldBalance" sqlType="DOUBLE"/> | ||
</query> | ||
<operation name="update_Accounts"> | ||
<call-query href="update_Accounts_query"> | ||
<with-param name="newBalance" query-param="newBalance"/> | ||
<with-param name="oldBalance" query-param="oldBalance"/> | ||
</call-query> | ||
</operation> | ||
</data> |
11 changes: 11 additions & 0 deletions
11
.../integration/tests-integration/tests/src/test/resources/artifacts/DSS/sql/h2/Accounts.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
insert into Accounts values (1,10.2); | ||
insert into Accounts values (2,10.2); | ||
insert into Accounts values (3,10.2); | ||
insert into Accounts values (4,10.2); | ||
insert into Accounts values (5,10.2); | ||
insert into Accounts values (6,10.2); | ||
insert into Accounts values (7,10.2); | ||
insert into Accounts values (8,10.2); | ||
insert into Accounts values (9,10.2); | ||
insert into Accounts values (10,10.2); | ||
insert into Accounts values (11,101.2); |