From 7b6199f5fd3d8922f972fcee8cc11f72dbe40eb0 Mon Sep 17 00:00:00 2001 From: kirti sagar jenamoni Date: Thu, 21 Feb 2019 12:57:22 +0530 Subject: [PATCH] functionalTests --- .../test/user/ReadUserTypeTest.java | 74 +++++++++++++++++++ .../response.json | 35 +++------ .../response.json | 14 ++++ .../response.json | 25 +++++++ 4 files changed, 125 insertions(+), 23 deletions(-) create mode 100644 sunbird_service_api_test/src/test/java/org/sunbird/integration/test/user/ReadUserTypeTest.java create mode 100644 sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeFailureWithoutAccessToken/response.json create mode 100644 sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeSuccessWithAccessToken/response.json diff --git a/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/user/ReadUserTypeTest.java b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/user/ReadUserTypeTest.java new file mode 100644 index 00000000..d36b820f --- /dev/null +++ b/sunbird_service_api_test/src/test/java/org/sunbird/integration/test/user/ReadUserTypeTest.java @@ -0,0 +1,74 @@ +package org.sunbird.integration.test.user; + +import com.consol.citrus.annotations.CitrusTest; +import com.consol.citrus.testng.CitrusParameters; +import org.springframework.http.HttpStatus; +import org.sunbird.integration.test.common.BaseCitrusTestRunner; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class ReadUserTypeTest extends BaseCitrusTestRunner { + + public static final String TEST_READ_USER_TYPE_FAILURE_WITHOUT_ACCESS_TOKEN = + "testReadUserTypeFailureWithoutAccessToken"; + + public static final String TEST_READ_USER_TYPE_SUCCESS_WITH_ACCESS_TOKEN = + "testReadUserTypeSuccessWithAccessToken"; + + public static final String TEMPLATE_DIR = "templates/user/type/read"; + + private String getReadUserTypeUrl() { + return getLmsApiUriPath("/api/user/v1/type/list", "/v1/user/type/list"); + } + + @DataProvider(name = "readUserTypeFailureDataProvider") + public Object[][] readUserTypeFailureDataProvider() { + + return new Object[][] { + new Object[] { + TEST_READ_USER_TYPE_FAILURE_WITHOUT_ACCESS_TOKEN, false, HttpStatus.UNAUTHORIZED + } + }; + } + + @DataProvider(name = "readUserTypeSuccessDataProvider") + public Object[][] readUserTypeSuccessDataProvider() { + return new Object[][] { + new Object[] {TEST_READ_USER_TYPE_SUCCESS_WITH_ACCESS_TOKEN, true, HttpStatus.OK}, + }; + } + + @Test(dataProvider = "readUserTypeFailureDataProvider") + @CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) + @CitrusTest + public void testReadUserTypeFailure( + String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { + getTestCase().setName(testName); + getAuthToken(this, isAuthRequired); + performGetTest( + this, + TEMPLATE_DIR, + testName, + getReadUserTypeUrl(), + isAuthRequired, + httpStatusCode, + RESPONSE_JSON); + } + + @Test(dataProvider = "readUserTypeSuccessDataProvider") + @CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) + @CitrusTest + public void testReadUserTypeSuccess( + String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { + getTestCase().setName(testName); + getAuthToken(this, isAuthRequired); + performGetTest( + this, + TEMPLATE_DIR, + testName, + getReadUserTypeUrl(), + isAuthRequired, + httpStatusCode, + RESPONSE_JSON); + } +} diff --git a/sunbird_service_api_test/src/test/resources/templates/user/role/read/testReadUserRoleSuccessWithAccessToken/response.json b/sunbird_service_api_test/src/test/resources/templates/user/role/read/testReadUserRoleSuccessWithAccessToken/response.json index fbb59601..8af7c4a6 100644 --- a/sunbird_service_api_test/src/test/resources/templates/user/role/read/testReadUserRoleSuccessWithAccessToken/response.json +++ b/sunbird_service_api_test/src/test/resources/templates/user/role/read/testReadUserRoleSuccessWithAccessToken/response.json @@ -1,15 +1,15 @@ { - "id": "api.role.read", - "ver": "v1", - "ts": "@ignore@", - "params": { - "resmsgid": null, - "msgid": "@ignore@", - "err": null, - "status": "success", - "errmsg": null - }, - "responseCode": "OK", + "id": "api.role.read", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": null, + "status": "success", + "errmsg": null + }, + "responseCode": "OK", "result": { "roles": [ { @@ -158,18 +158,7 @@ ], "name": "Flag Reviewer", "id": "FLAG_REVIEWER" - }, - { - "actionGroups": [ - { - "name": "Report Viewer", - "id": "REPORT_VIEWER", - "actions": [] - } - ], - "name": "Report Viewer", - "id": "REPORT_VIEWER" } ] } -} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeFailureWithoutAccessToken/response.json b/sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeFailureWithoutAccessToken/response.json new file mode 100644 index 00000000..dfd028ec --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeFailureWithoutAccessToken/response.json @@ -0,0 +1,14 @@ +{ + "id": "api.user.type.list", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": "UNAUTHORIZED_USER", + "status": "SERVER_ERROR", + "errmsg": "You are not authorized." + }, + "responseCode": "CLIENT_ERROR", + "result": {} +} \ No newline at end of file diff --git a/sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeSuccessWithAccessToken/response.json b/sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeSuccessWithAccessToken/response.json new file mode 100644 index 00000000..8713821b --- /dev/null +++ b/sunbird_service_api_test/src/test/resources/templates/user/type/read/testReadUserTypeSuccessWithAccessToken/response.json @@ -0,0 +1,25 @@ +{ + "id": "api.user.type.list", + "ver": "v1", + "ts": "@ignore@", + "params": { + "resmsgid": null, + "msgid": "@ignore@", + "err": null, + "status": "success", + "errmsg": null + }, + "responseCode": "OK", + "result": { + "response": [ + { + "name": "TEACHER", + "id": "TEACHER" + }, + { + "name": "OTHER", + "id": "OTHER" + } + ] + } +} \ No newline at end of file