-
Notifications
You must be signed in to change notification settings - Fork 3
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 ballerina-platform/coverage
Increase code coverage
- Loading branch information
Showing
12 changed files
with
187 additions
and
8 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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,50 @@ | ||
# Running Tests | ||
|
||
The SAP connector supports two test environments. The primary environment is a mock server, specifically designed to handle CSRF token expiry. The secondary environment utilizes the S/4HANA Sales Order (A2X) API. Each environment has a unique set of compatible tests that can be executed independently. | ||
|
||
Test Groups | Environment | ||
---| --- | ||
mock | Mock server | ||
sap | S/4HANA API | ||
|
||
**Note**: By default, the Gradle build enables tests for both environments. However, in GitHub workflows, the S/4HANA environment tests are disabled due to the lack of continuous access to the S/4HANA environment. | ||
|
||
## Running Tests in the Mock Server Only | ||
|
||
```sh | ||
bal test --disable-groups sap | ||
``` | ||
|
||
```sh | ||
./gradlew clean build -Pdisable=sap | ||
``` | ||
|
||
## Running Tests in S/4HANA API Only | ||
|
||
**Note**: The test case designed to handle the CSRF token expiry scenario may take approximately 35 minutes to run due to the configuration in S/4HANA setup. | ||
|
||
### Prerequisites | ||
|
||
### 1. Setup the S/4HANA API | ||
|
||
Refer to the [Setup Guide](https://central.ballerina.io/ballerinax/sap/latest#setup-guide) for the necessary credentials (hostname, username, password). | ||
|
||
### 2. Configuration | ||
|
||
Create a `Config.toml` file in the tests directory and add your authentication credentials. | ||
|
||
```toml | ||
hostname="<Hostname>" | ||
username="<Username>" | ||
password="<Password>" | ||
``` | ||
|
||
### 3. Run tests | ||
|
||
```sh | ||
bal test --groups sap | ||
``` | ||
|
||
```sh | ||
./gradlew clean build -Pgroups=sap | ||
``` |
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,59 @@ | ||
// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
// | ||
// WSO2 LLC. 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. | ||
|
||
import ballerina/http; | ||
import ballerina/lang.runtime; | ||
import ballerina/test; | ||
|
||
configurable string hostname = ""; | ||
configurable string username = ""; | ||
configurable string password = ""; | ||
|
||
// This test is run against the SAP Sales Order API. | ||
Client s4HanaClient = check new (string `https://${hostname}/sap/opu/odata/sap/API_SALES_ORDER_SRV`, { | ||
auth: { | ||
username, | ||
password | ||
} | ||
}); | ||
|
||
@test:Config { | ||
groups: ["sap"] | ||
} | ||
function testCSRFTokenRefresh() returns error? { | ||
json body = { | ||
"SalesOrder": "1234", | ||
"SalesOrderType": "OR", | ||
"SalesOrganization": "1710", | ||
"DistributionChannel": "10", | ||
"OrganizationDivision": "00", | ||
"SalesGroup": "170", | ||
"SalesOffice": "170", | ||
"RequestedDeliveryDate": "2024-04-13T12:00", | ||
"SoldToParty": "17100001", | ||
"PurchaseOrderByCustomer": "12345" | ||
}; | ||
|
||
http:Response response = check s4HanaClient->/A_SalesOrder.post(body); | ||
test:assertEquals(response.statusCode, 404, "Status code should be 404, this creates a partial sales order meant to fail"); | ||
|
||
// Sleep for 33 m to allow the CSRF token to expire | ||
runtime:sleep(2000); | ||
|
||
// Try again. If the csrf token is refreshed we expect 404 this time too | ||
response = check s4HanaClient->/A_SalesOrder.post(body); | ||
test:assertEquals(response.statusCode, 404, "Status code should be 404, this creates a partial sales order meant to fail"); | ||
} |
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