diff --git a/apitest/pom.xml b/apitest/pom.xml index a9d164221e0..34ba76aea0b 100644 --- a/apitest/pom.xml +++ b/apitest/pom.xml @@ -5,10 +5,10 @@ io.mosip.masterdata apitest-masterdata jar - automationtests-masterdata - Parent project of MOSIP functional tests - https://github.com/mosip/mosip-functional-tests - 1.2.0.1-SNAPSHOT + apitest-masterdata + Parent project of MOSIP Admin Services apitests + https://github.com/mosip/admin-services + 1.2.1-java21-SNAPSHOT @@ -18,166 +18,19 @@ - scm:git:git://github.com/mosip/mosip-functional-tests.git - scm:git:ssh://github.com:mosip/mosip-functional-tests.git - https://github.com/mosip/mosip-functional-tests + scm:git:git://github.com/mosip/admin-services.git + scm:git:ssh://github.com:mosip/admin-services.git + https://github.com/mosip/admin-services HEAD - - - - - UTF-8 - - - 11 - 11 - 3.7.0 - 3.0.2 - 3.1.0 - 2.9 - 0.8.1 - 3.2 - 3.0.1 - 2.3 - false - 3.7.0.1746 - - 2.0.2.RELEASE - 2.0.7.RELEASE - 5.0.5.RELEASE - 2.0.0.RELEASE - - 2.0.7 - 1.5.20 - 2.9.2 - - 3.6.2 - 3.7.0 - - - - 1.2 - 3.0.0 - 1.3 - 2.2 - 2.0.1.Final - 2.2.6 - - - 1.4.197 - 5.1.46 - 42.2.2 - 2.5.0 - 6.0.12.Final - - - 1.10.19 - 1.7.4 - 2.0.0-beta.5 - - - 3.6.1 - 3.7 - 2.6 - 1.11 - 4.3 - 1.9.2 - 2.2 - 4.5.6 - 19.0 - 1.18.8 - 0.1.54 - 1.4.0 - 7.1.0 - 2.0.0 - 5.5.13 - 2.3.23 - 1.7 - 2.0 - 1.5.2 - 2.1.1 - 1.60 - 63.1 - 1.0.0 - 3.3.3 - 2.8.1 - 4.1.0-incubating - 1.11.368 - 0.2.4 - 2.3.0 - 3.0.1 - 1.9.12 - 0.6.0 - 2.0.0.AM2 - - - - - - - - 0.8.2 - 2.2 - 3.2 - UTF-8 - 3.7.0 - 3.0.1 - - - 1.1.6 - 1.7.19 - 1.10.19 - - - 1.4.6 - - - 5.0.6.RELEASE - - - 5.4.2.Final - - - 2.1.1 - - - 10.13.1.1 - - - 3.4.0 - - - 1.3.5 - - - 0.3.12 - - - 0.3.0 - - - 1.1.2-incubating - 1.2.0.1-B1 - 0.4.7 - 3.0.0 - 2.41.2 - 2.4.0 - 3.3.9 - 3.0.7 - 6.11 - 1.13 - automationtests-commons-1.2.0.1-SNAPSHOT-jar-with-dependencies - - io.mosip.testrig.apirig.automationtests.commons automationtests-commons - 1.2.0.1-SNAPSHOT + 1.2.1-java21-SNAPSHOT diff --git a/apitest/src/main/java/io/mosip/testrig/apirig/testscripts/PutWithPathParamsAndBody.java b/apitest/src/main/java/io/mosip/testrig/apirig/testscripts/PutWithPathParamsAndBody.java new file mode 100644 index 00000000000..0568bef1d67 --- /dev/null +++ b/apitest/src/main/java/io/mosip/testrig/apirig/testscripts/PutWithPathParamsAndBody.java @@ -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 inputtestCases = AdminTestUtil.getInputTestCase(testCaseDTO); + ArrayList 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> 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> 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()); + } + } +} diff --git a/apitest/testNgXmlFiles/masterdataApi.xml b/apitest/testNgXmlFiles/masterdataApi.xml index bae548fab36..7edff8adeda 100644 --- a/apitest/testNgXmlFiles/masterdataApi.xml +++ b/apitest/testNgXmlFiles/masterdataApi.xml @@ -5,7 +5,7 @@ - +