Skip to content

Commit 885017c

Browse files
MOSIP-38871 - Fixed the DOB hardcording for infants in getApplicantType API (#1157)
* MOSIP-38871 - Fixed the DOB hardcording for infants in getApplicantType api Signed-off-by: Mohanachandran S <mohanachandran.s@technoforte.co.in> * Corrected the report naming Signed-off-by: Mohanachandran S <mohanachandran.s@technoforte.co.in> * Update push-trigger.yml Signed-off-by: Mohanachandran S <165888272+mohanachandran-s@users.noreply.github.com> * MOSIP-38871 - Fixed the DOB hardcording for infants in getApplicantType API Signed-off-by: Mohanachandran S <mohanachandran.s@technoforte.co.in> --------- Signed-off-by: Mohanachandran S <mohanachandran.s@technoforte.co.in> Signed-off-by: Mohanachandran S <165888272+mohanachandran-s@users.noreply.github.com>
1 parent c24384e commit 885017c

File tree

4 files changed

+49
-11
lines changed

4 files changed

+49
-11
lines changed

api-test/src/main/java/io/mosip/testrig/apirig/masterdata/testrunner/MosipTestRunner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ public static void startTestRunner() {
178178
TestNG runner = new TestNG();
179179
List<String> suitefiles = new ArrayList<>();
180180
if (file.getName().toLowerCase().contains("mastertestsuite")) {
181-
BaseTestCase.setReportName(GlobalConstants.MASTERDATA);
182181
suitefiles.add(file.getAbsolutePath());
183182
runner.setTestSuites(suitefiles);
184183
System.getProperties().setProperty("testng.outpur.dir", "testng-report");

api-test/src/main/java/io/mosip/testrig/apirig/masterdata/testscripts/SimplePost.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
public class SimplePost extends AdminTestUtil implements ITest {
3737
private static final Logger logger = Logger.getLogger(SimplePost.class);
38+
private MasterDataUtil masterDataUtil = new MasterDataUtil();
3839
protected String testCaseName = "";
3940
public Response response = null;
4041
public boolean auditLogCheck = false;
@@ -88,6 +89,7 @@ public void test(TestCaseDTO testCaseDTO) throws AuthenticationTestException, Ad
8889
}
8990

9091
String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate());
92+
inputJson = masterDataUtil.inputJsonKeyWordHandeler(inputJson, testCaseName);
9193

9294
if (testCaseDTO.getTemplateFields() != null && templateFields.length > 0) {
9395
ArrayList<JSONObject> inputtestCases = AdminTestUtil.getInputTestCase(testCaseDTO);
Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
package io.mosip.testrig.apirig.masterdata.utils;
22

3+
import java.time.LocalDateTime;
4+
import java.time.format.DateTimeFormatter;
5+
import java.util.HashMap;
6+
37
import org.apache.log4j.Logger;
48
import org.testng.SkipException;
59

10+
import com.google.gson.Gson;
11+
import com.google.gson.reflect.TypeToken;
12+
613
import io.mosip.testrig.apirig.dto.TestCaseDTO;
714
import io.mosip.testrig.apirig.utils.AdminTestUtil;
815
import io.mosip.testrig.apirig.utils.GlobalConstants;
@@ -11,14 +18,44 @@
1118
public class MasterDataUtil extends AdminTestUtil {
1219

1320
private static final Logger logger = Logger.getLogger(MasterDataUtil.class);
14-
21+
public static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
22+
public static String infantDob = LocalDateTime.now().minusYears(getInfantMaxAge()).format(dateFormatter);
23+
1524
public static String isTestCaseValidForExecution(TestCaseDTO testCaseDTO) {
1625
String testCaseName = testCaseDTO.getTestCaseName();
17-
26+
1827
if (SkipTestCaseHandler.isTestCaseInSkippedList(testCaseName)) {
1928
throw new SkipException(GlobalConstants.KNOWN_ISSUES);
2029
}
2130
return testCaseName;
2231
}
23-
32+
33+
public String inputJsonKeyWordHandeler(String jsonString, String testCaseName) {
34+
35+
if (jsonString.contains("$INFANT$")) {
36+
jsonString = replaceKeywordWithValue(jsonString, "$INFANT$", infantDob);
37+
}
38+
39+
return jsonString;
40+
}
41+
42+
private static int getInfantMaxAge() {
43+
HashMap<String, String> map = null;
44+
String ageGroup = getValueFromRegprocActuator("systemProperties",
45+
"mosip.regproc.packet.classifier.tagging.agegroup.ranges");
46+
47+
try {
48+
map = new Gson().fromJson(ageGroup, new TypeToken<HashMap<String, String>>() {
49+
}.getType());
50+
} catch (Exception e) {
51+
logger.error(
52+
GlobalConstants.ERROR_STRING_1 + ageGroup + GlobalConstants.EXCEPTION_STRING_1 + e.getMessage());
53+
}
54+
55+
String infantAgeGroup = map.get("INFANT").toString();
56+
57+
String[] parts = infantAgeGroup.split("-");
58+
return Integer.parseInt(parts[1]);
59+
}
60+
2461
}

api-test/src/main/resources/masterdata/GetApplicantType/GetApplicantType.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ GetApplicantType:
4545
},
4646
{
4747
"attribute": "dateOfBirth",
48-
"value": "2019/01/01"
48+
"value": "$INFANT$"
4949
},
5050
{
5151
"attribute": "gender",
@@ -76,7 +76,7 @@ GetApplicantType:
7676
},
7777
{
7878
"attribute": "dateOfBirth",
79-
"value": "2019/01/01"
79+
"value": "$INFANT$"
8080
},
8181
{
8282
"attribute": "gender",
@@ -169,7 +169,7 @@ GetApplicantType:
169169
},
170170
{
171171
"attribute": "dateOfBirth",
172-
"value": "2019/01/01"
172+
"value": "$INFANT$"
173173
},
174174
{
175175
"attribute": "gender",
@@ -428,7 +428,7 @@ GetApplicantType:
428428
},
429429
{
430430
"attribute": "dateOfBirth",
431-
"value": "2019/01/01"
431+
"value": "$INFANT$"
432432
},
433433
{
434434
"attribute": "gender",
@@ -459,7 +459,7 @@ GetApplicantType:
459459
},
460460
{
461461
"attribute": "dateOfBirth",
462-
"value": "2019/01/01"
462+
"value": "$INFANT$"
463463
},
464464
{
465465
"attribute": "gender",
@@ -552,7 +552,7 @@ GetApplicantType:
552552
},
553553
{
554554
"attribute": "dateOfBirth",
555-
"value": "2019/01/01"
555+
"value": "$INFANT$"
556556
},
557557
{
558558
"attribute": "gender",
@@ -583,7 +583,7 @@ GetApplicantType:
583583
},
584584
{
585585
"attribute": "dateOfBirth",
586-
"value": "2019/01/01"
586+
"value": "$INFANT$"
587587
},
588588
{
589589
"attribute": "gender",

0 commit comments

Comments
 (0)