Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
Signed-off-by: Nitin Hegde <[email protected]>
  • Loading branch information
hegdenitin authored Nov 15, 2024
2 parents ff8a3af + 3d06199 commit 971949f
Show file tree
Hide file tree
Showing 178 changed files with 4,217 additions and 8,470 deletions.
2 changes: 1 addition & 1 deletion api-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mosipdev/openjdk-21-jre:latest
FROM mosipid/openjdk-21-jre:21.0.4

ARG SOURCE
ARG COMMIT_HASH
Expand Down
153 changes: 151 additions & 2 deletions api-test/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,152 @@
# Automation test
# eSignet API Test Rig

All automation test code.
## Overview

The **eSignet API Test Rig** is designed for the execution of module-wise automation API tests for the eSignet service. This test rig utilizes **Java REST Assured** and **TestNG** frameworks to automate testing of the eSignet API functionalities. The key focus is to validate the authentication, signature generation, and related functionalities provided by the eSignet module.

## Test Categories

- **Smoke**: Contains only positive test scenarios for quick verification.
- **Regression**: Includes all test scenarios, covering both positive and negative cases.

## Coverage

This test rig covers only **external API endpoints** exposed by the eSignet module.

## Pre-requisites

Before running the automation tests, ensure the following software is installed on the machine:

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

### For Windows

- **Git Bash 2.18.0** or higher
- Ensure the `settings.xml` file is present in the `.m2` folder.

### For Linux

- The `settings.xml` file should be present in two places:
- In the regular Maven configuration folder (`/conf`)
- Under `/usr/local/maven/conf/`

## Access Test Automation Code

You can access the test automation code using either of the following methods:

### From Browser

1. Clone or download the repository as a zip file from [GitHub](https://github.com/mosip/esignet).
2. Unzip the contents to your local machine.
3. Open a terminal (Linux) or command prompt (Windows) and continue with the following steps.

### From Git Bash

1. Copy the Git repository URL: `https://github.com/mosip/esignet`
2. Open **Git Bash** on your local machine.
3. Run the following command to clone the repository:
```sh
git clone https://github.com/mosip/esignet
```

## Build Test Automation Code

Once the repository is cloned or downloaded, follow these steps to build and install the test automation code:

1. Navigate to the project directory:
```sh
cd api-test
```

2. Build the project using Maven:
```sh
mvn clean install -Dgpg.skip=true -Dmaven.gitcommitid.skip=true
```

This will download the required dependencies and prepare the test suite for execution.

## Execute Test Automation Suite

You can execute the test automation code using either of the following methods:

### Using Jar

To execute the tests using Jar, use the following steps:

1. Navigate to the `target` directory where the JAR file is generated:
```sh
cd target/
```

2. Run the automation test suite JAR file:
```
java -jar -Dmodules=esignet -Denv.user=api-internal.<env_name> -Denv.endpoint=<base_env> -Denv.testLevel=smokeAndRegression -jar apitest-esignet-1.2.1-SNAPSHOT-jar-with-dependencies.jar
```

# Using Eclipse IDE

To execute the tests using Eclipse IDE, use the following steps:

## 1. **Install Eclipse (Latest Version)**
- Download and install the latest version of Eclipse IDE from the [Eclipse Downloads](https://www.eclipse.org/downloads/).

## 2. **Import the Maven Project**

After Eclipse is installed, follow these steps to import the Maven project:

- Open Eclipse IDE.
- Go to `File` > `Import`.
- In the **Import** wizard, select `Maven` > `Existing Maven Projects`, then click **Next**.
- Browse to the location where the `api-test` folder is saved (either from the cloned Git repository or downloaded zip).
- Select the folder, and Eclipse will automatically detect the Maven project. Click **Finish** to import the project.

## 3. **Build the Project**

- Right-click on the project in the **Project Explorer** and select `Maven` > `Update Project`.
- This will download the required dependencies as defined in the `pom.xml` and ensure everything is correctly set up.

## 4. **Run the Tests**

To execute the test automation suite, you need to configure the run parameters in Eclipse:

- Go to `Run` > `Run Configurations`.
- In the **Run Configurations** window, create a new configuration for your tests:
- Right-click on **Java Application** and select **New**.
- In the **Main** tab, select the project by browsing the location where the `api-test` folder is saved, and select the **Main class** as `io.mosip.testrig.apirig.esignet.testrunner.MosipTestRunner`.
- In the **Arguments** tab, add the necessary **VM arguments**:
- **VM Arguments**:
```
-Dmodules=esignet -Denv.user=api-internal.<env_name> -Denv.endpoint=<base_env> -Denv.testLevel=smokeAndRegression```
## 5. **Run the Configuration**
- Once the configuration is set up, click **Run** to execute the test suite.
- The tests will run, and the results will be shown in the **Console** tab of Eclipse.
**Note**: You can also run in **Debug Mode** to troubleshoot issues by setting breakpoints in your code and choosing `Debug` instead of `Run`.
## 6. **View Test Results**
- After the tests are executed, you can view the detailed results in the `api-test\testng-report` directory.
### Details of Arguments Used
- **env.user**: Replace `<env_name>` with the appropriate environment name (e.g., `dev`, `qa`, etc.).
- **env.endpoint**: The environment where the application under test is deployed. Replace `<base_env>` with the correct base URL for the environment (e.g., `https://api-internal.<env_name>.mosip.net`).
- **env.testLevel**: Set this to `smoke` to run only smoke test cases, or `smokeAndRegression` to run both smoke and regression tests.
- **jar**: Specify the name of the JAR file to execute. The version will change according to the development code version. For example, the current version may look like `apitest-esignet-1.2.1-SNAPSHOT-jar-with-dependencies.jar`.
## Build and Run
To run the tests for both **Smoke** and **Regression**:
1. Ensure the correct environment and test level parameters are set.
2. Execute the tests as shown in the command above to validate eSignet's API functionalities.
## License
This project is licensed under the terms of the [Mozilla Public License 2.0]
2 changes: 1 addition & 1 deletion api-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>
io.mosip.testrig.apirig.testrunner.MosipTestRunner</mainClass>
io.mosip.testrig.apirig.esignet.testrunner.MosipTestRunner</mainClass>
</transformer>
</transformers>
<!-- add this to prevent some security issues when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.testrig.apirig.testrunner;
package io.mosip.testrig.apirig.esignet.testrunner;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -10,6 +10,7 @@
import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand All @@ -24,13 +25,17 @@

import io.mosip.testrig.apirig.dataprovider.BiometricDataProvider;
import io.mosip.testrig.apirig.dbaccess.DBManager;
import io.mosip.testrig.apirig.esignet.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.esignet.utils.EsignetUtil;
import io.mosip.testrig.apirig.report.EmailableReport;
import io.mosip.testrig.apirig.testrunner.BaseTestCase;
import io.mosip.testrig.apirig.testrunner.ExtractResource;
import io.mosip.testrig.apirig.testrunner.HealthChecker;
import io.mosip.testrig.apirig.testrunner.OTPListener;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.AuthTestsUtil;
import io.mosip.testrig.apirig.utils.CertificateGenerationUtil;
import io.mosip.testrig.apirig.utils.CertsUtil;
import io.mosip.testrig.apirig.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.utils.EsignetUtil;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.JWKKeyUtil;
import io.mosip.testrig.apirig.utils.KeyCloakUserAndAPIKeyGeneration;
Expand Down Expand Up @@ -123,6 +128,8 @@ public static void main(String[] arg) {
else
startTestRunner();
} else {
BaseTestCase.isTargetEnvLatest = true;
EsignetUtil.getSupportedLanguage();
startTestRunner();
}

Expand Down Expand Up @@ -191,30 +198,44 @@ public static void startTestRunner() {
homeDir = new File(dir.getParent() + "/mosip/testNgXmlFiles");
LOGGER.info("ELSE :" + homeDir);
}
for (File file : homeDir.listFiles()) {
TestNG runner = new TestNG();
List<String> suitefiles = new ArrayList<>();

if (file.getName().toLowerCase().contains(GlobalConstants.ESIGNET)) {
if (file.getName().toLowerCase().contains("prerequisite")) {
BaseTestCase.setReportName(GlobalConstants.ESIGNET + "-prerequisite");
} else {
// if the prerequisite total skipped/failed count is greater than zero

if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) {
// skipAll = true;
// List and sort the files
File[] files = homeDir.listFiles();
if (files != null) {
Arrays.sort(files, (f1, f2) -> {
// Customize the comparison based on file names
if (f1.getName().toLowerCase().contains("prerequisite")) {
return -1; // f1 should come before f2
} else if (f2.getName().toLowerCase().contains("prerequisite")) {
return 1; // f2 comes before f1
}
return f1.getName().compareTo(f2.getName()); // default alphabetical order
});

for (File file : files) {
TestNG runner = new TestNG();
List<String> suitefiles = new ArrayList<>();

if (file.getName().toLowerCase().contains(GlobalConstants.ESIGNET)) {
if (file.getName().toLowerCase().contains("prerequisite")) {
BaseTestCase.setReportName(GlobalConstants.ESIGNET + "-prerequisite");
} else {
// if the prerequisite total skipped/failed count is greater than zero
if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) {
// skipAll = true;
}

BaseTestCase.setReportName(GlobalConstants.ESIGNET);
}

BaseTestCase.setReportName(GlobalConstants.ESIGNET);
suitefiles.add(file.getAbsolutePath());
runner.setTestSuites(suitefiles);
System.getProperties().setProperty("testng.outpur.dir", "testng-report");
runner.setOutputDirectory("testng-report");
runner.run();
}
suitefiles.add(file.getAbsolutePath());
runner.setTestSuites(suitefiles);
System.getProperties().setProperty("testng.outpur.dir", "testng-report");
runner.setOutputDirectory("testng-report");
runner.run();
}
} else {
LOGGER.error("No files found in directory: " + homeDir);
}

}

public static String getGlobalResourcePath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.testrig.apirig.testscripts;
package io.mosip.testrig.apirig.esignet.testscripts;

import java.lang.reflect.Field;
import java.text.DateFormat;
Expand Down Expand Up @@ -26,12 +26,12 @@

import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.esignet.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.esignet.utils.EsignetUtil;
import io.mosip.testrig.apirig.testrunner.HealthChecker;
import io.mosip.testrig.apirig.testrunner.JsonPrecondtion;
import io.mosip.testrig.apirig.utils.AdminTestException;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.utils.EsignetUtil;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.GlobalMethods;
import io.mosip.testrig.apirig.utils.KernelAuthentication;
Expand Down Expand Up @@ -135,6 +135,10 @@ public void test(TestCaseDTO testCaseDTO) throws Exception {

writeAutoGeneratedId("Esignet_PartnerSelfRegistration_All_Valid_Smoke_sid", "partnerId",
generateRandomNumberString(20));

writeAutoGeneratedId("Esignet_PartnerSelfRegistration_Kyc_Valid_Smoke_sid", "partnerId",
generateRandomNumberString(20));

isvalueReplaced = true;
}
} else {
Expand All @@ -146,8 +150,6 @@ public void test(TestCaseDTO testCaseDTO) throws Exception {
new KernelAuthentication().getTokenByRole(testCaseDTO.getRole())).asString(),
"response.uin");

testCaseName = isTestCaseValidForExecution(testCaseDTO);

DateFormat dateFormatter = new SimpleDateFormat("yyyyMMddHHmmss");
Calendar cal = Calendar.getInstance();
String timestampValue = dateFormatter.format(cal.getTime());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.testrig.apirig.testscripts;
package io.mosip.testrig.apirig.esignet.testscripts;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand All @@ -22,12 +22,12 @@

import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.esignet.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.esignet.utils.EsignetUtil;
import io.mosip.testrig.apirig.testrunner.HealthChecker;
import io.mosip.testrig.apirig.utils.AdminTestException;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.AuthenticationTestException;
import io.mosip.testrig.apirig.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.utils.EsignetUtil;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.ReportUtil;
Expand Down Expand Up @@ -79,7 +79,6 @@ public Object[] getTestCaseList(ITestContext context) {
public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException {
testCaseName = testCaseDTO.getTestCaseName();
testCaseName = EsignetUtil.isTestCaseValidForExecution(testCaseDTO);
testCaseName = isTestCaseValidForExecution(testCaseDTO);
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.mosip.testrig.apirig.testscripts;
package io.mosip.testrig.apirig.esignet.testscripts;

import java.lang.reflect.Field;
import java.util.Base64;
Expand All @@ -23,14 +23,14 @@

import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.esignet.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.esignet.utils.EsignetUtil;
import io.mosip.testrig.apirig.testrunner.BaseTestCase;
import io.mosip.testrig.apirig.testrunner.HealthChecker;
import io.mosip.testrig.apirig.utils.AdminTestException;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.AuthenticationTestException;
import io.mosip.testrig.apirig.utils.BioDataUtility;
import io.mosip.testrig.apirig.utils.EsignetConfigManager;
import io.mosip.testrig.apirig.utils.EsignetUtil;
import io.mosip.testrig.apirig.utils.GlobalConstants;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.ReportUtil;
Expand Down Expand Up @@ -84,9 +84,10 @@ public Object[] getTestCaseList(ITestContext context) {
*/
@Test(dataProvider = "testcaselist")
public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException {
testCaseName = testCaseDTO.getTestCaseName();
testCaseName = EsignetUtil.isTestCaseValidForExecution(testCaseDTO);
testCaseName = isTestCaseValidForExecution(testCaseDTO);
testCaseName = testCaseDTO.getTestCaseName();
if (BaseTestCase.currentModule.equals(GlobalConstants.MASTERDATA)== false) {
testCaseName = EsignetUtil.isTestCaseValidForExecution(testCaseDTO);
}
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
Expand Down
Loading

0 comments on commit 971949f

Please sign in to comment.