Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 5 additions & 5 deletions .github/workflows/push-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
build-maven-apitest-inji-certify:
uses: mosip/kattu/.github/workflows/maven-build.yml@master-java21
with:
SERVICE_LOCATION: ./apitest
SERVICE_LOCATION: ./api-test
BUILD_ARTIFACT: apitest-inji-certify
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
Expand All @@ -103,7 +103,7 @@ jobs:
needs: build-maven-apitest-inji-certify
uses: mosip/kattu/.github/workflows/maven-publish-to-nexus.yml@master-java21
with:
SERVICE_LOCATION: ./apitest
SERVICE_LOCATION: ./api-test
secrets:
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_SECRET: ${{ secrets.OSSRH_SECRET }}
Expand All @@ -118,7 +118,7 @@ jobs:
env:
NAMESPACE: ${{ secrets.dev_namespace_docker_hub }}
SERVICE_NAME: apitest-inji-certify
SERVICE_LOCATION: apitest
SERVICE_LOCATION: api-test
BUILD_ARTIFACT: apitest-inji-certify-local
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
strategy:
matrix:
include:
- SERVICE_LOCATION: 'apitest'
- SERVICE_LOCATION: 'api-test'
SERVICE_NAME: 'apitest-inji-certify'
BUILD_ARTIFACT: 'apitest-inji-certify-local'
ONLY_DOCKER: true
Expand All @@ -186,7 +186,7 @@ jobs:
if: "${{ github.event_name != 'pull_request' }}"
uses: mosip/kattu/.github/workflows/maven-sonar-analysis.yml@master-java21
with:
SERVICE_LOCATION: ./apitest
SERVICE_LOCATION: ./api-test
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
ORG_KEY: ${{ secrets.ORG_KEY }}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion apitest/Dockerfile → api-test/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ WORKDIR /home/${container_user}
ENV work_dir=/home/${container_user}

# Combine all necessary files into a single COPY command
COPY ./apitest/target $work_dir/
COPY ./api-test/target $work_dir/
COPY application.properties $work_dir/
COPY ["Biometric Devices", "$work_dir/Biometric Devices"]
COPY ["resource", "$work_dir/resource"]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.mosip.testrig.apirig.dataprovider.BiometricDataProvider;
import io.mosip.testrig.apirig.dbaccess.DBManager;
import io.mosip.testrig.apirig.injicertify.utils.InjiCertifyConfigManager;
import io.mosip.testrig.apirig.injicertify.utils.InjiCertifyUtil;
import io.mosip.testrig.apirig.report.EmailableReport;
import io.mosip.testrig.apirig.testrunner.BaseTestCase;
import io.mosip.testrig.apirig.testrunner.ExtractResource;
Expand Down Expand Up @@ -188,24 +189,50 @@ public static void startTestRunner() {
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.INJICERTIFY)) {
if (file.getName().toLowerCase().contains("prerequisite")) {
BaseTestCase.setReportName(GlobalConstants.INJICERTIFY + "-prerequisite");
} else {
// if the prerequisite total skipped/failed count is greater than zero
if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) {
// skipAll = true;
String useCaseToExecute = InjiCertifyConfigManager.getproperty("useCaseToExecute");

// Split the string by commas
String[] useCases = useCaseToExecute.split(",");

// Loop through the resulting array and print each element
for (String useCase : useCases) {
InjiCertifyUtil.currentUseCase = useCase;

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

if (file.getName().toLowerCase().contains(GlobalConstants.INJICERTIFY)) {
if (file.getName().toLowerCase().contains("prerequisite")) {
if (useCase.equals("sunbird") == true) {
continue;
} else {
if (useCase != null && useCase.isBlank() == false) {
BaseTestCase.setReportName(
GlobalConstants.INJICERTIFY + "-" + useCase + "-prerequisite");
} else {
BaseTestCase.setReportName(GlobalConstants.INJICERTIFY + "-prerequisite");
}
}
} else {
// if the prerequisite total skipped/failed count is greater than zero
if (EmailableReport.getFailedCount() > 0 || EmailableReport.getSkippedCount() > 0) {
// skipAll = true;
}
if (useCase != null && useCase.isBlank() == false) {
BaseTestCase.setReportName(GlobalConstants.INJICERTIFY + "-" + useCase);
} else {
BaseTestCase.setReportName(GlobalConstants.INJICERTIFY);
}

}
BaseTestCase.setReportName(GlobalConstants.INJICERTIFY);
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
package io.mosip.testrig.apirig.injicertify.testscripts;

import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import javax.ws.rs.core.MediaType;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.testng.ITest;
import org.testng.ITestContext;
import org.testng.ITestResult;
import org.testng.Reporter;
import org.testng.SkipException;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.internal.BaseTestMethod;
import org.testng.internal.TestResult;

import io.mosip.testrig.apirig.dto.OutputValidationDto;
import io.mosip.testrig.apirig.dto.TestCaseDTO;
import io.mosip.testrig.apirig.injicertify.utils.InjiCertifyConfigManager;
import io.mosip.testrig.apirig.injicertify.utils.InjiCertifyUtil;
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.GlobalConstants;
import io.mosip.testrig.apirig.utils.GlobalMethods;
import io.mosip.testrig.apirig.utils.KernelAuthentication;
import io.mosip.testrig.apirig.utils.OutputValidationUtil;
import io.mosip.testrig.apirig.utils.ReportUtil;
import io.mosip.testrig.apirig.utils.RestClient;
import io.restassured.response.Response;

public class AddIdentity extends AdminTestUtil implements ITest {
private static final Logger logger = Logger.getLogger(AddIdentity.class);
protected String testCaseName = "";
public Response response = null;
private boolean isWaitRequired = false;

/**
* get current testcaseName
*/
@Override
public String getTestName() {
return testCaseName;

}

@BeforeClass
public static void setLogLevel() {
if (InjiCertifyConfigManager.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
}

/**
* Data provider class provides test case list
*
* @return object of data provider
*/
@DataProvider(name = "testcaselist")
public Object[] getTestCaseList(ITestContext context) {
String ymlFile = context.getCurrentXmlTest().getLocalParameters().get("ymlFile");
logger.info("Started executing yml: " + ymlFile);
return getYmlTestData(ymlFile);
}

/**
* Test method for OTP Generation execution
*
* @param objTestParameters
* @param testScenario
* @param testcaseName
* @throws Exception
*/
@Test(dataProvider = "testcaselist")
public void test(TestCaseDTO testCaseDTO) throws Exception {
testCaseName = testCaseDTO.getTestCaseName();
testCaseName = InjiCertifyUtil.isTestCaseValidForExecution(testCaseDTO);
if (HealthChecker.signalTerminateExecution) {
throw new SkipException(
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS);
}

if (testCaseDTO.getEndPoint().contains("mock-identity-system")) {
String individualIDStr = String.valueOf(Calendar.getInstance().getTimeInMillis());
String phoneStr = generateRandomNumberString(10);
String emailStr = testCaseName + "@mosip.net";
String passWordStr = properties.getProperty("passwordForAddIdentity");
String url = ApplnURI.replace("-internal", "") + testCaseDTO.getEndPoint();

String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());

inputJson = InjiCertifyUtil.inputstringKeyWordHandeler(inputJson, testCaseName);

if (inputJson.contains("$RANDOMINDIVIDUALIDFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$RANDOMINDIVIDUALIDFORMOCKIDENTITY$", individualIDStr);
writeAutoGeneratedId(testCaseName, "UIN", individualIDStr);
}

if (inputJson.contains("$EMAILIDFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$EMAILIDFORMOCKIDENTITY$", emailStr);
writeAutoGeneratedId(testCaseName, "EMAIL", emailStr);
}
if (inputJson.contains("$PASSWORDFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$PASSWORDFORMOCKIDENTITY$", passWordStr);
writeAutoGeneratedId(testCaseName, "PASSWORD", passWordStr);
}
if (inputJson.contains("$PHONEFORMOCKIDENTITY$")) {
inputJson = replaceKeywordWithValue(inputJson, "$PHONEFORMOCKIDENTITY$", phoneStr);
writeAutoGeneratedId(testCaseName, "PHONE", phoneStr);
}

GlobalMethods.reportRequest(null, inputJson, url);

response = RestClient.post(url, inputJson);

GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
} else {
isWaitRequired = true;
testCaseDTO.setInputTemplate(AdminTestUtil.modifySchemaGenerateHbs(testCaseDTO.isRegenerateHbs()));
String uin = JsonPrecondtion.getValueFromJson(
RestClient.getRequestWithCookie(ApplnURI + "/v1/idgenerator/uin", MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, COOKIENAME,
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());
String genRid = "27847" + generateRandomNumberString(10) + timestampValue;

String jsonInput = testCaseDTO.getInput();

String inputJson = getJsonFromTemplate(jsonInput, testCaseDTO.getInputTemplate(), false);

inputJson = inputJson.replace("$UIN$", uin);
inputJson = inputJson.replace("$RID$", genRid);
String phoneNumber = "";
String email = testCaseName + "@mosip.net";
if (inputJson.contains("$PHONENUMBERFORIDENTITY$")) {
if (!phoneSchemaRegex.isEmpty())
try {
phoneNumber = genStringAsperRegex(phoneSchemaRegex);
} catch (Exception e) {
logger.error(e.getMessage());
}
inputJson = replaceKeywordWithValue(inputJson, "$PHONENUMBERFORIDENTITY$", phoneNumber);
inputJson = replaceKeywordWithValue(inputJson, "$EMAILVALUE$", email);
}

response = postWithBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME,
testCaseDTO.getRole(), testCaseDTO.getTestCaseName());

if (testCaseDTO.getTestCaseName().contains("_Pos")) {
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "UIN", uin);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "RID", genRid);
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "EMAIL",
testCaseDTO.getTestCaseName() + "@mosip.net");
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);
}
if (!phoneNumber.isEmpty())
writeAutoGeneratedId(testCaseDTO.getTestCaseName(), "PHONE", phoneNumber);
}

Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation(
response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()),
testCaseDTO, response.getStatusCode());
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid));

if (!OutputValidationUtil.publishOutputResult(ouputValid))
throw new AdminTestException("Failed at output validation");

}

/**
* The method ser current test name to result
*
* @param result
*/
@AfterMethod(alwaysRun = true)
public void setResultTestName(ITestResult result) {
try {
Field method = TestResult.class.getDeclaredField("m_method");
method.setAccessible(true);
method.set(result, result.getMethod().clone());
BaseTestMethod baseTestMethod = (BaseTestMethod) result.getMethod();
Field f = baseTestMethod.getClass().getSuperclass().getDeclaredField("m_methodName");
f.setAccessible(true);
f.set(baseTestMethod, testCaseName);
} catch (Exception e) {
Reporter.log("Exception : " + e.getMessage());
}
}

@AfterClass(alwaysRun = true)
public void waittime() {

try {
if (isWaitRequired == true) {
logger.info("waiting for " + properties.getProperty("Delaytime")
+ " mili secs after UIN Generation In IDREPO");
Thread.sleep(Long.parseLong(properties.getProperty("Delaytime")));
}

} catch (Exception e) {
logger.error("Exception : " + e.getMessage());
Thread.currentThread().interrupt();
}

}
}
Loading
Loading