forked from mosip/admin-services
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MOSIP-32363 JAVA 21 upgrade (mosip#962)
Signed-off-by: Mohanachandran S <[email protected]> Signed-off-by: dhanendra06 <[email protected]>
- Loading branch information
1 parent
05a5522
commit 88323db
Showing
3 changed files
with
182 additions
and
156 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
173 changes: 173 additions & 0 deletions
173
apitest/src/main/java/io/mosip/testrig/apirig/testscripts/PutWithPathParamsAndBody.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,173 @@ | ||
package io.mosip.testrig.apirig.testscripts; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.apache.log4j.Level; | ||
import org.apache.log4j.Logger; | ||
import org.json.JSONObject; | ||
import org.testng.ITest; | ||
import org.testng.ITestContext; | ||
import org.testng.ITestResult; | ||
import org.testng.Reporter; | ||
import org.testng.SkipException; | ||
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.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.ConfigManager; | ||
import io.mosip.testrig.apirig.utils.GlobalConstants; | ||
import io.mosip.testrig.apirig.utils.OutputValidationUtil; | ||
import io.mosip.testrig.apirig.utils.ReportUtil; | ||
import io.restassured.response.Response; | ||
|
||
public class PutWithPathParamsAndBody extends AdminTestUtil implements ITest { | ||
private static final Logger logger = Logger.getLogger(PutWithPathParamsAndBody.class); | ||
protected String testCaseName = ""; | ||
String pathParams = null; | ||
public Response response = null; | ||
|
||
@BeforeClass | ||
public static void setLogLevel() { | ||
if (ConfigManager.IsDebugEnabled()) | ||
logger.setLevel(Level.ALL); | ||
else | ||
logger.setLevel(Level.ERROR); | ||
} | ||
|
||
/** | ||
* get current testcaseName | ||
*/ | ||
@Override | ||
public String getTestName() { | ||
return testCaseName; | ||
} | ||
|
||
/** | ||
* 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"); | ||
pathParams = context.getCurrentXmlTest().getLocalParameters().get("pathParams"); | ||
logger.info("Started executing yml: " + ymlFile); | ||
return getYmlTestData(ymlFile); | ||
} | ||
|
||
/** | ||
* Test method for OTP Generation execution | ||
* | ||
* @param objTestParameters | ||
* @param testScenario | ||
* @param testcaseName | ||
* @throws AuthenticationTestException | ||
* @throws AdminTestException | ||
*/ | ||
@Test(dataProvider = "testcaselist") | ||
public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, AdminTestException { | ||
testCaseName = testCaseDTO.getTestCaseName(); | ||
String[] templateFields = testCaseDTO.getTemplateFields(); | ||
if (HealthChecker.signalTerminateExecution) { | ||
throw new SkipException( | ||
GlobalConstants.TARGET_ENV_HEALTH_CHECK_FAILED + HealthChecker.healthCheckFailureMapS); | ||
} | ||
|
||
testCaseDTO = AdminTestUtil.filterHbs(testCaseDTO); | ||
String inputJson = filterInputHbs(testCaseDTO); | ||
|
||
if (testCaseDTO.getTemplateFields() != null && templateFields.length > 0) { | ||
ArrayList<JSONObject> inputtestCases = AdminTestUtil.getInputTestCase(testCaseDTO); | ||
ArrayList<JSONObject> outputtestcase = AdminTestUtil.getOutputTestCase(testCaseDTO); | ||
for (int i = 0; i < languageList.size(); i++) { | ||
response = putWithPathParamsBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), | ||
getJsonFromTemplate(inputtestCases.get(i).toString(), testCaseDTO.getInputTemplate()), | ||
COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams); | ||
|
||
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil.doJsonOutputValidation( | ||
response.asString(), | ||
getJsonFromTemplate(outputtestcase.get(i).toString(), testCaseDTO.getOutputTemplate()), | ||
testCaseDTO, response.getStatusCode()); | ||
Reporter.log(ReportUtil.getOutputValidationReport(ouputValid)); | ||
|
||
if (!OutputValidationUtil.publishOutputResult(ouputValid)) | ||
throw new AdminTestException("Failed at output validation"); | ||
} | ||
} | ||
|
||
else { | ||
response = putWithPathParamsBodyAndCookie(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME, | ||
testCaseDTO.getRole(), testCaseDTO.getTestCaseName(), pathParams); | ||
} | ||
Map<String, List<OutputValidationDto>> ouputValid = null; | ||
|
||
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"); | ||
} | ||
|
||
|
||
|
||
private String filterOutputHbs(TestCaseDTO testCaseDTO) { | ||
String outputJson = getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate()); | ||
|
||
if (outputJson.contains(GlobalConstants.$1STLANG$)) | ||
outputJson = outputJson.replace(GlobalConstants.$1STLANG$, BaseTestCase.languageList.get(0)); | ||
if (outputJson.contains(GlobalConstants.$2STLANG$)) | ||
outputJson = outputJson.replace(GlobalConstants.$2STLANG$, BaseTestCase.languageList.get(1)); | ||
if (outputJson.contains(GlobalConstants.$3STLANG$)) | ||
outputJson = outputJson.replace(GlobalConstants.$3STLANG$, BaseTestCase.languageList.get(2)); | ||
return outputJson; | ||
} | ||
|
||
private String filterInputHbs(TestCaseDTO testCaseDTO) { | ||
String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()); | ||
|
||
if (inputJson.contains(GlobalConstants.$1STLANG$)) | ||
inputJson = inputJson.replace(GlobalConstants.$1STLANG$, BaseTestCase.languageList.get(0)); | ||
if (inputJson.contains(GlobalConstants.$2STLANG$)) | ||
inputJson = inputJson.replace(GlobalConstants.$2STLANG$, BaseTestCase.languageList.get(1)); | ||
if (inputJson.contains(GlobalConstants.$3STLANG$)) | ||
inputJson = inputJson.replace(GlobalConstants.$3STLANG$, BaseTestCase.languageList.get(2)); | ||
|
||
return inputJson; | ||
} | ||
|
||
/** | ||
* 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()); | ||
} | ||
} | ||
} |
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