-
Notifications
You must be signed in to change notification settings - Fork 19
functional test cases #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release-2.0.0
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,18 @@ | |
|
||
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.UserUtil; | ||
import org.sunbird.integration.test.common.BaseCitrusTestRunner; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
public class AddUserToOrgTest extends BaseCitrusTestRunner { | ||
|
||
public static final String TEST_ADD_USER_TO_ORG_FAILURE_WITH_EMPTY_ROLE_ARRAY = | ||
"testAddUserToOrgFailureWithEmptyRoleArray"; | ||
"testAddUserToOrgSuccessWithEmptyRoleArray"; | ||
|
||
public static final String TEST_NAME_ADD_USER_TO_ORG_FAILURE_WITH_INVALID_USER_ID = | ||
"testAddUserToOrgFailureWithInvalidUserId"; | ||
|
@@ -24,21 +26,22 @@ private String getAddUserToOrgUrl() { | |
return getLmsApiUriPath("/api/org/v1/member/add", "v1/org/member/add"); | ||
} | ||
|
||
@DataProvider(name = "addUserToOrgFailureDataProvider") | ||
@DataProvider(name = "addUserToOrgDataProvider") | ||
public Object[][] addUserToOrgFailureDataProvider() { | ||
|
||
return new Object[][] { | ||
new Object[] {TEST_ADD_USER_TO_ORG_FAILURE_WITH_EMPTY_ROLE_ARRAY}, | ||
new Object[] {TEST_NAME_ADD_USER_TO_ORG_FAILURE_WITH_INVALID_USER_ID}, | ||
new Object[] {TEST_NAME_ADD_USER_TO_ORG_FAILURE_WITH_INVALID_ORG_ID}, | ||
new Object[] {TEST_ADD_USER_TO_ORG_FAILURE_WITH_EMPTY_ROLE_ARRAY, true, HttpStatus.OK}, | ||
new Object[] {TEST_NAME_ADD_USER_TO_ORG_FAILURE_WITH_INVALID_USER_ID, false, HttpStatus.BAD_REQUEST}, | ||
new Object[] {TEST_NAME_ADD_USER_TO_ORG_FAILURE_WITH_INVALID_ORG_ID, false, HttpStatus.BAD_REQUEST} | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "addUserToOrgFailureDataProvider") | ||
@CitrusParameters({"testName"}) | ||
@Test(dataProvider = "addUserToOrgDataProvider") | ||
@CitrusParameters({"testName", "getUserId", "httpStatus"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getUserId is used for which purpose |
||
@CitrusTest | ||
public void testAddUserToOrgFailure(String testName) { | ||
public void testAddUserToOrgFailure(String testName, boolean getUserId, HttpStatus httpStatus) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test name and data provider name mismatch. |
||
getAuthToken(this, true); | ||
beforeTest(getUserId); | ||
performPostTest( | ||
this, | ||
TEMPLATE_DIR, | ||
|
@@ -47,7 +50,18 @@ public void testAddUserToOrgFailure(String testName) { | |
REQUEST_JSON, | ||
MediaType.APPLICATION_JSON, | ||
true, | ||
HttpStatus.BAD_REQUEST, | ||
httpStatus, | ||
RESPONSE_JSON); | ||
} | ||
|
||
void beforeTest(boolean getUserId) { | ||
|
||
if (getUserId) { | ||
UserUtil.getUserId(this, testContext); | ||
variable("userId", testContext.getVariable("userId")); | ||
} else { | ||
variable("userId", "citrus:concat('user_',citrus:randomNumber(10))"); | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ public Object[][] blockUserFailureDataProvider() { | |
|
||
return new Object[][] { | ||
new Object[] {TEST_BLOCK_USER_FAILURE_WITHOUT_ACCESS_TOKEN, false, HttpStatus.UNAUTHORIZED}, | ||
new Object[] {TEST_BLOCK_USER_FAILURE_WITH_INVALID_USERID, true, HttpStatus.NOT_FOUND}, | ||
new Object[] {TEST_BLOCK_USER_FAILURE_WITH_INVALID_USERID, true, HttpStatus.INTERNAL_SERVER_ERROR}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does invalid user ID result in internal server error? |
||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,88 +2,94 @@ | |
|
||
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.UserUtil; | ||
import org.sunbird.integration.test.common.BaseCitrusTestRunner; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
|
||
public class UpdateUserLoginTimeTest extends BaseCitrusTestRunner { | ||
|
||
public static final String TEST_UPDATE_USER_LOGIN_TIME_FAILURE_WITHOUT_ACCESS_TOKEN = | ||
"testUpdateUserLoginTimeFailureWithoutAccessToken"; | ||
public static final String TEST_UPDATE_USER_LOGIN_TIME_FAILURE_WITHOUT_ACCESS_TOKEN = | ||
"testUpdateUserLoginTimeFailureWithoutAccessToken"; | ||
|
||
public static final String TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_INVALID_USER_ID = | ||
"testUpdateUserLoginTimeSuccessWithInvalidUserId"; | ||
public static final String TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_VALID_USER_ID = | ||
"testUpdateUserLoginTimeSuccessWithValidUserId"; | ||
public static final String TEMPLATE_DIR = "templates/user/loginTime/update"; | ||
|
||
public static final String TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_INVALID_USER_ID = | ||
"testUpdateUserLoginTimeSuccessWithInvalidUserId"; | ||
public static final String TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_VALID_USER_ID = | ||
"testUpdateUserLoginTimeSuccessWithValidUserId"; | ||
public static final String TEMPLATE_DIR = "templates/user/loginTime/update"; | ||
private String getUpdaterUserLoginTimeUrl() { | ||
return getLmsApiUriPath("/api/user/v1/update/logintime", "/v1/user/update/logintime"); | ||
} | ||
|
||
private String getUpdaterUserLoginTimeUrl() { | ||
return getLmsApiUriPath("/api/user/v1/update/logintime", "/v1/user/update/logintime"); | ||
} | ||
@DataProvider(name = "updateUserLoginTimeFailureDataProvider") | ||
public Object[][] updateUserLoginTimeFailureDataProvider() { | ||
|
||
@DataProvider(name = "updateUserLoginTimeFailureDataProvider") | ||
public Object[][] updateUserLoginTimeFailureDataProvider() { | ||
return new Object[][]{ | ||
new Object[]{ | ||
TEST_UPDATE_USER_LOGIN_TIME_FAILURE_WITHOUT_ACCESS_TOKEN, false, HttpStatus.UNAUTHORIZED | ||
} | ||
}; | ||
} | ||
|
||
return new Object[][] { | ||
new Object[] { | ||
TEST_UPDATE_USER_LOGIN_TIME_FAILURE_WITHOUT_ACCESS_TOKEN, false, HttpStatus.UNAUTHORIZED | ||
} | ||
}; | ||
} | ||
@Test(dataProvider = "updateUserLoginTimeFailureDataProvider") | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) | ||
@CitrusTest | ||
public void testUserUpdateLoginTimeFailure( | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { | ||
getTestCase().setName(testName); | ||
getAuthToken(this, isAuthRequired); | ||
performPatchTest( | ||
this, | ||
TEMPLATE_DIR, | ||
testName, | ||
getUpdaterUserLoginTimeUrl(), | ||
REQUEST_JSON, | ||
MediaType.APPLICATION_JSON, | ||
isAuthRequired, | ||
httpStatusCode, | ||
RESPONSE_JSON); | ||
} | ||
|
||
@DataProvider(name = "updateUserLoginTimeSuccessDataProvider") | ||
public Object[][] updateUserLoginTimeSuccessDataProvider() { | ||
@DataProvider(name = "updateUserLoginTimeSuccessDataProvider") | ||
public Object[][] updateUserLoginTimeSuccessDataProvider() { | ||
|
||
return new Object[][] { | ||
new Object[] {TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_VALID_USER_ID, true, HttpStatus.OK}, | ||
new Object[] {TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_INVALID_USER_ID, true, HttpStatus.OK}, | ||
}; | ||
} | ||
return new Object[][]{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Format code properly. |
||
new Object[]{TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_VALID_USER_ID, true, HttpStatus.OK, true}, | ||
new Object[]{TEST_UPDATE_USER_LOGIN_TIME_SUCCESS_WITH_INVALID_USER_ID, true, HttpStatus.OK, false}, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "updateUserLoginTimeFailureDataProvider") | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) | ||
@CitrusTest | ||
public void testUserUpdateLoginTimeFailure( | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { | ||
getTestCase().setName(testName); | ||
getAuthToken(this, isAuthRequired); | ||
performPatchTest( | ||
this, | ||
TEMPLATE_DIR, | ||
testName, | ||
getUpdaterUserLoginTimeUrl(), | ||
REQUEST_JSON, | ||
MediaType.APPLICATION_JSON, | ||
isAuthRequired, | ||
httpStatusCode, | ||
RESPONSE_JSON); | ||
} | ||
@Test(dataProvider = "updateUserLoginTimeSuccessDataProvider") | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode", "isUserIdReq"}) | ||
@CitrusTest | ||
public void testUpdateUserLoginTimeSuccess( | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode, boolean isUserIdReq) { | ||
getTestCase().setName(testName); | ||
getAuthToken(this, isAuthRequired); | ||
beforeTest(isUserIdReq); | ||
performPatchTest( | ||
this, | ||
TEMPLATE_DIR, | ||
testName, | ||
getUpdaterUserLoginTimeUrl(), | ||
REQUEST_JSON, | ||
MediaType.APPLICATION_JSON, | ||
isAuthRequired, | ||
httpStatusCode, | ||
RESPONSE_JSON); | ||
} | ||
|
||
@Test(dataProvider = "updateUserLoginTimeSuccessDataProvider") | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) | ||
@CitrusTest | ||
public void testUpdateUserLoginTimeSuccess( | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { | ||
getTestCase().setName(testName); | ||
getAuthToken(this, isAuthRequired); | ||
beforeTest(); | ||
performPatchTest( | ||
this, | ||
TEMPLATE_DIR, | ||
testName, | ||
getUpdaterUserLoginTimeUrl(), | ||
REQUEST_JSON, | ||
MediaType.APPLICATION_JSON, | ||
isAuthRequired, | ||
httpStatusCode, | ||
RESPONSE_JSON); | ||
} | ||
private void beforeTest(boolean isUserIdReq) { | ||
|
||
private void beforeTest() { | ||
UserUtil.getUserId(this, testContext); | ||
variable("userId", testContext.getVariable("userId")); | ||
} | ||
if (isUserIdReq) { | ||
UserUtil.getUserId(this, testContext); | ||
variable("userId", testContext.getVariable("userId")); | ||
} else { | ||
variable("userId", "INVALID"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,46 +43,33 @@ public Object[][] updateUserProfileVisibilityFailureDataProvider() { | |
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_FAILURE_WITHOUT_ACCESS_TOKEN, | ||
false, | ||
HttpStatus.UNAUTHORIZED | ||
HttpStatus.UNAUTHORIZED, false | ||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_FAILURE_WITH_INVALID_USERID, true, HttpStatus.NOT_FOUND | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_FAILURE_WITH_INVALID_USERID, true, HttpStatus.BAD_REQUEST, false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does invalid user ID result in bad request? Not found is more relevant. |
||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_FAILURE_WITH_INVALID_COLUMN, | ||
true, | ||
HttpStatus.BAD_REQUEST | ||
HttpStatus.BAD_REQUEST, true | ||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_FAILURE_WITH_SAME_COLUMN_IN_PRIVATE_AND_PUBLIC_ARRAY, | ||
true, | ||
HttpStatus.BAD_REQUEST | ||
HttpStatus.BAD_REQUEST, true | ||
}, | ||
}; | ||
} | ||
|
||
@DataProvider(name = "updateUserProfileVisibilitySuccessDataProvider") | ||
public Object[][] updateUserProfileVisibilitySuccessDataProvider() { | ||
return new Object[][] { | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_SUCCESS_WITH_VALID_USERID, true, HttpStatus.OK | ||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_SUCCESS_WITH_ALREADY_PUBLIC_COLUMN, true, HttpStatus.OK | ||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_SUCCESS_WITH_ALREADY_PRIVATE_COLUMN, true, HttpStatus.OK | ||
}, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "updateUserProfileVisibilityFailureDataProvider") | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode", "isUserIdReq"}) | ||
@CitrusTest | ||
public void testUpdateUserProfileVisibilityFailure( | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode, boolean isUserIdReq) { | ||
getTestCase().setName(testName); | ||
beforeTest(isAuthRequired); | ||
getAuthToken(this, isAuthRequired); | ||
beforeTest(isUserIdReq); | ||
performPostTest( | ||
this, | ||
TEMPLATE_DIR, | ||
|
@@ -95,13 +82,31 @@ public void testUpdateUserProfileVisibilityFailure( | |
RESPONSE_JSON); | ||
} | ||
|
||
|
||
@DataProvider(name = "updateUserProfileVisibilitySuccessDataProvider") | ||
public Object[][] updateUserProfileVisibilitySuccessDataProvider() { | ||
return new Object[][] { | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_SUCCESS_WITH_VALID_USERID, true, HttpStatus.OK | ||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_SUCCESS_WITH_ALREADY_PUBLIC_COLUMN, true, HttpStatus.OK | ||
}, | ||
new Object[] { | ||
TEST_UPDATE_USER_PROFILE_VISIBILITY_SUCCESS_WITH_ALREADY_PRIVATE_COLUMN, true, HttpStatus.OK | ||
}, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "updateUserProfileVisibilitySuccessDataProvider") | ||
@CitrusParameters({"testName", "isAuthRequired", "httpStatusCode"}) | ||
@CitrusTest | ||
public void testUpdateUserProfileVisibilitySuccess( | ||
String testName, boolean isAuthRequired, HttpStatus httpStatusCode) { | ||
getTestCase().setName(testName); | ||
beforeTest(isAuthRequired); | ||
getAuthToken(this, true); | ||
beforeTest(true); | ||
variable("userId", testContext.getVariable("userId")); | ||
performPostTest( | ||
this, | ||
TEMPLATE_DIR, | ||
|
@@ -114,9 +119,17 @@ public void testUpdateUserProfileVisibilitySuccess( | |
RESPONSE_JSON); | ||
} | ||
|
||
private void beforeTest(boolean isAuthRequired) { | ||
getAuthToken(this, isAuthRequired); | ||
private void beforeTest(boolean isUserIdReq) { | ||
|
||
if(isUserIdReq) | ||
{ | ||
UserUtil.getUserId(this, testContext); | ||
variable("userId", TestActionUtil.getVariable(testContext, "userId")); | ||
variable("userId", testContext.getVariable("userId")); | ||
UserUtil.createUserAndGetToken(this, testContext); | ||
} | ||
else { | ||
variable("userId", "Invalid"); | ||
} | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,8 @@ public void testDeleteUserNoteSuccess( | |
@CitrusTest | ||
public void testDeleteUserNoteFailureWithInvalidNoteId() { | ||
getTestCase().setName(TEST_DELETE_USER_NOTE_FAILURE_WITH_INVALID_NOTEID); | ||
beforeTest(); | ||
//beforeTest(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why beforeTest(); is commented. |
||
getAuthToken(this, true); | ||
performDeleteTest( | ||
this, | ||
TEMPLATE_DIR, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constant name and value don't correspond.