Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohandey committed Nov 28, 2024
2 parents c864b89 + 903a655 commit 11d6d65
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 68 deletions.
58 changes: 27 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,43 @@
# MOSIP Functional Tests

## Overview
The **`mosip-functional-tests`** repository contains the reusable **`apitest-commons`** library, which simplifies API testing with pre-built utilities and helpers. The **`apitest-commons`** can be used as a dependency in POM files for MOSIP testrigs of all the modules and can consume the reusable codes.

The API Test Rig Commons is a shared code base that is used for the execution of module-wise automation API tests. This uses Java REST Assured and TestNG frameworks to automate testing for different modules like Pre-registration, Masterdata, Partner Management, PMS, ID Repository, IDA, Resident, E-Signet, and Mimoto.
---

## Pre-requisites
## Repository Structure

Ensure the following software is installed on the machine from where the automation tests will be executed:
This repository consists of:
1. **`apitest-commons`**:
- A reusable library for API testing.
- Released independently to [Maven Central](https://search.maven.org/) under the artifact ID `apitest-commons`.
- Includes its own [README](apitest-commons/README.md) for detailed instructions on setup and usage.

- Java 21
- Maven 3.9.6 or higher
- Lombok (Refer to [Lombok Project](https://projectlombok.org/))
---

### For Windows
## Prerequisites

- Git Bash 2.18.0 or higher
- `settings.xml` needs to be present in the `.m2` folder.
To use this repository, ensure you have:
- **Java 21** ([download here](https://jdk.java.net/)).
- **Maven 3.9.6** or higher ([installation guide](https://maven.apache.org/install.html)).
- Access to necessary MOSIP services or mocked test environments.

### For Linux
---

- `settings.xml` file needs to be present in two places:
- Regular Maven conf folder
- Copy the same `settings.xml` under `/usr/local/maven/conf`
## Apitest Commons

## Access Test Automation Code
### Setting Up and Building the Project
- Refer to the ReadMe file [README](apitest-commons/README.md)

### From Browser
### Using it as dependency in the Project
- Add the following dependency in the POM of required project
```sh
<dependency>
<groupId>io.mosip.testrig.apirig.apitest.commons</groupId>
<artifactId>apitest-commons</artifactId>
<version>1.3.0</version>
</dependency>

1. Clone or download the repository as a zip file from [GitHub](https://github.com/mosip/mosip-functional-tests).
2. Unzip the contents.
3. Continue with the steps below from a terminal (Linux) or command prompt (Windows).

### From Git Bash

1. Copy the git link: `https://github.com/mosip/mosip-functional-tests`
2. On your local system, open Git Bash at any location.
3. Run the following command:
```sh
git clone https://github.com/mosip/mosip-functional-tests

## Build Test Automation Code
1. cd ../apitest-commons
2. `mvn clean install -Dgpg.skip=true -Dmaven.gitcommitid.skip=true`
---

## License
This project is licensed under the terms of [Mozilla Public License 2.0](https://github.com/mosip/mosip-platform/blob/master/LICENSE)
94 changes: 92 additions & 2 deletions apitest-commons/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
# Automation test
# API Test Commons

All automation test code.
## Overview

The API Test Commons is a shared codebase used for executing module-wise automation API tests. It utilizes Java REST Assured and TestNG frameworks to automate testing for various modules, including:
- Pre-registration
- Masterdata
- Partner Management
- PMS
- ID Repository
- IDA
- Resident
- ESignet
- ESignet-signup
- Mimoto
- Inji-Certify

---

## Pre-requisites

Ensure the following software is installed on the machine from where the automation tests will be executed:

- **Java 21** ([download here](https://jdk.java.net/)).
- **Maven 3.9.6** or higher ([installation guide](https://maven.apache.org/install.html)).
- **Lombok** (Refer to [Lombok Project](https://projectlombok.org/))
- **setting.xml** ([download here](https://github.com/mosip/mosip-functional-tests/blob/master/settings.xml))

---

### For Windows

- Git Bash 2.18.0 or higher
- `settings.xml` needs to be present in the `.m2` folder.

### For Linux

- `settings.xml` file needs to be present in two places:
- Regular Maven conf folder
- Copy the same `settings.xml` under `/usr/local/maven/conf`

---

## Access Test Automation Code

### From Browser

1. Clone or download the repository as a zip file from [GitHub](https://github.com/mosip/mosip-functional-tests).
2. Unzip the contents.
3. Continue with the steps below from a terminal (Linux) or command prompt (Windows).

### From Git Bash

1. Copy the git link: `https://github.com/mosip/mosip-functional-tests`
2. Open Git Bash at your desired location on your local systemn.
3. Run the following command to clone the repository:
```sh
git clone https://github.com/mosip/mosip-functional-tests

---

## Update the property file
1. Navigate to the kernel.properties file located at:
```sh
mosip-functional-tests\apitest-commons\src\main\resources\config\kernel.properties
2. Open the file in your preferred editor
3. Update the client secret values and other required credentials as per your environment
---
## Build Test Automation Code
1. From the already opened Git Bash, navigate to the apitest-commons directory:
```sh
cd mosip-functional-tests/apitest-commons/
2. Run the following Maven command:
```sh
mvn clean install -Dgpg.skip=true -Dmaven.gitcommitid.skip=true
---
## Using Apitest Commons as a dependency in the Project
- Add the following dependency in the POM of required project
```sh
<dependency>
<groupId>io.mosip.testrig.apirig.apitest.commons</groupId>
<artifactId>apitest-commons</artifactId>
<version>1.3.0</version>
</dependency>

---

## License
This project is licensed under the terms of [Mozilla Public License 2.0](https://github.com/mosip/mosip-platform/blob/master/LICENSE)
5 changes: 5 additions & 0 deletions apitest-commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus.bundles</groupId>
<artifactId>tyrus-standalone-client</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>io.mosip.authentication</groupId>
<artifactId>authentication-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public void run() {

public static String checkActuatorNoAuth(String actuatorURL) {
Response response = null;
actuatorURL = GlobalMethods.addToServerEndPointMap(actuatorURL);
response = given().contentType(ContentType.JSON).get(actuatorURL);
if (response != null && response.getStatusCode() == 200) {
logger.info(response.getBody().asString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -665,13 +665,16 @@ public void getvalueFromResponseHeader(Response response, String testCaseName) {
if (eachSetCookieValue.trim().startsWith("IDV_TRANSACTION_ID")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "idvTransactionID", testCaseName);
}
if (eachSetCookieValue.trim().startsWith("IDV_SLOT_ALLOTTED")) {
getCookieAndWriteAutoGenId(eachSetCookieValue, "idvSlotAllotted", testCaseName);
}
}
}
}
}

protected void getCookieAndWriteAutoGenId(String cookieValue, String key, String testCaseName) {
if (!cookieValue.split("=")[1].isBlank()) {
if (cookieValue.split("=").length > 1 && !cookieValue.split("=")[1].isBlank()) {
String value = cookieValue.split("=")[1];
writeAutoGeneratedId(testCaseName, key, value);
}
Expand Down Expand Up @@ -720,8 +723,11 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin
JSONObject request = new JSONObject(inputJson);
String encodedResp = null;
String transactionId = null;
String headerTransactionID = "";
String pathFragmentCookie = null;
String pathFragmentCookieTransactionId = null;
Map<String, String> cookiesMap = new HashMap<>();

if (request.has(GlobalConstants.ENCODEDHASH)) {
encodedResp = request.get(GlobalConstants.ENCODEDHASH).toString();
request.remove(GlobalConstants.ENCODEDHASH);
Expand All @@ -742,7 +748,7 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin
request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE_TRANSACTIONID);
request.remove(GlobalConstants.PATH_FRAGMENT_COOKIE);
}

inputJson = request.toString();
if (BaseTestCase.currentModule.equals(GlobalConstants.MIMOTO) || BaseTestCase.currentModule.equals("auth")
|| BaseTestCase.currentModule.equals(GlobalConstants.ESIGNET)
Expand All @@ -751,12 +757,24 @@ protected Response postRequestWithCookieAuthHeaderAndXsrfTokenForAutoGenId(Strin
}

token = properties.getProperty(GlobalConstants.XSRFTOKEN);

if (request.has(GlobalConstants.IDV_TRANSACTION_ID)) {
headerTransactionID = request.get(GlobalConstants.IDV_TRANSACTION_ID).toString();
headers.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.IDV_TRANSACTION_ID_KEY, headerTransactionID);
cookiesMap.put(GlobalConstants.XSRF_TOKEN, token);
request.remove(GlobalConstants.IDV_TRANSACTION_ID);
}

logger.info(GlobalConstants.POST_REQ_URL + url);
GlobalMethods.reportRequest(headers.toString(), inputJson, url);
try {
if (pathFragmentCookie!=null) {
response = RestClient.postRequestWithMultipleHeadersAndMultipleCookies(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, pathFragmentCookieTransactionId, pathFragmentCookie, headers);
} else if (cookiesMap.containsKey(GlobalConstants.IDV_TRANSACTION_ID_KEY)) {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson,
MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON, cookiesMap, headers);
} else {
response = RestClient.postRequestWithMultipleHeadersAndCookies(url, inputJson, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, cookieName, token, headers);
Expand Down Expand Up @@ -794,8 +812,14 @@ protected Response getRequestWithCookieAuthHeaderAndXsrfToken(String url, String
headers.put(XSRF_HEADERNAME, properties.getProperty(GlobalConstants.XSRFTOKEN));
headers.put(OAUTH_HASH_HEADERNAME, encodedResp);
headers.put(OAUTH_TRANSID_HEADERNAME, transactionId);

token = null;

if (request.has(GlobalConstants.IDV_SLOT_ALLOTED)) {
token = request.get(GlobalConstants.IDV_SLOT_ALLOTED).toString();
cookieName = "IDV_SLOT_ALLOTTED";
request.remove(GlobalConstants.IDV_SLOT_ALLOTED);
}
logger.info(GlobalConstants.GET_REQ_STRING + url);
GlobalMethods.reportRequest(headers.toString(), null, url);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public static void getValueForKeyAddToPropertiesMap(Properties props, String key
value = System.getProperty("env.endpoint").replace("api-internal", "signup");
}
propertiesMap.put(key, value);
} else if (key.equalsIgnoreCase("injiCertifyBaseURL")){
String value = null;
if (System.getenv("injiCertifyBaseURL") != null) {
value = System.getenv("injiCertifyBaseURL");
} else {
value = System.getProperty("env.endpoint").replace("api-internal", "injicertify");
}
propertiesMap.put(key, value);
} else if (key.equalsIgnoreCase("mosip_components_base_urls")){
String components_base_urls = System.getenv("mosip_components_base_urls") == null
? props.getProperty("mosip_components_base_urls")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,6 @@ public class GlobalConstants {
public static final String PATH_FRAGMENT_COOKIE_TRANSACTIONID = "pathFragmentCookieTransactionId";
public static final String IDV_TRANSACTION_ID = "idvTransactionID";
public static final String IDV_TRANSACTION_ID_KEY = "IDV_TRANSACTION_ID";
public static final String IDV_SLOT_ALLOTED = "idvSlotAllotted";
public static final String IDV_SLOT_ALLOTED_KEY = "IDV_SLOT_ALLOTTED=";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class GlobalMethods {
public static Set<String> serverEndpoints = new HashSet<>();

// Define the regex pattern to extract the domain and the path after the domain
private static final String module_name = "(mimoto|partnermanager|preregistration|resident|residentmobileapp|masterdata|esignet|idgenerator|policymanager|idauthentication|idrepository|auditmanager|authmanager)";
private static final String module_name = "(mimoto|certify|signup|partnermanager|preregistration|resident|residentmobileapp|masterdata|esignet|idgenerator|policymanager|idauthentication|idrepository|auditmanager|authmanager)";
private static final String regex_1 = "https://([^/]+)/(v[0-9]+)?/" + module_name + "/([^,]+)";
private static final String regex_2 = "https://([^/]+)/" + module_name + "/(v[0-9]+)/([^,]+)";

Expand Down
Loading

0 comments on commit 11d6d65

Please sign in to comment.