forked from mosip/mosip-functional-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseTestCase.java
More file actions
677 lines (569 loc) · 26.1 KB
/
Copy pathBaseTestCase.java
File metadata and controls
677 lines (569 loc) · 26.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
package io.mosip.testrig.apirig.testrunner;
import java.io.File;
import java.io.FileInputStream;
import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import javax.ws.rs.core.MediaType;
import org.apache.commons.io.FileUtils;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.json.JSONArray;
import org.json.simple.JSONObject;
import org.testng.annotations.AfterSuite;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.ExtentTest;
import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
import com.nimbusds.jose.jwk.RSAKey;
import io.mosip.testrig.apirig.utils.AdminTestUtil;
import io.mosip.testrig.apirig.utils.ConfigManager;
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.RestClient;
import io.mosip.testrig.apirig.utils.RunConfigUtil;
import io.restassured.RestAssured;
import io.restassured.response.Response;
/**
* This is the main class for TestNG that will setup and begin running tests.
* All suite level before and after tests will be completed here.
*
*/
public class BaseTestCase {
private static Logger logger = Logger.getLogger(BaseTestCase.class);
public static OTPListener otpListener = null;
public static List<String> preIds = new ArrayList<>();
public ExtentHtmlReporter htmlReporter;
public ExtentReports extent;
public ExtentTest test;
protected static String individualToken;
public String preRegAdminToken;
protected static String regClientToken;
public String regProcToken;
public final String COOKIENAME = GlobalConstants.AUTHORIZATION;
public final String IDTOKENCOOKIENAME = "id_token";
public final String ACCESSTOKENCOOKIENAME = "access_token";
public final String COOKIENAMESTATE = "state";
public String idaCookie = null;
public String idrepoCookie = null;
public String regProcCookie = null;
public String regProCookie = null;
public String regAdminCookie = null;
public String invalidcookie = "anyRandomString";
public String registrationOfficerCookie = null;
public String regSupervisorCookie = null;
public String zonalAdminCookie = null;
public String zonalApproverCookie = null;
public String adminCookie = null;
public String testrigCookie = null;
public String partnerCookie = null;
public String partnerauthCookie = null;
public String deviceproviderCookie = null;
public String partnerdeviceCookie = null;
public String partnerftmCookie = null;
public String partneradminCookie = null;
public String partnerNewCookie = null;
public String withoutpartnerCookie = null;
public String withoutpolicyCookie = null;
public String partnerNewKycCookie = null;
public String esignetPartnerCookie = null;
public String esignetPartnerKycCookie = null;
public String policytestCookie = null;
public String residentCookie = null;
public HashMap<String, String> residentNewCookie = new HashMap<>();
public HashMap<String, String> residentNewVidCookie = new HashMap<>();
public String residentNewCookieKc = null;
public String hotlistCookie = null;
public String keycloakCookie = null;
public String zonemapCookie = null;
public String dslUserCookie = null;
public String mobileAuthCookie = null;
public String autoTstUsrCkie = null;
public static String currentModule = GlobalConstants.MASTERDATA;
public static String certsForModule = "DSL";
public static List<String> listOfModules = null;
public static List<String> languageList = new ArrayList<>();
public static String languageCode = null;
public static String dslUser = null;
public static String dslUserPwd = null;
public static List<String> supportedIdType = new ArrayList<>();
public static KernelAuthentication kernelAuthLib = null;
public static Map<?, ?> queries;
public static HashMap<String, String> documentId = new HashMap<>();
public static HashMap<String, String> regCenterId = new HashMap<>();
public static String expiredPreId = null;
public String batchJobToken = null;
public String invalidBatchJobToken = null;
public static List<String> expiredPreRegIds = null;
public static List<String> consumedPreRegIds = null;
public static Map<?, ?> residentQueries;
public static Map<?, ?> partnerQueries;
public static boolean insertDevicedata = false;
public static boolean proxy = true;
public static String ApplnURI;
public static String ApplnURIForKeyCloak;
public static String authToken;
public static String regProcAuthToken;
public static String getStatusRegProcAuthToken;
public static String environment;
public static String testLevel;
public static String adminRegProcAuthToken;
public static String SEPRATOR = "";
public static String buildNumber = "";
public static List<String> t = new ArrayList<>();
private static final char[] alphaNumericAllowed = "abcdefghijklmnopqrstuvwxyzABCDEFGJKLMNPRSTUVWXYZ0123456789"
.toCharArray();
private static final char[] alphabetsAllowed = "abcdefghijklmnopqrstuvwxyzABCDEFGJKLMNPRSTUVWXYZ".toCharArray();
private static final char[] nNumericAllowed = "0123456789".toCharArray();
public static SecureRandom secureRandom = new SecureRandom();
public static String hierarchyName = "";
public static int hierarchyLevel = 0;
public static String parentLocCode = "";
public static String locationName = "";
public static int hierarchyLevelWithLocationCode = 0;
public static String locationCode = "";
public static String ZonelocationCode = "";
public static String leafZoneCode = "";
public static String hierarchyZoneCode = "";
public static String genRid = "27847" + generateRandomNumberString(10);
public static String genPolicyNumber = "9" + generateRandomNumberString(5);
public static String genRidDel = "2785" + generateRandomNumberString(10);
public String genPolicyGroupDesc = "policyGroupForAutomationEsi" + generateRandomNumberString(6);
public String genMispPolicyGroupDesc = "policyGroupForMispEsi" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
public String genPolicyGroupName = "policyGroupNameForAutomationEsi" + generateRandomNumberString(5);
public String genMispPolicyGroupName = "policyGroupNameForMispEsi" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
public String genPolicyDesc = "policyDescForAutomationEsi" + generateRandomNumberString(5);
public String genMispPolicyDesc = "policyDescForMispEsit" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
public String genPolicyName = "policyNameForAutomationEsi" + generateRandomNumberString(4);
public String genPolicyNameNonAuth = "policyNameForEsignet" + generateRandomNumberString(4);
public String genMispPolicyName = "policyNameForMispEsi" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
//public static String genPartnerName = "partnernameforautomationesi-" + generateRandomNumberString(6);
public static String genPartnerName = null;
//public static String genPartnerNameNonAuth = "partnernameforesignet-" + generateRandomNumberString(6);
public static String genPartnerNameNonAuth = BaseTestCase.currentModule + "-partnernameforesignet";
public String genPartnerNameForDsl = "partnernameforautomationdsl-" + generateRandomNumberString(6);
public static String genMispPartnerName = "esignet_" + generateRandomNumberString(6)
+ generateRandomNumberString(3);
public static String genPartnerEmail = "automationpartneresi" + generateRandomNumberString(7)
+ "@automationMosip.com";
public String genPartnerEmailForDsl = "automationpartnerdsl" + generateRandomNumberString(10)
+ "@automationMosip.com";
public String genPartnerEmailNonAuth = "automationesignet" + generateRandomNumberString(10)
+ "@automationMosip.com";
public String genMispPartnerEmail = "misppartner" + generateRandomNumberString(4) + generateRandomNumberString(4)
+ "@automationMosip.com";
public static String publickey;
public static RSAKey rsaJWK;
public static String clientAssertionToken;
private static String zoneMappingRequest = null;
public static Properties props = null;
public static String currentRunningLanguage = "";
private static String cachedPath = null;
private static String runTypeS = "";
protected static String jarURLS = "";
public static String runContext = GlobalMethods.getRunContext();
public static void setLogLevel() {
if (ConfigManager.IsDebugEnabled())
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.ERROR);
}
public static void setRunContext(String runType, String jarURL) {
runTypeS = runType;
jarURLS = jarURL;
}
public static void init() {
props = getproperty(getGlobalResourcePath() + "/" + "config/application.properties");
zoneMappingRequest = "config/Authorization/zoneMappingRequest.json";
}
// Need to handle this
/*
* static String timeStamp =
* String.valueOf(Calendar.getInstance().getTimeInMillis()); static String
* partnerId = "Tech-1245"; static String emailId = "mosip_1" + timeStamp +
* "@gmail.com"; static String role = PartnerRegistration.partnerType;
*/
public static void initializePMSDetails() {
genPartnerName = BaseTestCase.currentModule + "-partnernameforautomationesi";
}
public static String getGlobalResourcePath() {
if (cachedPath != null) {
return cachedPath;
}
String path = null;
if (runTypeS.equalsIgnoreCase("JAR")) {
path = new File(jarURLS).getParentFile().getAbsolutePath() + "/MosipTestResource/MosipTemporaryTestResource";
} else if (runTypeS.equalsIgnoreCase("IDE")) {
path = new File(BaseTestCase.class.getClassLoader().getResource("").getPath()).getAbsolutePath()
+ "/MosipTestResource/MosipTemporaryTestResource";
if (path.contains(GlobalConstants.TESTCLASSES))
path = path.replace(GlobalConstants.TESTCLASSES, "classes");
}
if (path != null) {
cachedPath = path;
return path;
} else {
return "Global Resource File Path Not Found";
}
}
public static void copymoduleSpecificAndConfigFile(String moduleName) {
if (runTypeS.equalsIgnoreCase("JAR")) {
ExtractResource.getListOfFilesFromJarAndCopyToExternalResource(moduleName + "/");
} else {
try {
File destination = new File(RunConfigUtil.getGlobalResourcePath());
File source = new File(RunConfigUtil.getGlobalResourcePath()
.replace("MosipTestResource/MosipTemporaryTestResource", "") + moduleName);
FileUtils.copyDirectoryToDirectory(source, destination);
logger.info("Copied the test resource successfully for " + moduleName);
} catch (Exception e) {
logger.error(
"Exception occured while copying the file for : " + moduleName + " Error : " + e.getMessage());
}
}
}
public static String getOSType() {
String type = System.getProperty("os.name");
if (type.toLowerCase().contains("windows")) {
SEPRATOR = "\\\\";
return "WINDOWS";
} else if (type.toLowerCase().contains("linux") || type.toLowerCase().contains("unix")) {
SEPRATOR = "/";
return "OTHERS";
}
return null;
}
public static void initialize() {
PropertyConfigurator.configure(getLoggerPropertyConfig());
kernelAuthLib = new KernelAuthentication();
queries = AdminTestUtil.readProperty("adminQueries");
partnerQueries = AdminTestUtil.readProperty("partnerQueries");
residentQueries = AdminTestUtil.readProperty("residentServicesQueries");
/**
* Make sure test-output is there
*/
getOSType();
logger.info("We have created a Config Manager. Beginning to read properties!");
environment = System.getProperty("env.user");
logger.info("Environemnt is ==== :" + environment);
ApplnURI = System.getProperty("env.endpoint");
logger.info("Application URI ======" + ApplnURI);
ApplnURIForKeyCloak = System.getProperty("env.keycloak");
logger.info("Application URI ======" + ApplnURIForKeyCloak);
testLevel = System.getProperty("env.testLevel");
logger.info("Test Level ======" + testLevel);
logger.info("Test Level ======" + languageList);
logger.info("Configs from properties file are set.");
}
public static void setReportName(String moduleName) {
System.getProperties().setProperty("emailable.report2.name",
"mosip-" + environment + "-" + moduleName + "-" + getCurrentDateTime() + "-report.html");
}
// Method to get the current date and time in the specified format
public static String getCurrentDateTime() {
// Get the current date and time
LocalDateTime now = LocalDateTime.now();
// Define the desired formatter with the pattern "yyyy-MM-dd_HH:mm:ss"
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm");
// Format the current date and time using the formatter
return now.format(formatter);
}
/**
* After the entire test suite clean up rest assured
*/
@AfterSuite(alwaysRun = true)
public void testTearDown() {
RestAssured.reset();
copyReportAndLog();
logger.info("\n\n");
logger.info("Rest Assured framework has been reset because all tests have been executed.");
logger.info("TESTING COMPLETE: SHUTTING DOWN FRAMEWORK!!");
}
public static Properties getproperty(String path) {
Properties prop = new Properties();
FileInputStream inputStream = null;
try {
File file = new File(path);
inputStream = new FileInputStream(file);
prop.load(inputStream);
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e.getMessage());
} finally {
AdminTestUtil.closeInputStream(inputStream);
}
return prop;
}
private static Properties getLoggerPropertyConfig() {
Properties logProp = new Properties();
logProp.setProperty("log4j.rootLogger", "INFO, Appender1,Appender2");
logProp.setProperty("log4j.appender.Appender1", "org.apache.log4j.ConsoleAppender");
logProp.setProperty("log4j.appender.Appender1.layout", "org.apache.log4j.PatternLayout");
logProp.setProperty("log4j.appender.Appender1.layout.ConversionPattern", "%-7p %d [%t] %c %x - %m%n");
logProp.setProperty("log4j.appender.Appender2", "org.apache.log4j.FileAppender");
logProp.setProperty("log4j.appender.Appender2.File", "src/logs/mosip-api-test.log");
logProp.setProperty("log4j.appender.Appender2.layout", "org.apache.log4j.PatternLayout");
logProp.setProperty("log4j.appender.Appender2.layout.ConversionPattern", "%-7p %d [%t] %c %x - %m%n");
return logProp;
}
private void copyReportAndLog() {
String folderForReport = AdminTestUtil.readProperty("Kernel").get("reportLogPath");
String dirToReport = System.getProperty("user.home") + "/" + folderForReport;
File dest = new File(dirToReport);
if (!dest.exists())
dest.mkdir();
String os = System.getProperty("os.name");
String projDirPath = null;
if (runTypeS.contains("IDE") || os.toLowerCase().contains("windows"))
projDirPath = System.getProperty("user.dir");
else
projDirPath = new File(System.getProperty("user.dir")).getParent();
File reportFolder = new File(projDirPath + "/testng-report");
File logFolder = new File(projDirPath + "/src/logs");
try {
if (dest.listFiles().length != 0)
FileUtils.cleanDirectory(dest);
FileUtils.copyDirectoryToDirectory(reportFolder, dest);
FileUtils.copyDirectoryToDirectory(logFolder, dest);
} catch (Exception e) {
logger.info("Not able to store the log and report at the specified path: " + dirToReport);
logger.error(e.getMessage());
}
logger.info("Copied the logs and reports successfully in folder: " + dirToReport);
}
@SuppressWarnings("unchecked")
public static void mapUserToZone() {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + ConfigManager.getproperty("zoneMappingUrl");
org.json.simple.JSONObject actualrequest = getRequestJson(zoneMappingRequest);
JSONObject request = new JSONObject();
request.put("zoneCode", hierarchyZoneCode);
request.put("userId", BaseTestCase.currentModule + "-" + ConfigManager.getUserAdminName());
request.put("langCode", BaseTestCase.getLanguageList().get(0));
request.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
actualrequest.put(GlobalConstants.REQUEST, request);
logger.info(actualrequest);
Response response = RestClient.postRequestWithCookie(url, actualrequest, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(ConfigManager.getUserAdminName() + "Mapped to" + props.get("zoneCode_to_beMapped") + "Zone");
logger.info(response);
}
// below method is used by dsl.
@SuppressWarnings("unchecked")
public static void mapUserToZone(String user, String zone) {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + ConfigManager.getproperty("zoneMappingUrl");
org.json.simple.JSONObject actualrequest = getRequestJson(zoneMappingRequest);
JSONObject request = new JSONObject();
request.put("zoneCode", zone);
request.put("userId", user);
request.put("langCode", BaseTestCase.getLanguageList().get(0));
request.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
actualrequest.put(GlobalConstants.REQUEST, request);
logger.info(actualrequest);
Response response = RestClient.postRequestWithCookie(url, actualrequest, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(user + "Mapped to" + zone + "Zone");
logger.info(response);
}
public static void mapZone() {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + ConfigManager.getproperty("zoneMappingActivateUrl");
HashMap<String, String> map = new HashMap<>();
map.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
map.put("userId", BaseTestCase.currentModule + "-" + ConfigManager.getUserAdminName());
Response response = RestClient.patchRequestWithCookieAndQueryParm(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(response);
}
public static void mapZone(String user) {
String token = kernelAuthLib.getTokenByRole("globalAdmin");
String url = ApplnURI + ConfigManager.getproperty("zoneMappingActivateUrl");
HashMap<String, String> map = new HashMap<>();
map.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
map.put("userId", user);
Response response = RestClient.patchRequestWithCookieAndQueryParm(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(response);
}
public static boolean zoneName() {
boolean firstUser = true;
String token = kernelAuthLib.getTokenByRole("admin");
String url = ApplnURI + ConfigManager.getproperty("zoneNameUrl");
HashMap<String, String> map = new HashMap<>();
map.put("userID", BaseTestCase.currentModule + "-" + ConfigManager.getUserAdminName());
map.put("langCode", BaseTestCase.getLanguageList().get(0));
Response response = RestClient.getRequestWithCookieAndQueryParm(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(response);
String otpInput = response.getBody().asString();
if (otpInput.contains("KER-MSD-391")) {
firstUser = false;
}
return firstUser;
}
public static void userCenterMapping() {
String token = kernelAuthLib.getTokenByRole("admin");
String url = ApplnURI + ConfigManager.getproperty("userCenterMappingUrl");
HashMap<String, String> requestMap = new HashMap<>();
requestMap.put("id", BaseTestCase.currentModule + "-" + ConfigManager.getUserAdminName());
requestMap.put("name", "automation");
requestMap.put("statusCode", "active");
// TODO remove hardcoding
requestMap.put("regCenterId", "10005");
requestMap.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
requestMap.put("langCode", "eng");
HashMap<String, Object> map = new HashMap<>();
map.put("id", GlobalConstants.STRING);
map.put(GlobalConstants.VERSION, GlobalConstants.STRING);
map.put(GlobalConstants.REQUESTTIME, AdminTestUtil.generateCurrentUTCTimeStamp());
map.put(GlobalConstants.METADATA, new HashMap<>());
map.put(GlobalConstants.REQUEST, requestMap);
Response response = RestClient.postRequestWithCookie(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(response);
}
public static void userCenterMappingStatus() {
String token = kernelAuthLib.getTokenByRole("admin");
String url = ApplnURI + ConfigManager.getproperty("userCenterMappingUrl");
HashMap<String, String> map = new HashMap<>();
map.put(GlobalConstants.ISACTIVE, GlobalConstants.TRUE_STRING);
map.put("id", BaseTestCase.currentModule + "-" + ConfigManager.getUserAdminName());
Response response = RestClient.patchRequestWithCookieAndQueryParm(url, map, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_JSON, GlobalConstants.AUTHORIZATION, token);
logger.info(response);
}
public static JSONArray idaActuatorResponseArray = null;
public static String getValueFromActuators(String endPoint, String section, String key) {
String url = ApplnURI + endPoint;
String value = null;
try {
if (idaActuatorResponseArray == null) {
Response response = null;
org.json.JSONObject responseJson = null;
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
responseJson = new org.json.JSONObject(response.getBody().asString());
idaActuatorResponseArray = responseJson.getJSONArray("propertySources");
}
logger.info("idaActuatorResponseArray=" + idaActuatorResponseArray);
for (int i = 0, size = idaActuatorResponseArray.length(); i < size; i++) {
org.json.JSONObject eachJson = idaActuatorResponseArray.getJSONObject(i);
if (eachJson.get("name").toString().contains(section)) {
value = eachJson.getJSONObject(GlobalConstants.PROPERTIES).getJSONObject(key)
.get(GlobalConstants.VALUE).toString();
logger.info("value=" + value);
break;
}
}
return value;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return value;
}
}
public static List<String> getLanguageList() {
if (!languageList.isEmpty()) {
return languageList;
}
String section = "";
String optionalLanguages = null;
String mandatoryLanguages = null;
section = "/mosip-config/application-default.properties";
try {
optionalLanguages = getValueFromActuators(ConfigManager.getproperty("actuatorMasterDataEndpoint"), section,
"mosip.optional-languages");
logger.info("optionalLanguages from env:" + optionalLanguages);
mandatoryLanguages = getValueFromActuators(ConfigManager.getproperty("actuatorMasterDataEndpoint"), section,
"mosip.mandatory-languages");
logger.info("mandatoryLanguages from env:" + mandatoryLanguages);
} catch (Exception e) {
e.printStackTrace();
}
if (mandatoryLanguages != null && !mandatoryLanguages.isBlank())
languageList.addAll(Arrays.asList(mandatoryLanguages.split(",")));
if (optionalLanguages != null && !optionalLanguages.isBlank())
languageList.addAll(Arrays.asList(optionalLanguages.split(",")));
logger.info("languageList from env:" + languageList);
return languageList;
}
public static void setSupportedIdTypes(List<String> supportedIdTypeList) {
if (supportedIdType.isEmpty())
supportedIdType.addAll(supportedIdTypeList);
}
public static List<String> getSupportedIdTypesValue() {
return supportedIdType;
}
public static List<String> getSupportedIdTypesValueFromActuator() {
if (!supportedIdType.isEmpty()) {
return supportedIdType;
}
String section = "/mosip-config/id-authentication-default.properties";
Response response = null;
org.json.JSONObject responseJson = null;
JSONArray responseArray = null;
String url = ApplnURI + ConfigManager.getproperty("actuatorIDAEndpoint");
try {
response = RestClient.getRequest(url, MediaType.APPLICATION_JSON, MediaType.APPLICATION_JSON);
if (ConfigManager.IsDebugEnabled()) {
GlobalMethods.reportResponse(response.getHeaders().asList().toString(), url, response);
}
responseJson = new org.json.JSONObject(response.getBody().asString());
responseArray = responseJson.getJSONArray("propertySources");
for (int i = 0, size = responseArray.length(); i < size; i++) {
org.json.JSONObject eachJson = responseArray.getJSONObject(i);
logger.info("eachJson is :" + eachJson.toString());
if (eachJson.get("name").toString().contains(section)) {
org.json.JSONObject idTypes = (org.json.JSONObject) eachJson.getJSONObject("properties")
.get("request.idtypes.allowed");
String newIdTypes = idTypes.getString(GlobalConstants.VALUE);
supportedIdType.addAll(Arrays.asList((newIdTypes).split(",")));
break;
}
}
return supportedIdType;
} catch (Exception e) {
logger.error(GlobalConstants.EXCEPTION_STRING_2 + e);
return supportedIdType;
}
}
public static JSONObject getRequestJson(String filepath) {
return AdminTestUtil.readJsonData(filepath, true);
}
public static String generateRandomAlphaNumericString(int length) {
StringBuilder alphaNumericString = new StringBuilder();
for (int i = 0; i < length; i++) {
alphaNumericString.append(alphaNumericAllowed[secureRandom.nextInt(alphaNumericAllowed.length)]);
}
return alphaNumericString.toString();
}
public static String generateRandomAlphabeticString(int length) {
StringBuilder alphaNumericString = new StringBuilder();
for (int i = 0; i < length; i++) {
alphaNumericString.append(alphabetsAllowed[secureRandom.nextInt(alphabetsAllowed.length)]);
}
return alphaNumericString.toString();
}
public static String generateRandomNumberString(int length) {
StringBuilder numericString = new StringBuilder();
for (int i = 0; i < length; i++) {
numericString.append(nNumericAllowed[secureRandom.nextInt(nNumericAllowed.length)]);
}
return numericString.toString();
}
public static int getRecommendedHierarchyLevel() {
String recommendedHierarchLevel = getValueFromActuators(ConfigManager.getproperty("actuatorMasterDataEndpoint"),
"/mosip-config/application-default.properties", "mosip.recommended.centers.locCode");
return Integer.parseInt(recommendedHierarchLevel);
}
}