diff --git a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateIssuerTest.java b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateIssuerTest.java index 61f8f1ec..ea5efa22 100644 --- a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateIssuerTest.java +++ b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateIssuerTest.java @@ -10,19 +10,34 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpStatus; -import org.sunbird.common.util.HttpUtil; -import org.sunbird.integration.test.user.EndpointConfig.TestGlobalProperty; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; -public class CreateIssuerTest extends TestNGCitrusTestDesigner { +import org.sunbird.common.util.HttpUtil; +import org.sunbird.integration.test.common.BaseCitrusTest; +import org.sunbird.integration.test.user.EndpointConfig.TestGlobalProperty; + + +public class CreateIssuerTest extends BaseCitrusTest { public static final String TEST_NAME_CREATE_ISSUER_SUCCESS = "createIssuerSuccess"; - public static final String TEST_NAME_CREATE_ISSUER_WITH_IMAGE_SUCCESS = "createIssuerWithImageSuccess"; + public static final String TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE = "createIssuerSuccessWithImage"; + public static final String TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME = "createIssuerFailureWithoutName"; + public static final String TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION = "createIssuerFailureWithoutDescription"; + public static final String TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL = "createIssuerFailureWithoutUrl"; + public static final String TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL = "createIssuerFailureWithInvalidUrl"; + public static final String TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL = "createIssuerFailureWithoutEmail"; + public static final String TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL = "createIssuerFailureWithInvalidEmail"; public static final String TEMPLATE_DIR = "templates/badge/issuer/create"; public static final String TEST_DIR_CREATE_ISSUER_SUCCESS = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_SUCCESS); - public static final String TEST_DIR_CREATE_ISSUER_WITH_IMAGE_SUCCESS = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_WITH_IMAGE_SUCCESS); + public static final String TEST_DIR_CREATE_ISSUER_SUCCESS_WITH_IMAGE = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE); + public static final String TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_NAME = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME); + public static final String TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION); + public static final String TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_URL = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL); + public static final String TEST_DIR_CREATE_ISSUER_FAILURE_WITH_INVALID_URL = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL); + public static final String TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL); + public static final String TEST_DIR_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL = MessageFormat.format("{0}/{1}/", TEMPLATE_DIR, TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL); public static final String REQUEST_FORM_DATA = "request.params"; public static final String RESPONSE_JSON = "response.json"; @@ -32,35 +47,14 @@ public class CreateIssuerTest extends TestNGCitrusTestDesigner { @Autowired private TestGlobalProperty initGlobalValues; private String getCreateIssuerUrl() { + System.out.println("initGlobalValues = " + initGlobalValues); return initGlobalValues.getLmsUrl().contains("localhost") ? "/v1/issuer/create" : "/api/badging/v1/issuer/create"; } - private void performTest( - String testName, - HttpClient httpClient, - TestGlobalProperty config, - String url, - String requestFormData, - String responseJson) { - System.out.println(requestFormData); - - getTestCase().setName(testName); - - String testFolderPath = MessageFormat.format("{0}/{1}", TEMPLATE_DIR, testName); - - new HttpUtil().multipartPost(http().client(httpClient), config, url, requestFormData, testFolderPath); - - http() - .client(httpClient) - .receive() - .response(HttpStatus.OK) - .payload(new ClassPathResource(responseJson)); - } - - @DataProvider(name = "createIssuerDataProvider") - public Object[][] createIssuerDataProvider() { + @DataProvider(name = "createIssuerDataProviderSuccess") + public Object[][] createIssuerDataProviderSuccess() { return new Object[][] { new Object[]{ TEST_DIR_CREATE_ISSUER_SUCCESS + REQUEST_FORM_DATA, @@ -68,24 +62,79 @@ public Object[][] createIssuerDataProvider() { TEST_NAME_CREATE_ISSUER_SUCCESS }, new Object[]{ - TEST_DIR_CREATE_ISSUER_WITH_IMAGE_SUCCESS + REQUEST_FORM_DATA, - TEST_DIR_CREATE_ISSUER_WITH_IMAGE_SUCCESS + RESPONSE_JSON, - TEST_NAME_CREATE_ISSUER_WITH_IMAGE_SUCCESS + TEST_DIR_CREATE_ISSUER_SUCCESS_WITH_IMAGE + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_SUCCESS_WITH_IMAGE + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE } }; } - @Test(dataProvider = "createIssuerDataProvider") + @DataProvider(name = "createIssuerDataProviderFailure") + public Object[][] createIssuerDataProviderFailure() { + return new Object[][] { + new Object[]{ + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_NAME + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_NAME + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME + }, + new Object[]{ + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION + }, + new Object[]{ + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_URL + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_URL + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL + }, + new Object[]{ + TEST_DIR_CREATE_ISSUER_FAILURE_WITH_INVALID_URL + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_FAILURE_WITH_INVALID_URL + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL + }, + new Object[]{ + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL + }, + new Object[]{ + TEST_DIR_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL + REQUEST_FORM_DATA, + TEST_DIR_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL + RESPONSE_JSON, + TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL + } + }; + } + + @Test(dataProvider = "createIssuerDataProviderSuccess") + @CitrusParameters({"requestFormData", "responseJson", "testName"}) + @CitrusTest + public void testCreateIssuerSuccess(String requestFormData, String responseJson, String testName) { + System.out.println("initGlobalValues = " + initGlobalValues); + performMultipartTest( + testName, + TEMPLATE_DIR, + restTestClient, + initGlobalValues, + getCreateIssuerUrl(), + requestFormData, + responseJson, + HttpStatus.OK); + } + + @Test(dataProvider = "createIssuerDataProviderFailure") @CitrusParameters({"requestFormData", "responseJson", "testName"}) @CitrusTest - public void testCreateIssuer(String requestFormData, String responseJson, String testName) { + public void testCreateIssuerFailure(String requestFormData, String responseJson, String testName) { System.out.println("initGlobalValues = " + initGlobalValues); - performTest( - testName, - restTestClient, - initGlobalValues, - getCreateIssuerUrl(), - requestFormData, - responseJson); + performMultipartTest( + testName, + TEMPLATE_DIR, + restTestClient, + initGlobalValues, + getCreateIssuerUrl(), + requestFormData, + responseJson, + HttpStatus.BAD_REQUEST); } + } diff --git a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/common/BaseCitrusTest.java b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/common/BaseCitrusTest.java index c6943eb2..0aea3160 100644 --- a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/common/BaseCitrusTest.java +++ b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/common/BaseCitrusTest.java @@ -1,9 +1,15 @@ package org.sunbird.integration.test.common; import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner; +import com.consol.citrus.http.client.HttpClient; +import java.text.MessageFormat; import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpStatus; +import org.sunbird.common.util.HttpUtil; +import org.sunbird.integration.test.user.EndpointConfig.TestGlobalProperty; /** * Class to contain the common things for all citrus tests. @@ -15,4 +21,29 @@ public class BaseCitrusTest extends TestNGCitrusTestDesigner { public static Map> toDeleteCassandraRecordsMap = new HashMap>(); public static Map> toDeleteEsRecordsMap = new HashMap>(); + public void performMultipartTest( + String testName, + String testTemplateDir, + HttpClient httpClient, + TestGlobalProperty config, + String url, + String requestFormData, + String responseJson, + HttpStatus responseCode) { + System.out.println(requestFormData); + + getTestCase().setName(testName); + + String testFolderPath = MessageFormat.format("{0}/{1}", testTemplateDir, testName); + + new HttpUtil().multipartPost(http().client(httpClient), config, url, requestFormData, testFolderPath); + + http() + .client(httpClient) + .receive() + .response(responseCode) + .payload(new ClassPathResource(responseJson)); + } + + } diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidEmail/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidEmail/request.params new file mode 100644 index 00000000..1745569a --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidEmail/request.params @@ -0,0 +1,4 @@ +name=swarn +description=something +url=http://www.example.com +email=abc \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidEmail/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidEmail/response.json new file mode 100644 index 00000000..0e733d3d --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidEmail/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.issuer.create", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "EMAIL_FORMAT_ERROR", + "status": "EMAIL_FORMAT_ERROR", + "errmsg": "Email is invalid." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidUrl/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidUrl/request.params new file mode 100644 index 00000000..4cd1fa72 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidUrl/request.params @@ -0,0 +1,4 @@ +name=swarn +description=something +url=abc +email=someuser@someorg.com \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidUrl/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidUrl/response.json new file mode 100644 index 00000000..6274214e --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithInvalidUrl/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.issuer.create", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "URL_FORMAT_ERROR", + "status": "URL_FORMAT_ERROR", + "errmsg": "URL is invalid." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutDescription/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutDescription/request.params new file mode 100644 index 00000000..4d1b8939 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutDescription/request.params @@ -0,0 +1,3 @@ +name=swarn +url=http://www.example.com +email=someuser@someorg.com \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutDescription/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutDescription/response.json new file mode 100644 index 00000000..c890e1da --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutDescription/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.issuer.create", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "MANDATORY_PARAMETER_MISSING", + "status": "MANDATORY_PARAMETER_MISSING", + "errmsg": "Mandatory parameter description is missing." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutEmail/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutEmail/request.params new file mode 100644 index 00000000..ac6668df --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutEmail/request.params @@ -0,0 +1,3 @@ +name=swarn +description=something +url=http://www.example.com \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutEmail/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutEmail/response.json new file mode 100644 index 00000000..63f2e04a --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutEmail/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.issuer.create", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "MANDATORY_PARAMETER_MISSING", + "status": "MANDATORY_PARAMETER_MISSING", + "errmsg": "Mandatory parameter email is missing." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutName/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutName/request.params new file mode 100644 index 00000000..9cde804d --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutName/request.params @@ -0,0 +1,3 @@ +description=something +url=http://www.example.com +email=someuser@someorg.com \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutName/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutName/response.json new file mode 100644 index 00000000..a6d3be1f --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutName/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.issuer.create", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "MANDATORY_PARAMETER_MISSING", + "status": "MANDATORY_PARAMETER_MISSING", + "errmsg": "Mandatory parameter name is missing." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutUrl/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutUrl/request.params new file mode 100644 index 00000000..f5fa451a --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutUrl/request.params @@ -0,0 +1,3 @@ +name=swarn +description=something +email=someuser@someorg.com \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutUrl/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutUrl/response.json new file mode 100644 index 00000000..53d1dd7c --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerFailureWithoutUrl/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.issuer.create", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "MANDATORY_PARAMETER_MISSING", + "status": "MANDATORY_PARAMETER_MISSING", + "errmsg": "Mandatory parameter url is missing." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerWithImageSuccess/image.png b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerSuccessWithImage/image.png similarity index 100% rename from sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerWithImageSuccess/image.png rename to sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerSuccessWithImage/image.png diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerWithImageSuccess/request.params b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerSuccessWithImage/request.params similarity index 100% rename from sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerWithImageSuccess/request.params rename to sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerSuccessWithImage/request.params diff --git a/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerWithImageSuccess/response.json b/sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerSuccessWithImage/response.json similarity index 100% rename from sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerWithImageSuccess/response.json rename to sunbird_service_api_test/src/test/resources/templates/badge/issuer/create/createIssuerSuccessWithImage/response.json