Skip to content

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

Open
wants to merge 4 commits into
base: release-2.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Contributor

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.

"testAddUserToOrgFailureWithEmptyRoleArray";
"testAddUserToOrgSuccessWithEmptyRoleArray";

public static final String TEST_NAME_ADD_USER_TO_ORG_FAILURE_WITH_INVALID_USER_ID =
"testAddUserToOrgFailureWithInvalidUserId";
Expand All @@ -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"})
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand All @@ -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
Expand Up @@ -24,7 +24,7 @@ private String getSearchOrgUrl() {
public Object[][] searchOrgFailureDataProvider() {

return new Object[][] {
new Object[] {TEST_NAME_SEARCH_ORG_FAILURE_WITHOUT_FILTER, HttpStatus.INTERNAL_SERVER_ERROR},
new Object[] {TEST_NAME_SEARCH_ORG_FAILURE_WITHOUT_FILTER, HttpStatus.BAD_REQUEST},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does invalid user ID result in internal server error?

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Object[][] searchUserFailureDataProvider() {
new Object[] {
TEST_NAME_SEARCH_USER_FAILURE_WITHOUT_ACCESS_TOKEN, false, HttpStatus.UNAUTHORIZED
},
new Object[] {TEST_SEARCH_EMPTY_BODY_FAILURE, true, HttpStatus.INTERNAL_SERVER_ERROR},
new Object[] {TEST_SEARCH_EMPTY_BODY_FAILURE, true, HttpStatus.BAD_REQUEST},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[][]{
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand All @@ -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,
Expand All @@ -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
Expand Up @@ -80,7 +80,8 @@ public void testDeleteUserNoteSuccess(
@CitrusTest
public void testDeleteUserNoteFailureWithInvalidNoteId() {
getTestCase().setName(TEST_DELETE_USER_NOTE_FAILURE_WITH_INVALID_NOTEID);
beforeTest();
//beforeTest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why beforeTest(); is commented.

getAuthToken(this, true);
performDeleteTest(
this,
TEMPLATE_DIR,
Expand Down
Loading