-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from thisisharshit/1.2.0-rc2
Automated and added testscript for notification API
- Loading branch information
Showing
11 changed files
with
458 additions
and
5 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
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
131 changes: 131 additions & 0 deletions
131
...ontests/src/main/java/io/mosip/testscripts/PostWithFormDataAndFileForNotificationAPI.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,131 @@ | ||
package io.mosip.testscripts; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
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.annotations.AfterMethod; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import org.testng.internal.BaseTestMethod; | ||
import org.testng.internal.TestResult; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
|
||
import io.mosip.admin.fw.util.AdminTestException; | ||
import io.mosip.admin.fw.util.AdminTestUtil; | ||
import io.mosip.admin.fw.util.TestCaseDTO; | ||
import io.mosip.authentication.fw.dto.OutputValidationDto; | ||
import io.mosip.authentication.fw.util.AuthenticationTestException; | ||
import io.mosip.authentication.fw.util.OutputValidationUtil; | ||
import io.mosip.authentication.fw.util.ReportUtil; | ||
import io.mosip.service.BaseTestCase; | ||
import io.restassured.response.Response; | ||
|
||
public class PostWithFormDataAndFileForNotificationAPI extends AdminTestUtil implements ITest { | ||
private static final Logger logger = Logger.getLogger(PostWithFormDataAndFileForNotificationAPI.class); | ||
protected String testCaseName = ""; | ||
String idKeyName = null; | ||
public Response response = null; | ||
/** | ||
* 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"); | ||
idKeyName = context.getCurrentXmlTest().getLocalParameters().get("idKeyName"); | ||
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(); | ||
testCaseDTO=AdminTestUtil.filterHbs(testCaseDTO); | ||
|
||
String inputJson = filterInputHbs(testCaseDTO); | ||
|
||
response = postWithMultipartFormDataAndFile(ApplnURI + testCaseDTO.getEndPoint(), inputJson, COOKIENAME, testCaseDTO.getRole(), testCaseDTO.getTestCaseName(),idKeyName); | ||
|
||
Map<String, List<OutputValidationDto>> ouputValid = OutputValidationUtil | ||
.doJsonOutputValidation(response.asString(), getJsonFromTemplate(testCaseDTO.getOutput(), testCaseDTO.getOutputTemplate())); | ||
Reporter.log(ReportUtil.getOutputValiReport(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("$1STLANG$")) | ||
outputJson = outputJson.replace("$1STLANG$", BaseTestCase.languageList.get(0)); | ||
if (outputJson.contains("$2NDLANG$")) | ||
outputJson = outputJson.replace("$2NDLANG$", BaseTestCase.languageList.get(1)); | ||
if (outputJson.contains("$3RDLANG$")) | ||
outputJson = outputJson.replace("$3RDLANG$", BaseTestCase.languageList.get(2)); | ||
return outputJson; | ||
} | ||
|
||
private String filterInputHbs(TestCaseDTO testCaseDTO) { | ||
String inputJson = getJsonFromTemplate(testCaseDTO.getInput(), testCaseDTO.getInputTemplate()); | ||
|
||
if (inputJson.contains("$1STLANG$")) | ||
inputJson = inputJson.replace("$1STLANG$", BaseTestCase.languageList.get(0)); | ||
if (inputJson.contains("$2NDLANG$")) | ||
inputJson = inputJson.replace("$2NDLANG$", BaseTestCase.languageList.get(1)); | ||
if (inputJson.contains("$3RDLANG$")) | ||
inputJson = inputJson.replace("$3RDLANG$", 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
98 changes: 98 additions & 0 deletions
98
automationtests/src/main/resources/preReg/SendNotifications/SendNotifications.yml
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,98 @@ | ||
SendNotifications: | ||
Prereg_SendNotifications_All_Valid_Smoke: | ||
endPoint: /preregistration/v1/notification | ||
role: batch | ||
restMethod: post | ||
inputTemplate: preReg/SendNotifications/sendNotifications_$LANGNUMBER$ | ||
outputTemplate: preReg/SendNotifications/sendNotificationsResult | ||
input: '{ | ||
"id":"mosip.pre-registration.notification.notify", | ||
"version":"1.0", | ||
"requesttime":"$TIMESTAMP$", | ||
"name":"Test Book appointment", | ||
"preRegistrationId":"$ID:CreatePrereg_All_Valid_Smoke_BookByPRID_sid_preRegistrationId$", | ||
"appointmentDate":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_appointment_date$", | ||
"appointmentTime":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_time_slot_from$", | ||
"mobNum":"8249742850", | ||
"emailID":"[email protected]", | ||
"additionalRecipient":false, | ||
"isBatch":false | ||
}' | ||
output: '{ | ||
"message": "Email and sms request successfully submitted" | ||
}' | ||
Prereg_SendNotifications_Notify_All_Valid_Smoke: | ||
endPoint: /preregistration/v1/notification/notify | ||
role: batch | ||
restMethod: post | ||
inputTemplate: preReg/SendNotifications/sendNotificationsNotify | ||
outputTemplate: preReg/SendNotifications/sendNotificationsResult | ||
input: '{ | ||
"id":"mosip.pre-registration.notification.notify", | ||
"version":"1.0", | ||
"requesttime":"$TIMESTAMP$", | ||
"name":"Test Book appointment", | ||
"preRegistrationId":"$ID:CreatePrereg_All_Valid_Smoke_BookByPRID_sid_preRegistrationId$", | ||
"appointmentDate":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_appointment_date$", | ||
"appointmentTime":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_time_slot_from$", | ||
"mobNum":"8249742850", | ||
"emailID":"[email protected]", | ||
"isBatch":true | ||
}' | ||
output: '{ | ||
"message": "Email and sms request successfully submitted" | ||
}' | ||
Prereg_SendNotifications_InValid_id: | ||
endPoint: /preregistration/v1/notification | ||
role: batch | ||
restMethod: post | ||
inputTemplate: preReg/SendNotifications/sendNotifications_$LANGNUMBER$ | ||
outputTemplate: preReg/error | ||
input: '{ | ||
"id":"mosip.pre-registration.notification.notifyasdf", | ||
"version":"1.0", | ||
"requesttime":"$TIMESTAMP$", | ||
"name":"Test Book appointment", | ||
"preRegistrationId":"$ID:CreatePrereg_All_Valid_Smoke_BookByPRID_sid_preRegistrationId$", | ||
"appointmentDate":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_appointment_date$", | ||
"appointmentTime":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_time_slot_from$", | ||
"mobNum":"8249742850", | ||
"emailID":"[email protected]", | ||
"additionalRecipient":false, | ||
"isBatch":false | ||
}' | ||
output: '{ | ||
"errors": [ | ||
{ | ||
"errorCode": "PRG_PAM_CORE_001", | ||
"message": "Request id is invalid" | ||
} | ||
] | ||
}' | ||
Prereg_SendNotifications_InValid_preRegId: | ||
endPoint: /preregistration/v1/notification | ||
role: batch | ||
restMethod: post | ||
inputTemplate: preReg/SendNotifications/sendNotifications_$LANGNUMBER$ | ||
outputTemplate: preReg/error | ||
input: '{ | ||
"id":"mosip.pre-registration.notification.notify", | ||
"version":"1.0", | ||
"requesttime":"$TIMESTAMP$", | ||
"name":"Test Book appointment", | ||
"preRegistrationId":"sadgf", | ||
"appointmentDate":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_appointment_date$", | ||
"appointmentTime":"$ID:GetAppointmentDetails_BookByPRID_All_Valid_Smoke_sid_time_slot_from$", | ||
"mobNum":"8249742850", | ||
"emailID":"[email protected]", | ||
"additionalRecipient":false, | ||
"isBatch":false | ||
}' | ||
output: '{ | ||
"errors": [ | ||
{ | ||
"errorCode": "PRG_PAM_APP_005", | ||
"message": "No data found for the requested pre-registration id" | ||
} | ||
] | ||
}' |
Oops, something went wrong.