diff --git a/sunbird_service_api_test/src/test/java/org/sunbird/common/action/IssuerUtil.java b/sunbird_service_api_test/src/test/java/org/sunbird/common/action/IssuerUtil.java index 177c468a..e79081e1 100644 --- a/sunbird_service_api_test/src/test/java/org/sunbird/common/action/IssuerUtil.java +++ b/sunbird_service_api_test/src/test/java/org/sunbird/common/action/IssuerUtil.java @@ -12,6 +12,10 @@ public static String getCreateIssuerUrl(BaseCitrusTestRunner runner) { return runner.getLmsApiUriPath("/api/badging/v1/issuer/create", "/v1/issuer/create"); } + public static String getDeleteIssuerUrl(BaseCitrusTestRunner runner, String pathParam) { + return runner.getLmsApiUriPath("/api/badging/v1/issuer/delete", "/v1/issuer/delete", pathParam); + } + public static void createIssuer( BaseCitrusTestRunner runner, TestContext testContext, @@ -42,4 +46,22 @@ public static void createIssuer( "$.result.issuerId", Constant.EXTRACT_VAR_ISSUER_ID)); } + + public static void deleteIssuer( + BaseCitrusTestRunner runner, + TestContext testContext, + TestGlobalProperty config, + String issuerId) { + runner.http( + builder -> + TestActionUtil.getDeleteRequestTestAction( + builder, + Constant.LMS_ENDPOINT, + null, + null, + getDeleteIssuerUrl(runner, issuerId), + null, + null, + null)); + } } diff --git a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateBadgeClassTest.java b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateBadgeClassTest.java index d6495e2a..83eefc5f 100644 --- a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateBadgeClassTest.java +++ b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/badge/CreateBadgeClassTest.java @@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus; import org.sunbird.common.action.IssuerUtil; import org.sunbird.common.action.OrgUtil; +import org.sunbird.common.util.Constant; import org.sunbird.integration.test.common.BaseCitrusTestRunner; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -86,7 +87,7 @@ public void testCreateBadgeClassSuccess(String testName) { false, HttpStatus.OK, RESPONSE_JSON); - afterTest(); + afterTest(true); } @Test(dataProvider = "createBadgeClassDataProviderFailure") @@ -114,14 +115,21 @@ private void beforeTest(Boolean canCreateOrg, Boolean canCreateIssuer) { } if (canCreateIssuer) { IssuerUtil.createIssuer( - this, - testContext, - config, - BT_CREATE_ISSUER_TEMPLATE_DIR, - BT_TEST_NAME_CREATE_ISSUER_SUCCESS, - HttpStatus.OK); + this, + testContext, + config, + BT_CREATE_ISSUER_TEMPLATE_DIR, + BT_TEST_NAME_CREATE_ISSUER_SUCCESS, + HttpStatus.OK); } } - private void afterTest() {} + private void afterTest(boolean isIssuerCreated) { + if (isIssuerCreated) + IssuerUtil.deleteIssuer( + this, + testContext, + config, + (String) testContext.getVariables().get(Constant.EXTRACT_VAR_ISSUER_ID)); + } } 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 53b940ec..9c03a1ed 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 @@ -1,7 +1,6 @@ package org.sunbird.integration.test.badge; import com.consol.citrus.annotations.CitrusTest; -import com.consol.citrus.http.client.HttpClient; import com.consol.citrus.testng.CitrusParameters; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -29,15 +28,9 @@ public class CreateIssuerTest extends BaseCitrusTestRunner { "testCreateIssuerFailureWithInvalidEmail"; public static final String TEMPLATE_DIR = "templates/badge/issuer/create"; - - public static final String RESPONSE_JSON = "response.json"; - - @Autowired private HttpClient restTestClient; - @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"; @@ -46,64 +39,53 @@ private String getCreateIssuerUrl() { @DataProvider(name = "createIssuerDataProviderSuccess") public Object[][] createIssuerDataProviderSuccess() { return new Object[][] { - new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_SUCCESS}, - new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE} + new Object[] {TEST_NAME_CREATE_ISSUER_SUCCESS}, + new Object[] {TEST_NAME_CREATE_ISSUER_SUCCESS_WITH_IMAGE} }; } @DataProvider(name = "createIssuerDataProviderFailure") public Object[][] createIssuerDataProviderFailure() { return new Object[][] { - new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME}, - new Object[] { - REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION - }, - new Object[] {REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL}, - new Object[] { - REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL - }, - new Object[] { - REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL - }, - new Object[] { - REQUEST_FORM_DATA, RESPONSE_JSON, TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL - } + new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_NAME}, + new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_DESCRIPTION}, + new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_URL}, + new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_URL}, + new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITHOUT_EMAIL}, + new Object[] {TEST_NAME_CREATE_ISSUER_FAILURE_WITH_INVALID_EMAIL} }; } @Test(dataProvider = "createIssuerDataProviderSuccess") - @CitrusParameters({"requestFormData", "responseJson", "testName"}) + @CitrusParameters({"testName"}) @CitrusTest - public void testCreateIssuerSuccess( - String requestFormData, String responseJson, String testName) { + public void testCreateIssuerSuccess(String testName) { System.out.println("initGlobalValues = " + initGlobalValues); performMultipartTest( this, TEMPLATE_DIR, testName, getCreateIssuerUrl(), - requestFormData, + REQUEST_FORM_DATA, null, false, HttpStatus.OK, - responseJson); + RESPONSE_JSON); } @Test(dataProvider = "createIssuerDataProviderFailure") - @CitrusParameters({"requestFormData", "responseJson", "testName"}) + @CitrusParameters({"testName"}) @CitrusTest - public void testCreateIssuerFailure( - String requestFormData, String responseJson, String testName) { - System.out.println("initGlobalValues = " + initGlobalValues); + public void testCreateIssuerFailure(String testName) { performMultipartTest( this, TEMPLATE_DIR, testName, getCreateIssuerUrl(), - requestFormData, + REQUEST_FORM_DATA, null, false, HttpStatus.BAD_REQUEST, - responseJson); + RESPONSE_JSON); } } diff --git a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/geolocation/CreateGeolocationTest.java b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/geolocation/CreateGeolocationTest.java new file mode 100644 index 00000000..76d45e36 --- /dev/null +++ b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/geolocation/CreateGeolocationTest.java @@ -0,0 +1,96 @@ +package org.sunbird.integration.test.geolocation; + +import com.consol.citrus.annotations.CitrusTest; +import com.consol.citrus.testng.CitrusParameters; +import javax.ws.rs.core.MediaType; +import org.springframework.http.HttpStatus; +import org.sunbird.common.action.OrgUtil; +import org.sunbird.integration.test.common.BaseCitrusTestRunner; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class CreateGeolocationTest extends BaseCitrusTestRunner { + + private static final String TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITHOUT_ROOT_ORG_ID = + "testCreateGeolocationFailureWithoutRootOrgId"; + private static final String TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_EMPTY_ROOT_ORG_ID = + "testCreateGeolocationFailureWithEmptyRootOrgId"; + private static final String TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_INVALID_ROOT_ORG_ID = + "testCreateGeolocationFailureWithInvalidRootOrgId"; + + private static final String TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_ROOT_ORG_ID = + "testCreateGeolocationSuccessWithRootOrgId"; + private static final String TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_SUB_ORG_ID = + "testCreateGeolocationSuccessWithSubOrgId"; + + private static final String TEMPLATE_DIR = "templates/geolocation/create"; + + private String getCreateGeolocationUrl() { + return getLmsApiUriPath("/api/org/v1/location/create", "/v1/notification/location/create"); + } + + @DataProvider(name = "createGeolocationDataProviderFailure") + public Object[][] createGeolocationDataProviderFailure() { + return new Object[][] { + new Object[] {TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITHOUT_ROOT_ORG_ID}, + new Object[] {TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_EMPTY_ROOT_ORG_ID}, + new Object[] {TEST_NAME_CREATE_GEOLOCATION_FAILURE_WITH_INVALID_ROOT_ORG_ID} + }; + } + + @DataProvider(name = "createGeolocationDataProviderSuccess") + public Object[][] createGeolocationDataProviderSuccess() { + return new Object[][] { + new Object[] {TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_ROOT_ORG_ID, true}, + new Object[] {TEST_NAME_CREATE_GEOLOCATION_SUCCESS_WITH_SUB_ORG_ID, false} + }; + } + + @Test(dataProvider = "createGeolocationDataProviderSuccess") + @CitrusParameters({"testName", "canCreateRootOrg"}) + @CitrusTest + public void testCreateGeolocationSuccess(String testName, boolean canCreateRootOrg) { + beforeTest(testName, canCreateRootOrg); + performPostTest( + this, + TEMPLATE_DIR, + testName, + getCreateGeolocationUrl(), + REQUEST_JSON, + MediaType.APPLICATION_JSON, + true, + HttpStatus.OK, + RESPONSE_JSON); + } + + @Test(dataProvider = "createGeolocationDataProviderFailure") + @CitrusParameters({"testName"}) + @CitrusTest + public void testCreateGeolocationFailure(String testName) { + getTestCase().setName(testName); + getAuthToken(this, true); + performPostTest( + this, + TEMPLATE_DIR, + testName, + getCreateGeolocationUrl(), + REQUEST_JSON, + MediaType.APPLICATION_JSON, + true, + HttpStatus.BAD_REQUEST, + RESPONSE_JSON); + } + + private void beforeTest(String testName, boolean canCreateRootOrg) { + getTestCase().setName(testName); + getAuthToken(this, true); + if (canCreateRootOrg) { + variable("rootOrgChannel", OrgUtil.getRootOrgChannel()); + OrgUtil.getRootOrgId(this, testContext); + } else { + variable("externalId", OrgUtil.getRootOrgChannel()); + variable("provider", OrgUtil.getRootOrgChannel()); + OrgUtil.createSubOrgId(this, testContext); + } + } +} diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithEmptyRootOrgId/request.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithEmptyRootOrgId/request.json new file mode 100644 index 00000000..cb6761fc --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithEmptyRootOrgId/request.json @@ -0,0 +1,11 @@ +{ + "request": { + "rootOrgId": "", + "data": [ + { + "location": "someLocation", + "type": "someType" + } + ] + } +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithEmptyRootOrgId/response.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithEmptyRootOrgId/response.json new file mode 100644 index 00000000..0659be1a --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithEmptyRootOrgId/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.notification.location.create", + "ver": "@ignore@", + "ts": "@ignore@", + "params": { + "resmsgid": "@ignore@", + "msgid": "@ignore@", + "err": "INVALID_ORG_ID", + "status": "INVALID_ORG_ID", + "errmsg": "INVALID_ORG_ID" + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithInvalidRootOrgId/request.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithInvalidRootOrgId/request.json new file mode 100644 index 00000000..93c02a41 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithInvalidRootOrgId/request.json @@ -0,0 +1,11 @@ +{ + "request": { + "rootOrgId": "invalidOrgId", + "data": [ + { + "location": "someLocation", + "type": "someType" + } + ] + } +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithInvalidRootOrgId/response.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithInvalidRootOrgId/response.json new file mode 100644 index 00000000..0659be1a --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithInvalidRootOrgId/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.notification.location.create", + "ver": "@ignore@", + "ts": "@ignore@", + "params": { + "resmsgid": "@ignore@", + "msgid": "@ignore@", + "err": "INVALID_ORG_ID", + "status": "INVALID_ORG_ID", + "errmsg": "INVALID_ORG_ID" + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithoutRootOrgId/request.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithoutRootOrgId/request.json new file mode 100644 index 00000000..ec4801d8 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithoutRootOrgId/request.json @@ -0,0 +1,10 @@ +{ + "request": { + "data": [ + { + "location": "someLocation", + "type": "someType" + } + ] + } +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithoutRootOrgId/response.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithoutRootOrgId/response.json new file mode 100644 index 00000000..0659be1a --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationFailureWithoutRootOrgId/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.notification.location.create", + "ver": "@ignore@", + "ts": "@ignore@", + "params": { + "resmsgid": "@ignore@", + "msgid": "@ignore@", + "err": "INVALID_ORG_ID", + "status": "INVALID_ORG_ID", + "errmsg": "INVALID_ORG_ID" + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithRootOrgId/request.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithRootOrgId/request.json new file mode 100644 index 00000000..bb23fdb3 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithRootOrgId/request.json @@ -0,0 +1,11 @@ +{ + "request": { + "rootOrgId": "${organisationId}", + "data": [ + { + "location": "someLocation", + "type": "someType" + } + ] + } +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithRootOrgId/response.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithRootOrgId/response.json new file mode 100644 index 00000000..87cd1b23 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithRootOrgId/response.json @@ -0,0 +1,22 @@ +{ + "id": "api.notification.location.create", + "ver": "@ignore@", + "ts": "@ignore@", + "params": { + "resmsgid": "@ignore@", + "msgid": "@ignore@", + "err": "@ignore@", + "status": "success", + "errmsg": "@ignore@" + }, + "responseCode": "OK", + "result": { + "response": [ + { + "location": "@ignore@", + "id": "@ignore@", + "status": "SUCCESS" + } + ] + } +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithSubOrgId/request.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithSubOrgId/request.json new file mode 100644 index 00000000..8b2e6155 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithSubOrgId/request.json @@ -0,0 +1,11 @@ +{ + "request": { + "rootOrgId": "${subOrganisationId}", + "data": [ + { + "location": "someLocation", + "type": "someType" + } + ] + } +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithSubOrgId/response.json b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithSubOrgId/response.json new file mode 100644 index 00000000..87cd1b23 --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/geolocation/create/testCreateGeolocationSuccessWithSubOrgId/response.json @@ -0,0 +1,22 @@ +{ + "id": "api.notification.location.create", + "ver": "@ignore@", + "ts": "@ignore@", + "params": { + "resmsgid": "@ignore@", + "msgid": "@ignore@", + "err": "@ignore@", + "status": "success", + "errmsg": "@ignore@" + }, + "responseCode": "OK", + "result": { + "response": [ + { + "location": "@ignore@", + "id": "@ignore@", + "status": "SUCCESS" + } + ] + } +} \ No newline at end of file