diff options
Diffstat (limited to 'test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user')
3 files changed, 2768 insertions, 0 deletions
diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/ActivateDeActivateDeleteUser.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/ActivateDeActivateDeleteUser.java new file mode 100644 index 0000000000..24afcec40f --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/ActivateDeActivateDeleteUser.java @@ -0,0 +1,756 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.user; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.http.HttpStatus; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.dao.utils.UserStatusEnum; +import org.openecomp.sdc.be.model.LifecycleStateEnum; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ResourceRespJavaObject; +import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo; +import org.openecomp.sdc.ci.tests.datatypes.enums.NormativeTypesEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.ResourceCategoryEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedUserCRUDAudit; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.users.UserResponseMessageEnum; +import org.openecomp.sdc.ci.tests.utils.DbUtils; +import org.openecomp.sdc.ci.tests.utils.general.Convertor; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.CatalogRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ImportRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResourceRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.rest.UserRestUtils; +import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ResourceValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.UserValidationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.AssertJUnit; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; + +/** + * @author alitvinsky + * + */ +public class ActivateDeActivateDeleteUser extends ComponentBaseTest { + private static Logger logger = LoggerFactory.getLogger(ActivateDeActivateDeleteUser.class.getName()); + protected Gson gson = new Gson(); + protected User sdncAdminUser; + + @BeforeMethod + public void init() { + sdncAdminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + + } + + @Rule + public static TestName name = new TestName(); + + public ActivateDeActivateDeleteUser() { + super(name, ActivateDeActivateDeleteUser.class.getName()); + } + + @Test + public void authorizeDeActivatedUser() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + // deActivate created user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + sdncUserDetails.setStatus(UserStatusEnum.INACTIVE); + validateSuccessDeActivateUserResponse(sdncUserDetails, deActivateUserResponse); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + + AssertJUnit.assertEquals("Check response code after deActive user", errorInfo.getCode(), + getUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables, + getUserResponse.getResponse()); + + // clean audit before authorization test + DbUtils.cleanAllAudits(); + + // Perform login from WebSeal + User sealUserDetails = sdncUserDetails; + RestResponse authorizedUserResponse = UserRestUtils.authorizedUserTowardsCatalogBeQA(sealUserDetails); + + // validate response + + ErrorInfo errorInfo2 = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_ACCESS.name()); + + AssertJUnit.assertNotNull("check response object is not null after user login", authorizedUserResponse); + AssertJUnit.assertNotNull("check error code exists in response after user login", + authorizedUserResponse.getErrorCode()); + AssertJUnit.assertEquals("Check response code after deActive user", errorInfo2.getCode(), + authorizedUserResponse.getErrorCode()); + + List<String> variables2 = Arrays.asList(); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.RESTRICTED_ACCESS.name(), variables2, + authorizedUserResponse.getResponse()); + + // validate against ES DB + + UserValidationUtils.validateDataAgainstAuditDB_access(sealUserDetails, + DbUtils.parseAuditRespByAction("Access"), authorizedUserResponse, errorInfo2, variables2); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + public User getDefaultUserDetails() { + + String httpCspUserId = "km2000"; + String userFirstName = "Kot"; + String userLastName = "May"; + String email = "km2000@intl.sdc.com"; + String role = UserRoleEnum.ADMIN.name(); + User sdncUserDetails = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + + return sdncUserDetails; + } + + public void validateSuccessCreateUserResponse(User sdncUserDetails, RestResponse createUserResponse) + throws Exception { + + AssertJUnit.assertNotNull("check response object is not null after create user", createUserResponse); + AssertJUnit.assertNotNull("check error code exists in response after create user", + createUserResponse.getErrorCode()); + AssertJUnit.assertEquals("Check response code after create user", HttpStatus.SC_CREATED, + createUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, createUserResponse.getResponse()); + // UserRestUtils.validateAddUserAuditMessage(sdncUserDetails, + // sdncAdminUser, String.valueOf(HttpStatus.SC_CREATED), + // UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + // UserRestUtils.getAddUserAuditMessage("AddUser")); + String addUser = "AddUser"; + ExpectedUserCRUDAudit constructFieldsForAuditValidation = Convertor.constructFieldsForAuditValidation(addUser, + sdncAdminUser, ActionStatus.CREATED, sdncUserDetails, null); + AuditValidationUtils.validateAddUserAudit(constructFieldsForAuditValidation, addUser); + + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, getUserResponse.getResponse()); + + } + + public void validateSuccessDeActivateUserResponse(User sdncUserDetails, RestResponse deActivateUserResponse) + throws Exception { + + AssertJUnit.assertNotNull("check response object is not null after deActive user", deActivateUserResponse); + AssertJUnit.assertNotNull("check error code exists in response after deActive user", + deActivateUserResponse.getErrorCode()); + AssertJUnit.assertEquals("Check response code after deActive user", 200, + deActivateUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, deActivateUserResponse.getResponse()); + + String deleteUser = "DeleteUser"; + ExpectedUserCRUDAudit constructFieldsForAuditValidation = Convertor + .constructFieldsForAuditValidation(deleteUser, sdncAdminUser, ActionStatus.OK, null, sdncUserDetails); + AuditValidationUtils.validateAddUserAudit(constructFieldsForAuditValidation, deleteUser); + + } + + // US498322 - Add Status Field to USER + + @Test + public void createNewUser() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + @Test + public void createDefaultUser() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + sdncUserDetails.setFirstName(null); + sdncUserDetails.setLastName(null); + sdncUserDetails.setEmail(null); + sdncUserDetails.setRole(null); + + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + @Test + public void createTesterUser() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + sdncUserDetails.setLastName(null); + sdncUserDetails.setRole(UserRoleEnum.TESTER.name()); + + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + @Test + public void deActivateCreatedAdminUser() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + // deActivate created user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + sdncUserDetails.setStatus(UserStatusEnum.INACTIVE); + validateSuccessDeActivateUserResponse(sdncUserDetails, deActivateUserResponse); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + + assertEquals("Check response code after get user", errorInfo.getCode(), getUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables, + getUserResponse.getResponse()); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + @Test + public void deActivateTheSameUserTwice() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + // deActivate created user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + sdncUserDetails.setStatus(UserStatusEnum.INACTIVE); + validateSuccessDeActivateUserResponse(sdncUserDetails, deActivateUserResponse); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + + assertEquals("Check response code after deActive user", errorInfo.getCode(), + getUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables, + getUserResponse.getResponse()); + + // deActivate the same user once time more + RestResponse deActivateUserResponse2 = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + ErrorInfo errorInfo2 = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + assertEquals("Check response code after deActive user", errorInfo2.getCode(), + deActivateUserResponse2.getErrorCode()); + + List<String> variables2 = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables2, + deActivateUserResponse2.getResponse()); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + @Test + public void createAgainDeActivatedUser() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + + try { + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + // deActivate created user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + sdncUserDetails.setStatus(UserStatusEnum.INACTIVE); + validateSuccessDeActivateUserResponse(sdncUserDetails, deActivateUserResponse); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + + assertEquals("Check response code after deActive user", errorInfo.getCode(), + getUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables, + getUserResponse.getResponse()); + + // create the user with the same UserId(details) as deActivated user + DbUtils.cleanAllAudits(); + + RestResponse createUserResponse2 = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + ErrorInfo errorInfo2 = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + assertEquals("Check response code after deActive user", errorInfo2.getCode(), + createUserResponse2.getErrorCode()); + + List<String> variables2 = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables2, + createUserResponse2.getResponse()); + + } finally { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + // very not recommend to run this test, resources/services may be zombie + // @Test + public void deActivateLastAdminUser() throws Exception { + + try { + + // send get all ADMIN user request toward BE + RestResponse getAllAdminUsers = UserRestUtils.getAllAdminUsers(sdncAdminUser); + + assertNotNull("check response object is not null after create user", getAllAdminUsers); + assertNotNull("check error code exists in response after create user", getAllAdminUsers.getErrorCode()); + assertEquals("Check response code after create user", 200, getAllAdminUsers.getErrorCode().intValue()); + + TypeToken<List<User>> typeToken = new TypeToken<List<User>>() { + }; + List<User> listOfUsersOnResponse = gson.fromJson(getAllAdminUsers.getResponse(), typeToken.getType()); + logger.debug("listOfUsers: {}", listOfUsersOnResponse); + + // build map of all Admin users from listOfUsersOnResponse from + // response + Map<String, User> mapAllUsersOnResponse = new HashMap<String, User>(); + for (User sdncUser : listOfUsersOnResponse) { + mapAllUsersOnResponse.put(sdncUser.getUserId(), sdncUser); + } + + // remove from mapAllUsersOnResponse map one of admin users + mapAllUsersOnResponse.remove(sdncAdminUser.getUserId()); + logger.debug("map Of all Admin users exclude one : {}", mapAllUsersOnResponse); + + // deActivate all Admin users from the userIdAllAdminList list + for (Entry<String, User> entry : mapAllUsersOnResponse.entrySet()) { + UserRestUtils.deActivateUser(entry.getValue(), sdncAdminUser); + } + + // deActivate last Admin user user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncAdminUser, sdncAdminUser); + + ErrorInfo errorInfo = ErrorValidationUtils + .parseErrorConfigYaml(ActionStatus.DELETE_USER_ADMIN_CONFLICT.name()); + + assertEquals("Check response code after deActive user", errorInfo.getCode(), + deActivateUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.DELETE_USER_ADMIN_CONFLICT.name(), variables, + deActivateUserResponse.getResponse()); + + } finally { + // UserRestUtils.deleteUser(UserRestUtils.getAdminDetails2(), + // sdncAdminUser); + // UserRestUtils.deleteUser(UserRestUtils.getAdminDetails3(), + // sdncAdminUser); + // UserRestUtils.createUser(UserRestUtils.getAdminDetails2(), + // sdncAdminUser); + // UserRestUtils.createUser(UserRestUtils.getAdminDetails3(), + // sdncAdminUser); + } + + } + + // test check the resource accessibility via catalog view, resource was + // created by user which was deActivated + + @Test + public void resourceAccessibility() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource("tosca.nodes.newresource4test4", + NormativeTypesEnum.ROOT, ResourceCategoryEnum.GENERIC_INFRASTRUCTURE, "jh0003"); + String resourceBaseVersion = "0.1"; + + try { + // Delete resource + // resourceUtils.deleteResource_allVersions(resourceDetails, + // sdncAdminUser); + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + + DbUtils.cleanAllAudits(); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + // ------------------------Start create + // resource--------------------------------------------------------------------------------- + + // create resource + RestResponse createResponse = ResourceRestUtils.createResource(resourceDetails, sdncUserDetails); + assertEquals("Check response code after create", 201, createResponse.getErrorCode().intValue()); + + Resource createdResource = ResponseParser.convertResourceResponseToJavaObject(createResponse.getResponse()); + + RestResponse resourceGetResponse = ResourceRestUtils.getResource(sdncUserDetails, + createdResource.getUniqueId()); + assertEquals("Check response code after get", 200, resourceGetResponse.getErrorCode().intValue()); + + // validate get response + ResourceRespJavaObject resourceRespJavaObject = Convertor.constructFieldsForRespValidation(resourceDetails, + resourceBaseVersion); + resourceRespJavaObject.setLifecycleState((LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT).toString()); + resourceRespJavaObject.setAbstractt("false"); + resourceRespJavaObject.setCreatorUserId(sdncUserDetails.getUserId()); + resourceRespJavaObject.setLastUpdaterUserId(sdncUserDetails.getUserId()); + + resourceRespJavaObject + .setCreatorFullName(sdncUserDetails.getFirstName() + " " + sdncUserDetails.getLastName()); + resourceRespJavaObject + .setLastUpdaterFullName(sdncUserDetails.getFirstName() + " " + sdncUserDetails.getLastName()); + + ResourceValidationUtils.validateResp(resourceGetResponse, resourceRespJavaObject); + + // ------------------------End create + // resource--------------------------------------------------------------------------------- + + // clean audit before authorization test + DbUtils.cleanAllAudits(); + + // deActivate created user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + sdncUserDetails.setStatus(UserStatusEnum.INACTIVE); + validateSuccessDeActivateUserResponse(sdncUserDetails, deActivateUserResponse); + + UserValidationUtils.validateDeleteUserAuditMessage(sdncUserDetails, sdncAdminUser, "200", + UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("DeleteUser")); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + + assertEquals("Check response code after deActive user", errorInfo.getCode(), + getUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables, + getUserResponse.getResponse()); + + // checking if created resource is accessible + DbUtils.cleanAllAudits(); + + RestResponse getCatalogDataResponse = CatalogRestUtils.getCatalog(sdncAdminUser.getUserId()); + + // validate response + + assertNotNull("check response object is not null after user login", getCatalogDataResponse); + assertNotNull("check error code exists in response after user login", + getCatalogDataResponse.getErrorCode()); + assertEquals("Check response code after deActive user", 200, + getCatalogDataResponse.getErrorCode().intValue()); + + // expected resource list + List<String> resourceExpectedUniqIdList = new ArrayList<String>(); + resourceExpectedUniqIdList.add(resourceDetails.getUniqueId()); + logger.debug("resourceExpectedUniqIdList: {}", resourceExpectedUniqIdList); + + compareResourceUniqIdList(getCatalogDataResponse.getResponse(), resourceExpectedUniqIdList, true); + + } finally { + // resourceUtils.deleteResource_allVersions(resourceDetails, + // sdncAdminUser); + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + // test check the resource accessibility via catalog view, resource was + // created by user which was deActivated + + @Test + public void resourceAccessibilityOnImport() throws Exception { + + User sdncUserDetails = getDefaultUserDetails(); + ResourceReqDetails resourceDetails = ElementFactory.getDefaultResource("importResource4test", + NormativeTypesEnum.ROOT, ResourceCategoryEnum.NETWORK_L2_3_ROUTERS, "jh0003"); + resourceDetails.addCategoryChain(ResourceCategoryEnum.GENERIC_DATABASE.getCategory(), + ResourceCategoryEnum.GENERIC_DATABASE.getSubCategory()); + // String resourceBaseVersion = "1.0"; + + try { + // Delete resource + // resourceUtils.deleteResource_allVersions(resourceDetails, + // sdncAdminUser); + RestResponse deleteUserResponse = UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + assertTrue("delete user request failed", + deleteUserResponse.getErrorCode() == 200 || deleteUserResponse.getErrorCode() == 404); + DbUtils.cleanAllAudits(); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + validateSuccessCreateUserResponse(sdncUserDetails, createUserResponse); + + // ------------------------Start import + // resource--------------------------------------------------------------------------------- + + // import new resource with CERTIFIED state + User importer = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN4); + RestResponse importResponse = ImportRestUtils.importResourceByName(resourceDetails, importer); + + assertNotNull("check response object is not null after create user", importResponse); + assertNotNull("check error code exists in response after create user", importResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, importResponse.getErrorCode().intValue()); + + // ------------------------End import + // resource--------------------------------------------------------------------------------- + + // clean audit before authorization test + DbUtils.cleanAllAudits(); + + // deActivate created user + RestResponse deActivateUserResponse = UserRestUtils.deActivateUser(sdncUserDetails, sdncAdminUser); + sdncUserDetails.setStatus(UserStatusEnum.INACTIVE); + validateSuccessDeActivateUserResponse(sdncUserDetails, deActivateUserResponse); + + UserValidationUtils.validateDeleteUserAuditMessage(sdncUserDetails, sdncAdminUser, "200", + UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("DeleteUser")); + + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_INACTIVE.name()); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + + assertEquals("Check response code after deActive user", errorInfo.getCode(), + getUserResponse.getErrorCode()); + + List<String> variables = Arrays.asList(sdncUserDetails.getUserId()); + ErrorValidationUtils.checkBodyResponseOnError(ActionStatus.USER_INACTIVE.name(), variables, + getUserResponse.getResponse()); + + // checking if created resource is accessible + DbUtils.cleanAllAudits(); + + RestResponse getCatalogDataResponse = CatalogRestUtils.getCatalog(sdncAdminUser.getUserId()); + + // validate response + + assertNotNull("check response object is not null after user login", getCatalogDataResponse); + assertNotNull("check error code exists in response after user login", + getCatalogDataResponse.getErrorCode()); + assertEquals("Check response code after deActive user", 200, + getCatalogDataResponse.getErrorCode().intValue()); + + // expected resource list + List<String> resourceExpectedUniqIdList = new ArrayList<String>(); + resourceExpectedUniqIdList.add(resourceDetails.getUniqueId()); + logger.debug("resourceExpectedUniqIdList: {}", resourceExpectedUniqIdList); + + compareResourceUniqIdList(getCatalogDataResponse.getResponse(), resourceExpectedUniqIdList, true); + + } finally { + // resourceUtils.deleteResource_allVersions(resourceDetails, + // sdncAdminUser); + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + } + + } + + public void compareServiceUniqIdList(String response, List<String> expectedList, boolean flag) { + + JsonElement jelement = new JsonParser().parse(response); + JsonObject jobject = jelement.getAsJsonObject(); + JsonArray serviceArray = (JsonArray) jobject.get("services"); + logger.debug("{}", serviceArray); + assertTrue("expected service count: " + expectedList.size() + " or more" + ", actual: " + serviceArray.size(), + serviceArray.size() >= expectedList.size()); + + // build service list from response + List<ServiceReqDetails> serviceReqDetailsListOnResponse = new ArrayList<ServiceReqDetails>(); + for (int i = 0; i < serviceArray.size(); i++) { + ServiceReqDetails json = gson.fromJson(serviceArray.get(i), ServiceReqDetails.class); + serviceReqDetailsListOnResponse.add(json); + } + } + + public void compareResourceUniqIdList(String response, List<String> expectedList, boolean flag) { + + JsonElement jelement = new JsonParser().parse(response); + JsonObject jobject = jelement.getAsJsonObject(); + JsonArray resourceArray = (JsonArray) jobject.get("resources"); + logger.debug("{}", resourceArray); + assertTrue("expected resource count: " + expectedList.size() + " or more" + ", actual: " + resourceArray.size(), + resourceArray.size() >= expectedList.size()); + + // build resource list from response + List<ResourceReqDetails> resourceReqDetailsListOnResponse = new ArrayList<ResourceReqDetails>(); + for (int i = 0; i < resourceArray.size(); i++) { + ResourceReqDetails json = gson.fromJson(resourceArray.get(i), ResourceReqDetails.class); + resourceReqDetailsListOnResponse.add(json); + } + + logger.debug("ResourceReqDetails list on response: {}", resourceReqDetailsListOnResponse); + + List<String> resourceActualUniqIdList = new ArrayList<String>(); + for (ResourceReqDetails resource : resourceReqDetailsListOnResponse) { + resourceActualUniqIdList.add(resource.getUniqueId()); + } + logger.debug("resourceActualUniqIdList on response: {}", resourceActualUniqIdList); + logger.debug("resourceExpectedUniqIdList on response: {}", expectedList); + + if (flag) { + assertTrue("actual list does not contain expected list", + resourceActualUniqIdList.containsAll(expectedList)); + } else { + assertFalse("actual list contains non expected list elements", + resourceActualUniqIdList.containsAll(expectedList)); + } + } + + // public User getDefaultUserDetails(){ + // + // String userFirstName = "Kot"; + // String userLastName = "May"; + // String role = UserRoleEnum.ADMIN.name(); + // User sdncUserDetails = new User(userFirstName, userLastName, + // httpCspUserId, email, role,null); + // + // return sdncUserDetails; + // } + // + // public void validateSuccessCreateUserResponse(User sdncUserDetails, + // RestResponse createUserResponse) throws Exception{ + // + // assertNotNull("check response object is not null after create user", + // createUserResponse); + // assertNotNull("check error code exists in response after create user", + // createUserResponse.getErrorCode()); + // assertEquals("Check response code after create user", + // HttpStatus.SC_CREATED, createUserResponse.getErrorCode().intValue()); + // + // UserRestUtils.validateUserDetailsOnResponse(sdncUserDetails, + // createUserResponse.getResponse()); + // UserRestUtils.validateAddUserAuditMessage(sdncUserDetails, sdncAdminUser, + // String.valueOf(HttpStatus.SC_CREATED), + // UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + // UserRestUtils.getAddUserAuditMessage("AddUser")); + // RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, + // sdncAdminUser); + // UserRestUtils.validateUserDetailsOnResponse(sdncUserDetails, + // getUserResponse.getResponse()); + // + // } + // + // public void validateSuccessDeActivateUserResponse(User sdncUserDetails, + // RestResponse deActivateUserResponse) throws Exception{ + // + // assertNotNull("check response object is not null after deActive user", + // deActivateUserResponse); + // assertNotNull("check error code exists in response after deActive user", + // deActivateUserResponse.getErrorCode()); + // assertEquals("Check response code after deActive user", 200, + // deActivateUserResponse.getErrorCode().intValue()); + // + // UserRestUtils.validateUserDetailsOnResponse(sdncUserDetails, + // deActivateUserResponse.getResponse()); + // UserRestUtils.validateDeleteUserAuditMessage(sdncUserDetails, + // sdncAdminUser, "200", UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + // UserRestUtils.getAddUserAuditMessage("DeleteUser")); + // + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/CreateUserApiTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/CreateUserApiTest.java new file mode 100644 index 0000000000..2f979f3d15 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/CreateUserApiTest.java @@ -0,0 +1,1693 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.user; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; + +import java.io.IOException; + +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.enums.ErrorInfo; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.expected.ExpectedUserCRUDAudit; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.users.UserResponseMessageEnum; +import org.openecomp.sdc.ci.tests.utils.DbUtils; +import org.openecomp.sdc.ci.tests.utils.general.Convertor; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.UserRestUtils; +import org.openecomp.sdc.ci.tests.utils.validation.AuditValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ErrorValidationUtils; +import org.openecomp.sdc.ci.tests.utils.validation.UserValidationUtils; +import org.testng.AssertJUnit; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class CreateUserApiTest extends ComponentBaseTest { + + protected User sdncAdminUser; + protected User sdncDesignerUser; + protected User sdncGovernorUser; + protected User sdncTesterUser; + + public static final int STATUS_CODE_SUCCESS = 200; + public static final int STATUS_CODE_SUCSESS_CREATED = 201; + public static final int STATUS_CODE_SUCCESS_DELETE_GET = 200; + public static final int STATUS_CODE_INVALID_CONTENT = 400; + public static final int STATUS_CODE_MISSING_DATA = 400; + public static final int STATUS_CODE_MISSING_INFORMATION = 403; + public static final int STATUS_CODE_RESTRICTED_ACCESS = 403; + public static final int STATUS_CODE_NOT_FOUND = 404; + public static final int STATUS_CODE_RESTRICTED_OPERATION = 409; + public static final int USER_ALREADY_EXIST = 409; + public static final int INVALID_ROLE = 400; + + @Rule + public static TestName name = new TestName(); + + public CreateUserApiTest() { + super(name, CreateUserApiTest.class.getName()); + } + + @BeforeMethod + public void init() { + sdncAdminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + sdncDesignerUser = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + sdncGovernorUser = ElementFactory.getDefaultUser(UserRoleEnum.GOVERNOR); + sdncTesterUser = ElementFactory.getDefaultUser(UserRoleEnum.TESTER); + + } + + // Story : REST API to provision new user (POST) - US429379 + // must parameters: UserId and Email + + // **********************************************************201*************************************************** + // create user with full parameter set(UserID, First Name, Last Name, Email, + // Role = "DESIGNER", Creator details) + // expected 201 Created + @Test + public void createUser() throws Exception { + + // user initialization + String httpCspUserId = "km2000"; + String userFirstName = "Kot"; + String userLastName = "Matroskin"; + String email = "km2000@intl.sdc.com"; + String role = "ADMIN"; + User sdncUserDetails = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + String addUser = "AddUser"; + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + + AssertJUnit.assertNotNull("check response object is not null after create user", createUserResponse); + AssertJUnit.assertNotNull("check error code exists in response after create user", + createUserResponse.getErrorCode()); + AssertJUnit.assertEquals("Check response code after create user", 201, + createUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, createUserResponse.getResponse()); + + ExpectedUserCRUDAudit constructFieldsForAuditValidation = Convertor.constructFieldsForAuditValidation(addUser, + sdncAdminUser, ActionStatus.CREATED, sdncUserDetails, null); + AuditValidationUtils.validateAddUserAudit(constructFieldsForAuditValidation, addUser); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, getUserResponse.getResponse()); + } + + protected static final String ADD_USER = "AddUser"; + + private User mechIdUser = new User(); + private User emptyUser = new User(); + private static final User adminUser = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + + @AfterMethod + public void setup() throws IOException { + UserRestUtils.deactivateUser(mechIdUser, adminUser); + } + + // create default user(UserID, Email, Creator details) + // expected: role = DESIGNER, first and last name = null, 201 Created + @Test + public void createDefaultUser() throws Exception { + // user initialization + String httpCspUserId = "km2000"; + String userFirstName = null; + String userLastName = null; + String email = null; + String role = null; + User sdncUserDetails = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + + deleteUserAndAudit(sdncUserDetails); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, createUserResponse.getResponse()); + UserValidationUtils.validateAddUserAuditMessage(sdncUserDetails, sdncAdminUser, "201", + UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, getUserResponse.getResponse()); + + } + + // create user with one optional parameter first name (UserID, Email, First + // Name, Creator details) + // expected: role = DESIGNER, last name = null, 201 Created + @Test + public void createUserFirstName() throws Exception { + // user initialization + String httpCspUserId = "km2000"; + String userFirstName = "Kot"; + String userLastName = null; + String email = null; + String role = null; + User sdncUserDetails = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + + deleteUserAndAudit(sdncUserDetails); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, createUserResponse.getResponse()); + UserValidationUtils.validateAddUserAuditMessage(sdncUserDetails, sdncAdminUser, "201", + UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, getUserResponse.getResponse()); + } + + @Test + public void createDeleteOpsUser() throws Exception { + + String httpCspUserId = "oo2000"; + String userFirstName = "ops"; + String userLastName = "opsLast"; + String email = "ops@intl.sdc.com"; + String role = "OPS"; + User sdncUserDetails = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + + deleteUserAndAudit(sdncUserDetails); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, createUserResponse.getResponse()); + UserValidationUtils.validateAddUserAuditMessage(sdncUserDetails, sdncAdminUser, "201", + UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, getUserResponse.getResponse()); + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + RestResponse getDeletedUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + assertEquals("Check response code after delete user", 404, getDeletedUserResponse.getErrorCode().intValue()); + + } + + @Test + public void createDeleteGOVERNORUser() throws Exception { + + String httpCspUserId = "gg2000"; + String userFirstName = "gov"; + String userLastName = "govLast"; + String email = "gov@intl.sdc.com"; + String role = "GOVERNOR"; + User sdncUserDetails = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + + deleteUserAndAudit(sdncUserDetails); + RestResponse createUserResponse = UserRestUtils.createUser(sdncUserDetails, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, createUserResponse.getResponse()); + UserValidationUtils.validateAddUserAuditMessage(sdncUserDetails, sdncAdminUser, "201", + UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + RestResponse getUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(sdncUserDetails, getUserResponse.getResponse()); + + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + RestResponse getDeletedUserResponse = UserRestUtils.getUser(sdncUserDetails, sdncAdminUser); + assertEquals("Check response code after delete user", 404, getDeletedUserResponse.getErrorCode().intValue()); + + } + + // Benny + // Admin Create OPS user + @Test + public void createOpsUser() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "aa1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + User expectedOpsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedOpsUser); + RestResponse createUserResponse = UserRestUtils.createUser(expectedOpsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedOpsUser, createUserResponse.getResponse()); + deleteAndCheckUserResponse(expectedOpsUser, 200); + + } + + // Admin Create GOVERNOR user + @Test + public void createGovernorUser() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "aa1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + User expectedUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedUser); + RestResponse createUserResponse = UserRestUtils.createUser(expectedUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedUser, createUserResponse.getResponse()); + RestResponse getUserResponse = UserRestUtils.getUser(expectedUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedUser, getUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(expectedUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from OPS to GOVERNOR + @Test + public void updateOpsUserRole() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ab1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "GOVERNOR"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(governerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(governerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Designer Create OPS user -409 Response Restricted operation + @Test + public void createOpsUserByDesigner() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "aa1122"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + User expectedOpsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedOpsUser); + RestResponse createUserResponse = UserRestUtils.createUser(expectedOpsUser, sdncDesignerUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 409, createUserResponse.getErrorCode().intValue()); + assertEquals("Check response code after create user", "Conflict", createUserResponse.getResponseMessage()); + } + + // Tester Create OPS user -409 Response Restricted operation + @Test + public void createOpsUserByTester() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "aa1122"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + User expectedOpsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedOpsUser); + RestResponse createUserResponse = UserRestUtils.createUser(expectedOpsUser, sdncTesterUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 409, createUserResponse.getErrorCode().intValue()); + assertEquals("Check response code after create user", "Conflict", createUserResponse.getResponseMessage()); + } + + // Designer Try Update OPS user role to GOVERNOR - Response 409 + @Test + public void updateOpsUserRolebyDesigner() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "bt751e"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "GOVERNOR"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // Admin create user with OPS role + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // Designer user try to update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncDesignerUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 409, updateUserRoleResponse.getErrorCode().intValue()); + assertEquals("Check response code after updating user", "Conflict", + updateUserRoleResponse.getResponseMessage()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Tester Try Update OPS user role to GOVERNOR - Response 409 + @Test + public void updateOpsUserRolebyTester() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "bt751w"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "GOVERNOR"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // Admin create user with OPS role + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // Designer user try to update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncTesterUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 409, updateUserRoleResponse.getErrorCode().intValue()); + assertEquals("Check response code after updating user", "Conflict", + updateUserRoleResponse.getResponseMessage()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from OPS to Designer + @Test + public void updateOpsUserRoleFromOpsToDesigner() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ab1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "DESIGNER"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User designerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(designerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(designerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from OPS to TESTER + @Test + public void updateOpsUserRoleFromOpsToTester() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ac1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "TESTER"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User testerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(testerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(testerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Tester try to Update user role from OPS to GOVERNOR - Response 409 + // Conflict + @Test + public void updateOpsUserRoleByTester() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ad1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "GOVERNOR"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + // Create user by Admin + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR by Tester + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncTesterUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 409, updateUserRoleResponse.getErrorCode().intValue()); + assertEquals("Check response code after updating user", "Conflict", + updateUserRoleResponse.getResponseMessage()); + + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Designer try to Update user role from OPS to GOVERNOR - Response 409 + // Conflict + @Test + public void updateOpsUserRoleByDesigner() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ad1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + String updatedRole = "GOVERNOR"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + // User governerUser = new User(userFirstName, + // userLastName,httpCspUserId, email, updatedRole); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + // Create user by Admin + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR by Tester + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncDesignerUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 409, updateUserRoleResponse.getErrorCode().intValue()); + assertEquals("Check response code after updating user", "Conflict", + updateUserRoleResponse.getResponseMessage()); + + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Create OPS user - user already exist + @Test + public void createOpsUserAlreadyExist() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "af1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "OPS"; + User expectedOpsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedOpsUser); + RestResponse createUserResponse = UserRestUtils.createUser(expectedOpsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedOpsUser, createUserResponse.getResponse()); + // Create user that already exists + RestResponse createUserAgainResponse = UserRestUtils.createUser(expectedOpsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserAgainResponse); + assertNotNull("check error code exists in response after create user", createUserAgainResponse.getErrorCode()); + assertEquals("Check response code after create user", 409, createUserAgainResponse.getErrorCode().intValue()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(expectedOpsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from OPS to GOVERNOR - user already has GOVERNOR + // role + @Test + public void updateRoleToSameRole() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ag1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = "GOVERNOR"; + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + RestResponse createUserResponse = UserRestUtils.createUser(opsUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, createUserResponse.getResponse()); + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from GOVERNOR to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + opsUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(governerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(governerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from Tester to GOVERNOR - 200 response + + // Admin Update user role from Designer to GOVERNOR - 200 response + @Test + public void updateUserRoleDesignerToGovernor() throws Exception { + DbUtils.cleanAllAudits(); + String httpCspUserId = "ah1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "DESIGNER"; + String updatedRole = "GOVERNOR"; + User designerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(designerUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(designerUser, createUserResponse.getResponse()); + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from TESTER to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + designerUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + // Update user role + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(governerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(governerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(designerUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update deactivated user role - response 404 (user not found) + @Test + public void updateRoleToDeactivatedUser() throws Exception { + DbUtils.cleanAllAudits(); + String httpCspUserId = "aj1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "DESIGNER"; + String updatedRole = "GOVERNOR"; + User designerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User governerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(designerUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(designerUser, createUserResponse.getResponse()); + deleteAndCheckUserResponse(designerUser, 200); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role - user deActivted + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + designerUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after create user", 404, updateUserRoleResponse.getErrorCode().intValue()); + } + + // Admin Update user role, user does not exist in DB - response 404 (user + // not found) + @Test + public void updateRoleForNonExistingUser() throws Exception { + DbUtils.cleanAllAudits(); + String httpCspUserId = "aj1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "DESIGNER"; + String updatedRole = "GOVERNOR"; + User designerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + // User governerUser = new User(userFirstName, + // userLastName,httpCspUserId, email, updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role - user deActivted + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + designerUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 404, updateUserRoleResponse.getErrorCode().intValue()); + + } + + // Admin Update user role from GOVERNOR to TESTER + @Test + public void updateRoleFromGovernorToTester() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ak1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = "TESTER"; + User governorUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User testerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(governorUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(governorUser, createUserResponse.getResponse()); + + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + governorUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(testerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(testerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(governorUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from GOVERNOR to DESIGNER + @Test + public void updateRoleFromGovernorToDesigner() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ak1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = "DESIGNER"; + User governorUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User designerUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(governorUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(governorUser, createUserResponse.getResponse()); + + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + governorUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(designerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(designerUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(governorUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role from GOVERNOR to OPS + @Test + public void updateRoleFromGovernorToOps() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ak1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = "OPS"; + User governorUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User opsUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(governorUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(governorUser, createUserResponse.getResponse()); + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + governorUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(opsUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(opsUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + deleteAndCheckUserResponse(governorUser, 200); + + } + + private void deleteAndCheckUserResponse(User userDetailes, int expectedResponseCode) throws IOException { + RestResponse deleteUser = UserRestUtils.deleteUser(sdncGovernorUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteUser); + assertEquals("Check response code after deleting user", expectedResponseCode, + deleteUser.getErrorCode().intValue()); + } + + // Admin Update user role from GOVERNOR to ADMIN + @Test + public void updateRoleFromGovernorToAdmin() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ak1000"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = "ADMIN"; + User governorUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User adminUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(governorUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(governorUser, createUserResponse.getResponse()); + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + governorUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 200, updateUserRoleResponse.getErrorCode().intValue()); + + RestResponse getUpdatedRoleUserResponse = UserRestUtils.getUser(adminUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(adminUser, getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(governorUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role to non existing role - Response 400 Bad Request + @Test + public void updateRoleToNonExistingRole() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "al1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = "VVVVVVV"; + User governorUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User newUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(governorUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(governorUser, createUserResponse.getResponse()); + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role from OPS to GOVERNOR + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + governorUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 400, updateUserRoleResponse.getErrorCode().intValue()); + assertEquals("Check response code after updating user", "Bad Request", + updateUserRoleResponse.getResponseMessage()); + + // RestResponse getUpdatedRoleUserResponse = + // UserRestUtils.getUser(adminUser,sdncAdminUser); + // UserValidationUtils.validateUserDetailsOnResponse(adminUser,getUpdatedRoleUserResponse.getResponse()); + // Delete OPS user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(governorUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // Admin Update user role to null - Response 400 Bad Request + @Test + public void updateRoleToNull() throws Exception { + DbUtils.cleanAllAudits(); + + String httpCspUserId = "ax1001"; + String userFirstName = "Benny"; + String userLastName = "Tal"; + String email = "optBenny@intl.sdc.com"; + String role = "GOVERNOR"; + String updatedRole = ""; + User governorUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + User newUser = new User(userFirstName, userLastName, httpCspUserId, email, updatedRole, null); + // UserRestUtils.deleteUser(opsUser, sdncAdminUser, true); + // UserRestUtils.deleteUser(UserUpdateRole, sdncAdminUser); + RestResponse createUserResponse = UserRestUtils.createUser(governorUser, sdncAdminUser); + assertNotNull("check response object is not null after create user", createUserResponse); + assertNotNull("check error code exists in response after create user", createUserResponse.getErrorCode()); + assertEquals("Check response code after create user", 201, createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(governorUser, createUserResponse.getResponse()); + // opsUser.setRole(updatedRole); + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // update user role + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + governorUser.getUserId()); + assertNotNull("check response object is not null after updating user", updateUserRoleResponse); + assertNotNull("check error code exists in response after updating user", updateUserRoleResponse.getErrorCode()); + assertEquals("Check response code after updating user", 400, updateUserRoleResponse.getErrorCode().intValue()); + assertEquals("Check response code after updating user", "Bad Request", + updateUserRoleResponse.getResponseMessage()); + // Delete user + RestResponse deleteOpsUser = UserRestUtils.deleteUser(governorUser, sdncAdminUser, true); + assertNotNull("check response object is not null after deleting user", deleteOpsUser); + assertEquals("Check response code after deleting user", 200, deleteOpsUser.getErrorCode().intValue()); + + } + + // create user with one optional parameter last name (UserID, Email, Last + // Name, Creator details) + // expected: role = DESIGNER, first name = null, 201 Created + // @Test + // public void createUserLastName(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // // create user with one optional parameter role name (UserID, Email, Role + // = "TESTER", Creator details) + // // expected: first and last name = null, 201 Created + // @Test + // public void createUserRoleName(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // // create user with two optional parameters first name and role (UserID, + // Email, First Name, Role = "ADMIN", Creator details) + // // expected: last name = null, 201 Created + // @Test + // public void createUserFirstNameAndRole(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // // create user with two optional parameters first and last name(UserID, + // Email, First Name, Last name, Creator details) + // // expected: role = DESIGNER, 201 Created + // @Test + // public void createUserFirstAndLastName(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // + // + // + // + // // + // **********************************************************Create*user*failed*************************************************** + // + // // + // **********************************************************403*************************************************** + // // create default user without creator details (UserID, Email) + // // expected: 403 Forbidden, error message:"Error : Missing information" + // @Test + // public void createDefaultUserNonCreatorDetails(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // + // // create user with part of creator details (UserID, Email, First name, + // Last Name, Role, Part of creator details) + // // expected: 403 Forbidden, error message:"Error : Missing information" + // @Test + // public void createUserPartOfCreatorDetails(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // // create user with full parameter set, non admin creator(UserID, First + // Name, Last Name, Email, Role, Creator details) + // // expected: 403 Forbidden, error message: + // "Error : Restricted operation" + // @Test + // public void createUserNonAdminCreator(){ + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // + // // + // **********************************************************405*************************************************** + // + // // create user with full parameter set by sending http PUT request + // (UserID, First Name, Last Name, Email, Role, Creator details) + // // expected: 405 not Allowed, error message: + // "Error : Method not allowed" + // @Test + // public void createUserPutRequest(){ + // // send PUT create user request + // // validate data on response + // // check the audit message + // } + // + // + // // create default user by sending http PUT request (UserID, Email, + // Creator details) + // // expected: 405 not Allowed, error message: + // "Error : Method not allowed" + // @Test + // public void createDefaultUserPutRequest(){ + // // send PUT create user request + // // validate data on response + // // check the audit message + // } + // + // + // // create user with full parameter set by sending http DELETE request + // (UserID, First Name, Last Name, Email, Role, Creator details) + // // expected: 405 not Allowed, error message: + // "Error : Method not allowed" + // @Test + // public void createUserDeleteRequest(){ + // // send DELETE create user request + // // validate data on response + // // check the audit message + // } + // + // + // // create default user by sending http DELETE request (UserID, Email, + // Creator details) + // // expected: 405 not Allowed, error message: + // "Error : Method not allowed" + // @Test + // public void createDefaultUserDeleteRequest(){ + // // send DELETE create user request + // // validate data on response + // // check the audit message + // } + // + // + // // create user with full parameter set by sending http GET request + // (UserID, First Name, Last Name, Email, Role, Creator details) + // // expected: 405 not Allowed, error message: + // "Error : Method not allowed" + // @Test + // public void createUserGetRequest(){ + // // send GET create user request + // // validate data on response + // // check the audit message + // } + // + // + // // create default user by sending http GET request (UserID, Email, + // Creator details) + // // expected: 405 not Allowed, error message: + // "Error : Method not allowed" + // @Test + // public void createDefaultUserGetRequest(){ + // // send GET create user request + // // validate data on response + // // check the audit message + // } + // + // + // // + // **********************************************************409*************************************************** + // + // // create the same user twice with full parameter set(UserID, First Name, + // Last Name, Email, Role, Creator details) + // // expected 409 Conflict, error message: + // "Error : User with '%s' ID already exists", where: %s - USER_ID + // @Test + // public void createSameUserTwice(){ + // // send POST create user request + // // validate data on response + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // // create user twice, first full details (UserID, First Name, Last Name, + // Email, Role, Creator details), second default user (UserID, Email, Role, + // Creator details) + // // expected 409 Conflict, error message: + // "Error : User with '%s' ID already exists", where: %s - USER_ID + // @Test + // public void createFullThanDefaultUserTwice(){ + // // send POST create user request + // + // // validate data on response + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // // create user twice, first default user (UserID, Email, Role, Creator + // details), second full details (UserID, First Name, Last Name, Email, + // Role, Creator details) + // // expected 409 Conflict, error message: + // "Error : User with '%s' ID already exists", where: %s - USER_ID + // @Test + // public void createDefaulThanFullUserTwice(){ + // // send POST create user request + // + // // validate data on response + // // send POST create user request + // // validate data on response + // // check the audit message + // } + // + // + // // + // **********************************************************400*************************************************** + // // create default user with invalid email address format(UserID, Email, + // Creator details) + // // expected: 400, error message: + // "Error : Invalid Content . Invalid e-mail address '%s'", where %s - + // email address + // @Test + // public void createDefaultUserInvalidEmailAddressFormat(){ + // // send GET create user request + // // validate data on response + // // check the audit message + // } + // + // // create an user with invalid role type (UserID, Email,Role = "TESTER-1" + // ,Creator details) + // // expected: 400, error message: + // "Error : Invalid Content . Invalid role '%s'", where %s - role type + // @Test + // public void createUserInvalidRoleType(){ + // // send GET create user request + // // validate data on response + // // check the audit message + // } + // + // // + // **********************************************************500*************************************************** + // // create default user when BE is down (UserID, Email, Creator details) + // // expected: 500, error message: + // "Error : Internal Server Error . Try later again." + // @Test + // public void createDefaultUserBeNoAccess(){ + // // send GET create user request + // // validate data on response + // // check the audit message + // } + // + + // Benny US570551 + + @Test + public void createProductManagerUser() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Man"; + String email = "prodMan@intl.sdc.com"; + String role = "PRODUCT_MANAGER"; + User expectedProductManagerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + UserRestUtils.deleteUser(expectedProductManagerUser, sdncAdminUser, true); + DbUtils.deleteFromEsDbByPattern("_all"); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, createUserResponse.getResponse()); + // Audit validation + UserValidationUtils.validateAddUserAuditMessage(expectedProductManagerUser, sdncAdminUser, + Integer.toString(STATUS_CODE_SUCSESS_CREATED), UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductManagerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, getUserResponse.getResponse()); + // Delete ProductManager user + RestResponse deleteProductManagerUser = UserRestUtils.deleteUser(expectedProductManagerUser, sdncAdminUser, + true); + assertEquals("Check response code after deleting OPS user", STATUS_CODE_SUCCESS, + deleteProductManagerUser.getErrorCode().intValue()); + } + + @Test + public void createProductStrategistUser() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodStr@intl.sdc.com"; + String role = "PRODUCT_STRATEGIST"; + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + UserRestUtils.deleteUser(expectedProductStrategistUser, sdncAdminUser, true); + DbUtils.deleteFromEsDbByPattern("_all"); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductStrategistUser, + createUserResponse.getResponse()); + // Audit validation + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, sdncAdminUser, + Integer.toString(STATUS_CODE_SUCSESS_CREATED), UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductStrategistUser, getUserResponse.getResponse()); + // Delete ProductStrategist user + RestResponse deleteProductStrategistUser = UserRestUtils.deleteUser(expectedProductStrategistUser, + sdncAdminUser, true); + assertNotNull("Check response object is not null after deleting OPS user", deleteProductStrategistUser); + assertEquals("Check response code after deleting OPS user", 200, + deleteProductStrategistUser.getErrorCode().intValue()); + } + + @Test + public void createProductStrategistUserByNonAdminUser() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodStr@intl.sdc.com"; + String role = "PRODUCT_STRATEGIST"; + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + UserRestUtils.deleteUser(expectedProductStrategistUser, sdncAdminUser, true); + DbUtils.deleteFromEsDbByPattern("_all"); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, sdncDesignerUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_RESTRICTED_OPERATION, + createUserResponse.getErrorCode().intValue()); + // Audit validation + expectedProductStrategistUser.setUserId(""); + expectedProductStrategistUser.setFirstName(null); + expectedProductStrategistUser.setLastName(null); + expectedProductStrategistUser.setEmail(""); + expectedProductStrategistUser.setRole(""); + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, sdncDesignerUser, + Integer.toString(STATUS_CODE_RESTRICTED_OPERATION), errorInfo.getAuditDesc(""), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // Try to get user - user is not created + expectedProductStrategistUser.setUserId("pm1000"); + expectedProductStrategistUser.setFirstName("Prod"); + expectedProductStrategistUser.setLastName("Strategist"); + expectedProductStrategistUser.setEmail("prodStr@intl.sdc.com"); + expectedProductStrategistUser.setRole("PRODUCT_STRATEGIST"); + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code ", STATUS_CODE_NOT_FOUND, getUserResponse.getErrorCode().intValue()); + } + + @Test + public void createProductManagerUserByNonAdminUser() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Man"; + String email = "prodStr@intl.sdc.com"; + String role = "PRODUCT_MANAGER"; + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + UserRestUtils.deleteUser(expectedProductStrategistUser, sdncAdminUser, true); + DbUtils.deleteFromEsDbByPattern("_all"); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, sdncDesignerUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_RESTRICTED_OPERATION, + createUserResponse.getErrorCode().intValue()); + // Audit validation + expectedProductStrategistUser.setUserId(""); + expectedProductStrategistUser.setFirstName(null); + expectedProductStrategistUser.setLastName(null); + expectedProductStrategistUser.setEmail(""); + expectedProductStrategistUser.setRole(""); + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.RESTRICTED_OPERATION.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, sdncDesignerUser, + Integer.toString(STATUS_CODE_RESTRICTED_OPERATION), errorInfo.getAuditDesc(""), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // Try to get user - user is not created + expectedProductStrategistUser.setUserId("pm1000"); + expectedProductStrategistUser.setFirstName("Prod"); + expectedProductStrategistUser.setLastName("Strategist"); + expectedProductStrategistUser.setEmail("prodStr@intl.sdc.com"); + expectedProductStrategistUser.setRole("PRODUCT_MANAGER"); + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code ", STATUS_CODE_NOT_FOUND, getUserResponse.getErrorCode().intValue()); + } + + @Test + public void createProductStrategistUserByNonExistingUser() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodStr@intl.sdc.com"; + String role = "PRODUCT_STRATEGIST"; + User noSdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + noSdncUserDetails.setRole("blabla"); + noSdncUserDetails.setUserId("bt750h"); + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + DbUtils.deleteFromEsDbByPattern("_all"); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, noSdncUserDetails); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_NOT_FOUND, + createUserResponse.getErrorCode().intValue()); + // Audit validation + expectedProductStrategistUser.setUserId(""); + expectedProductStrategistUser.setFirstName(null); + expectedProductStrategistUser.setLastName(null); + expectedProductStrategistUser.setEmail(""); + expectedProductStrategistUser.setRole(""); + noSdncUserDetails.setFirstName(""); + noSdncUserDetails.setLastName(""); + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_NOT_FOUND.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, noSdncUserDetails, + Integer.toString(STATUS_CODE_NOT_FOUND), errorInfo.getAuditDesc(noSdncUserDetails.getUserId()), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // Try to get user - user is not created + expectedProductStrategistUser.setUserId("pm1000"); + expectedProductStrategistUser.setFirstName("Prod"); + expectedProductStrategistUser.setLastName("Strategist"); + expectedProductStrategistUser.setEmail("prodStr@intl.sdc.com"); + expectedProductStrategistUser.setRole("PRODUCT_STRATEGIST"); + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code ", STATUS_CODE_NOT_FOUND, getUserResponse.getErrorCode().intValue()); + } + + @Test + public void createProductManagerUserByNonExistingUser() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Man"; + String email = "prodStr@intl.sdc.com"; + String role = "PRODUCT_MANAGER"; + User noSdncUserDetails = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + noSdncUserDetails.setRole("blabla"); + noSdncUserDetails.setUserId("bt750h"); + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + DbUtils.deleteFromEsDbByPattern("_all"); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, noSdncUserDetails); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_NOT_FOUND, + createUserResponse.getErrorCode().intValue()); + // Audit validation + expectedProductStrategistUser.setUserId(""); + expectedProductStrategistUser.setFirstName(null); + expectedProductStrategistUser.setLastName(null); + expectedProductStrategistUser.setEmail(""); + expectedProductStrategistUser.setRole(""); + noSdncUserDetails.setFirstName(""); + noSdncUserDetails.setLastName(""); + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_NOT_FOUND.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, noSdncUserDetails, + Integer.toString(STATUS_CODE_NOT_FOUND), errorInfo.getAuditDesc(noSdncUserDetails.getUserId()), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // Try to get user - user is not created + expectedProductStrategistUser.setUserId("pm1000"); + expectedProductStrategistUser.setFirstName("Prod"); + expectedProductStrategistUser.setLastName("Strategist"); + expectedProductStrategistUser.setEmail("prodStr@intl.sdc.com"); + expectedProductStrategistUser.setRole("PRODUCT_MANAGER"); + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code ", STATUS_CODE_NOT_FOUND, getUserResponse.getErrorCode().intValue()); + } + + @Test(enabled = false) + public void updateProjectManagerRole() throws Exception { + // Update user role from PRODUCT_STRATEGIST to PRODUCT_MANAGER + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Man"; + String email = "prodMan@intl.sdc.com"; + String role = "PRODUCT_MANAGER"; + String updatedRole = "GOVERNOR"; + User expectedProductManagerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedProductManagerUser); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, createUserResponse.getResponse()); + // Update user role + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // Update user role from PRODUCT_STRATEGIST to PRODUCT_MANAGER + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + expectedProductManagerUser.getUserId()); + assertEquals("Check response code after create user", STATUS_CODE_SUCCESS, + updateUserRoleResponse.getErrorCode().intValue()); + expectedProductManagerUser.setRole(updatedRole); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, + updateUserRoleResponse.getResponse()); + // Audit validation + UserValidationUtils.validateAddUserAuditMessage(expectedProductManagerUser, sdncAdminUser, + Integer.toString(STATUS_CODE_SUCCESS), UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("UpdateUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductManagerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, getUserResponse.getResponse()); + // Delete ProductManager user + RestResponse deleteProductManagerUser = UserRestUtils.deleteUser(expectedProductManagerUser, sdncAdminUser, + true); + assertEquals("Check response code after deleting OPS user", STATUS_CODE_SUCCESS, + deleteProductManagerUser.getErrorCode().intValue()); + } + + @Test(enabled = false) + public void updateProductStrategistRole() throws Exception { + // Update user role from PRODUCT_STRATEGIST to PRODUCT_MANAGER + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodMan@intl.sdc.com"; + String role = "PRODUCT_STRATEGIST"; + String updatedRole = "TESTER"; + User expectedProductManagerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedProductManagerUser); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, createUserResponse.getResponse()); + // Update user role + User newRoleUser = new User(); + newRoleUser.setRole(updatedRole); + // Update user role from PRODUCT_STRATEGIST to PRODUCT_MANAGER + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + expectedProductManagerUser.getUserId()); + assertEquals("Check response code after create user", STATUS_CODE_SUCCESS, + updateUserRoleResponse.getErrorCode().intValue()); + expectedProductManagerUser.setRole(updatedRole); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, + updateUserRoleResponse.getResponse()); + // Audit validation + UserValidationUtils.validateAddUserAuditMessage(expectedProductManagerUser, sdncAdminUser, + Integer.toString(STATUS_CODE_SUCCESS), UserResponseMessageEnum.SUCCESS_MESSAGE.getValue(), + UserValidationUtils.getAddUserAuditMessage("UpdateUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductManagerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, getUserResponse.getResponse()); + // Delete ProductManager user + RestResponse deleteProductManagerUser = UserRestUtils.deleteUser(expectedProductManagerUser, sdncAdminUser, + true); + assertEquals("Check response code after deleting OPS user", STATUS_CODE_SUCCESS, + deleteProductManagerUser.getErrorCode().intValue()); + } + + @Test + public void createProductManagerUserAlreadyExit() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Man"; + String email = "prodMan@intl.sdc.com"; + String role = "PRODUCT_MANAGER"; + User expectedProductManagerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedProductManagerUser); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, createUserResponse.getResponse()); + // create same user again + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse createUserAgainResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", USER_ALREADY_EXIST, + createUserAgainResponse.getErrorCode().intValue()); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_ALREADY_EXIST.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductManagerUser, sdncAdminUser, + Integer.toString(USER_ALREADY_EXIST), errorInfo.getAuditDesc(expectedProductManagerUser.getUserId()), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductManagerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, getUserResponse.getResponse()); + // Delete ProductManager user + RestResponse deleteProductManagerUser = UserRestUtils.deleteUser(expectedProductManagerUser, sdncAdminUser, + true); + assertEquals("Check response code after deleting OPS user", STATUS_CODE_SUCCESS, + deleteProductManagerUser.getErrorCode().intValue()); + } + + @Test + public void createProductStrategistUserAlreadyExit() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodMan@intl.sdc.com"; + String role = "PRODUCT_STRATEGIST"; + User expectedProductManagerUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedProductManagerUser); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, createUserResponse.getResponse()); + // create same user again + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse createUserAgainResponse = UserRestUtils.createUser(expectedProductManagerUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", USER_ALREADY_EXIST, + createUserAgainResponse.getErrorCode().intValue()); + // Audit validation + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.USER_ALREADY_EXIST.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductManagerUser, sdncAdminUser, + Integer.toString(USER_ALREADY_EXIST), errorInfo.getAuditDesc(expectedProductManagerUser.getUserId()), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductManagerUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductManagerUser, getUserResponse.getResponse()); + // Delete ProductManager user + RestResponse deleteProductManagerUser = UserRestUtils.deleteUser(expectedProductManagerUser, sdncAdminUser, + true); + assertEquals("Check response code after deleting OPS user", STATUS_CODE_SUCCESS, + deleteProductManagerUser.getErrorCode().intValue()); + } + + @Test(enabled = false) + public void UpdateProductStrategistToNonExistingRole() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodMan@intl.sdc.com"; + String role = "PRODUCT_STRATEGIST"; + String nonExistingRole = "BLABLA"; + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedProductStrategistUser); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", STATUS_CODE_SUCSESS_CREATED, + createUserResponse.getErrorCode().intValue()); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductStrategistUser, + createUserResponse.getResponse()); + // Update user Role to non Existing role + User newRoleUser = new User(); + newRoleUser.setRole(nonExistingRole); + DbUtils.deleteFromEsDbByPattern("_all"); + RestResponse updateUserRoleResponse = UserRestUtils.updateUserRole(newRoleUser, sdncAdminUser, + expectedProductStrategistUser.getUserId()); + assertEquals("Check response code after updating user role", INVALID_ROLE, + updateUserRoleResponse.getErrorCode().intValue()); + + // Audit validation + /* + * expectedProductStrategistUser.setUserId(""); + * expectedProductStrategistUser.setFirstName(null); + * expectedProductStrategistUser.setLastName(null); + * expectedProductStrategistUser.setEmail(""); + * expectedProductStrategistUser.setRole(""); + */ + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_ROLE.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, sdncAdminUser, + Integer.toString(INVALID_ROLE), errorInfo.getAuditDesc(nonExistingRole), + UserValidationUtils.getAddUserAuditMessage("UpdateUser")); + // get user and compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + UserValidationUtils.validateUserDetailsOnResponse(expectedProductStrategistUser, getUserResponse.getResponse()); + // Delete ProductManager user + RestResponse deleteProductManagerUser = UserRestUtils.deleteUser(expectedProductStrategistUser, sdncAdminUser, + true); + assertEquals("Check response code after deleting OPS user", STATUS_CODE_SUCCESS, + deleteProductManagerUser.getErrorCode().intValue()); + } + + @Test(enabled = false) + public void createUserWithNonExistingRole() throws Exception { + String httpCspUserId = "pm1000"; + String userFirstName = "Prod"; + String userLastName = "Strategist"; + String email = "prodMan@intl.sdc.com"; + String role = "BLABLA"; + User expectedProductStrategistUser = new User(userFirstName, userLastName, httpCspUserId, email, role, null); + deleteUserAndAudit(expectedProductStrategistUser); + // create user + RestResponse createUserResponse = UserRestUtils.createUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check response code after create Product-Manager user", INVALID_ROLE, + createUserResponse.getErrorCode().intValue()); + + // Audit validation + /* + * expectedProductStrategistUser.setUserId(""); + * expectedProductStrategistUser.setFirstName(null); + * expectedProductStrategistUser.setLastName(null); + * expectedProductStrategistUser.setEmail(""); + * expectedProductStrategistUser.setRole(""); + */ + ErrorInfo errorInfo = ErrorValidationUtils.parseErrorConfigYaml(ActionStatus.INVALID_ROLE.name()); + UserValidationUtils.validateAddUserAuditMessage(expectedProductStrategistUser, sdncAdminUser, + Integer.toString(INVALID_ROLE), errorInfo.getAuditDesc(role), + UserValidationUtils.getAddUserAuditMessage("AddUser")); + // get user - verify user is not createdand compare with expected + RestResponse getUserResponse = UserRestUtils.getUser(expectedProductStrategistUser, sdncAdminUser); + assertEquals("Check user not created", STATUS_CODE_NOT_FOUND, getUserResponse.getErrorCode().intValue()); + + } + + private void deleteUserAndAudit(User sdncUserDetails) throws IOException { + UserRestUtils.deleteUser(sdncUserDetails, sdncAdminUser, true); + DbUtils.cleanAllAudits(); + } + +} diff --git a/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/GovernorWorkspaceApiTest.java b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/GovernorWorkspaceApiTest.java new file mode 100644 index 0000000000..5dd1abcf24 --- /dev/null +++ b/test-apis-ci/src/main/java/org/openecomp/sdc/ci/tests/execute/user/GovernorWorkspaceApiTest.java @@ -0,0 +1,319 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.ci.tests.execute.user; + +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertTrue; + +import java.io.IOException; +import java.util.List; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; +import org.openecomp.sdc.be.model.DistributionStatusEnum; +import org.openecomp.sdc.be.model.Resource; +import org.openecomp.sdc.be.model.Service; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.ci.tests.api.ComponentBaseTest; +import org.openecomp.sdc.ci.tests.datatypes.ArtifactReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ComponentInstanceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ResourceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.ServiceReqDetails; +import org.openecomp.sdc.ci.tests.datatypes.enums.ArtifactTypeEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.LifeCycleStatesEnum; +import org.openecomp.sdc.ci.tests.datatypes.enums.UserRoleEnum; +import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse; +import org.openecomp.sdc.ci.tests.execute.lifecycle.LCSbaseTest; +import org.openecomp.sdc.ci.tests.utils.DbUtils; +import org.openecomp.sdc.ci.tests.utils.Utils; +import org.openecomp.sdc.ci.tests.utils.general.AtomicOperationUtils; +import org.openecomp.sdc.ci.tests.utils.general.ElementFactory; +import org.openecomp.sdc.ci.tests.utils.rest.ArtifactRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ComponentInstanceRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.LifecycleRestUtils; +import org.openecomp.sdc.ci.tests.utils.rest.ResponseParser; +import org.openecomp.sdc.ci.tests.utils.rest.ServiceRestUtils; +import org.openecomp.sdc.ci.tests.utils.validation.ServiceValidationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class GovernorWorkspaceApiTest extends ComponentBaseTest { + + private static Logger logger = LoggerFactory.getLogger(GovernorWorkspaceApiTest.class.getName()); + @Rule + public static TestName name = new TestName(); + + public GovernorWorkspaceApiTest() { + super(name, GovernorWorkspaceApiTest.class.getName()); + + } + + protected final User admin1 = ElementFactory.getDefaultUser(UserRoleEnum.ADMIN); + protected final User governor = ElementFactory.getDefaultUser(UserRoleEnum.GOVERNOR); + protected final User sdncDesignerDetails1 = ElementFactory.getDefaultUser(UserRoleEnum.DESIGNER); + protected ResourceReqDetails resourceDetails1; + protected ComponentInstanceReqDetails componentInstanceReqDetails; + protected ArtifactReqDetails heatArtifactDetails; + + protected final String serviceVersion = "0.1"; + protected final String servicesString = "services"; + protected final String userRemarks = "commentTest"; + + protected ServiceReqDetails serviceDetails11 = null; + protected ServiceReqDetails serviceDetails22 = null; + protected ServiceReqDetails serviceDetails33 = null; + + @BeforeMethod + public void initBeforeTest() throws Exception { + DbUtils.deleteFromEsDbByPattern("_all"); + Resource resourceObj = AtomicOperationUtils + .createResourceByType(ResourceTypeEnum.VFC, UserRoleEnum.DESIGNER, true).left().value(); + resourceDetails1 = new ResourceReqDetails(resourceObj); + heatArtifactDetails = ElementFactory.getDefaultDeploymentArtifactForType(ArtifactTypeEnum.HEAT.getType()); + createThreeServices(sdncDesignerDetails1); + } + + protected void createThreeServices(User user) throws Exception { + + String checkinComment = "good checkin"; + String checkinComentJson = "{\"userRemarks\": \"" + checkinComment + "\"}"; + + RestResponse addInformationalArtifactToResource = ArtifactRestUtils.addInformationalArtifactToResource( + heatArtifactDetails, sdncDesignerDetails1, resourceDetails1.getUniqueId()); + RestResponse certifyResource = LifecycleRestUtils.certifyResource(resourceDetails1); + componentInstanceReqDetails = ElementFactory.getDefaultComponentInstance("defaultInstance", resourceDetails1); + + serviceDetails11 = ElementFactory.getDefaultService(); + serviceDetails22 = ElementFactory.getDefaultService(); + serviceDetails33 = ElementFactory.getDefaultService(); + + serviceDetails11.setName(serviceDetails11.getName() + "1"); + List<String> tags = serviceDetails11.getTags(); + tags.add(serviceDetails11.getName()); + serviceDetails11.setTags(tags); + + serviceDetails22.setName(serviceDetails11.getName() + "2"); + tags = serviceDetails22.getTags(); + tags.add(serviceDetails22.getName()); + serviceDetails22.setTags(tags); + + serviceDetails33.setName(serviceDetails11.getName() + "3"); + tags = serviceDetails33.getTags(); + tags.add(serviceDetails33.getName()); + serviceDetails33.setTags(tags); + + RestResponse createServiceResponse1 = createService(user, serviceDetails11); + RestResponse createServiceResponse2 = createService(user, serviceDetails22); + RestResponse createServiceResponse3 = createService(user, serviceDetails33); + } + + protected RestResponse createService(User user, ServiceReqDetails serviceDetails) throws Exception, IOException { + RestResponse createServiceResponse1 = ServiceRestUtils.createService(serviceDetails, user); + assertNotNull("check response object is not null after creating service", createServiceResponse1); + assertNotNull("check if error code exists in response after creating service", + createServiceResponse1.getErrorCode()); + assertEquals("Check response code after creating service", 201, + createServiceResponse1.getErrorCode().intValue()); + Service convertServiceResponseToJavaObject = ResponseParser + .convertServiceResponseToJavaObject(createServiceResponse1.getResponse()); + serviceDetails.setUniqueId(convertServiceResponseToJavaObject.getUniqueId()); + logger.debug("Created service1 ={}", serviceDetails); + addResourceWithHeatArt(serviceDetails); + return createServiceResponse1; + } + + protected void addResourceWithHeatArt(ServiceReqDetails serviceDetails) throws Exception { + + RestResponse createResourceInstance = ComponentInstanceRestUtils.createComponentInstance( + componentInstanceReqDetails, sdncDesignerDetails1, serviceDetails.getUniqueId(), + ComponentTypeEnum.SERVICE); + // System.out.println("serviceUID --->" + serviceDetails.getUniqueId()); + assertEquals("Check response code ", 201, createResourceInstance.getErrorCode().intValue()); + } + + protected void certifyAllServices() throws Exception { + LifecycleRestUtils.certifyService(serviceDetails11); + LifecycleRestUtils.certifyService(serviceDetails22); + LifecycleRestUtils.certifyService(serviceDetails33); + } + + protected boolean isElementInArray(String elementId, JSONArray jsonArray) throws Exception { + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jobject = (JSONObject) jsonArray.get(i); + + if (jobject.get("uniqueId").toString().equals(elementId)) { + return true; + } + } + return false; + } + + protected void approveDistributionStatusOfCertifiedService(ServiceReqDetails serviceDetails, User user) + throws Exception { + approveDistributionStatusOfService(serviceDetails, user, "1.0"); + } + + protected void approveDistributionStatusOfService(ServiceReqDetails serviceDetails, User user, String version) + throws Exception { + RestResponse res = LifecycleRestUtils.sendApproveDistribution(user, serviceDetails.getUniqueId(), userRemarks); + assertEquals(200, res.getErrorCode().intValue()); + ServiceValidationUtils.validateDistrubtionStatusValue(res, DistributionStatusEnum.DISTRIBUTION_APPROVED); + } + + protected void rejectDistributionStatusOfService(ServiceReqDetails serviceDetails, User user) throws Exception { + rejectDistributionStatusOfService(serviceDetails, user, "1.0"); + } + + protected void rejectDistributionStatusOfService(ServiceReqDetails serviceDetails, User user, String version) + throws Exception { + RestResponse res = LifecycleRestUtils.rejectDistribution(serviceDetails, version, user, userRemarks); + assertEquals(200, res.getErrorCode().intValue()); + ServiceValidationUtils.validateDistrubtionStatusValue(res, DistributionStatusEnum.DISTRIBUTION_REJECTED); + } + + protected JSONArray getFollowedListAsJsonArray(User user) throws Exception { + RestResponse getGovernorFollowed = ServiceRestUtils.getFollowed(user); + assertNotNull(getGovernorFollowed); + assertNotNull(getGovernorFollowed.getErrorCode()); + assertEquals(200, getGovernorFollowed.getErrorCode().intValue()); + + JSONArray listArrayFromRestResponse = ServiceRestUtils.getListArrayFromRestResponse(getGovernorFollowed); + + return listArrayFromRestResponse; + } + + protected void changeDistributionStatusOfAllService(boolean approved, User user) throws Exception { + if (approved) { + approveDistributionStatusOfCertifiedService(serviceDetails11, user); + approveDistributionStatusOfCertifiedService(serviceDetails22, user); + approveDistributionStatusOfCertifiedService(serviceDetails33, user); + } else { + rejectDistributionStatusOfService(serviceDetails11, user); + rejectDistributionStatusOfService(serviceDetails22, user); + rejectDistributionStatusOfService(serviceDetails33, user); + } + + } + + protected JSONArray checkFollowed(User user) throws Exception { + JSONArray getFollowedList = getFollowedListAsJsonArray(user); + assertFalse(getFollowedList.isEmpty()); + assertTrue(isElementInArray(serviceDetails11.getUniqueId(), getFollowedList)); + assertTrue(isElementInArray(serviceDetails22.getUniqueId(), getFollowedList)); + assertTrue(isElementInArray(serviceDetails33.getUniqueId(), getFollowedList)); + + return getFollowedList; + } + + // -------------------------------------T E S T + // S------------------------------------------------------// + + @Test + public void governorList_AllCertifiedVersionsOfService() throws Exception { + certifyAllServices(); + String serviceUniqueIdCertified1 = serviceDetails11.getUniqueId(); + RestResponse res = LifecycleRestUtils.changeServiceState(serviceDetails11, sdncDesignerDetails1, "1.0", + LifeCycleStatesEnum.CHECKOUT); + assertEquals(200, res.getErrorCode().intValue()); + + JSONArray getFollowedList = getFollowedListAsJsonArray(governor); + assertFalse(getFollowedList.isEmpty()); + assertFalse(isElementInArray(serviceDetails11.getUniqueId(), getFollowedList)); + assertTrue(isElementInArray(serviceDetails22.getUniqueId(), getFollowedList)); + assertTrue(isElementInArray(serviceDetails33.getUniqueId(), getFollowedList)); + assertTrue(isElementInArray(serviceUniqueIdCertified1, getFollowedList)); + assertEquals(3, getFollowedList.size()); + + // certifyService(serviceDetails11, "1.1"); + LifecycleRestUtils.certifyService(serviceDetails11); + + JSONArray governorFollowedList2 = checkFollowed(governor); + assertEquals(4, governorFollowedList2.size()); + assertTrue(isElementInArray(serviceDetails11.getUniqueId(), governorFollowedList2)); + assertTrue(isElementInArray(serviceUniqueIdCertified1, governorFollowedList2)); + + } + + // -------------------------------------T E S T + // S------------------------------------------------------// + + @Test + public void governorList_distributionNotApproved() throws Exception { + certifyAllServices(); + + JSONArray checkFollowed = checkFollowed(governor); + assertEquals(3, checkFollowed.size()); + } + + @Test + public void governorGetEmptyListTest_notCertifiedServices() throws Exception { + JSONArray governorFollowedList = getFollowedListAsJsonArray(governor); + + assertTrue(governorFollowedList.isEmpty()); + } + + @Test + public void governorList_distributionApproved() throws Exception { + certifyAllServices(); + boolean approved = true; + changeDistributionStatusOfAllService(approved, governor); + + JSONArray checkFollowed = checkFollowed(governor); + assertEquals(3, checkFollowed.size()); + } + + @Test(enabled = false) + public void governorList_distributed() throws Exception { + certifyAllServices(); + + LifecycleRestUtils.changeDistributionStatus(serviceDetails11, "1.0", governor, userRemarks, + DistributionStatusEnum.DISTRIBUTED); + LifecycleRestUtils.changeDistributionStatus(serviceDetails22, "1.0", governor, userRemarks, + DistributionStatusEnum.DISTRIBUTED); + LifecycleRestUtils.changeDistributionStatus(serviceDetails33, "1.0", governor, userRemarks, + DistributionStatusEnum.DISTRIBUTED); + + JSONArray governorFollowedList = getFollowedListAsJsonArray(governor); + assertFalse(governorFollowedList.isEmpty()); + assertTrue(isElementInArray(serviceDetails11.getUniqueId(), governorFollowedList)); + assertTrue(isElementInArray(serviceDetails22.getUniqueId(), governorFollowedList)); + assertTrue(isElementInArray(serviceDetails33.getUniqueId(), governorFollowedList)); + } + + @Test + public void governorList_distributionRejected() throws Exception { + certifyAllServices(); + boolean distributionRejected = false; + changeDistributionStatusOfAllService(distributionRejected, governor); + + JSONArray checkFollowed = checkFollowed(governor); + assertEquals(3, checkFollowed.size()); + } + +} |