Search in sources :

Example 1 with UsernameUpdateService

use of org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService in project identity-governance by wso2-extensions.

the class UpdateUsernameApiServiceImpl method updateUsernamePut.

/**
 * Username update service method.
 *
 * @param user UsernameUpdateRequestDTO{@link UsernameUpdateRequestDTO} including update request parameters
 * @return Response status. Returns 200 upon successful update
 */
@Override
public Response updateUsernamePut(UsernameUpdateRequestDTO user) {
    try {
        UserDTO userDTO = new UserDTO();
        userDTO.setExistingUsername(user.getExistingUsername());
        userDTO.setNewUsername(user.getNewUsername());
        userDTO.setUserStoreDomain(user.getRealm());
        userDTO.setTenantDomain(getTenantDomainFromContext());
        UsernameUpdateService usernameUpdateService = Utils.getUsernameUpdateService();
        usernameUpdateService.updateUsername(userDTO);
    } catch (UsernameUpdateClientException e) {
        handleClientError(e);
    } catch (UsernameUpdateException e) {
        handleServerError(e);
    } catch (Throwable e) {
        handleUnexpectedServerError(e);
    }
    return Response.ok().status(Response.Status.OK).build();
}
Also used : UsernameUpdateService(org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService) UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) UsernameUpdateClientException(org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateClientException) UsernameUpdateException(org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateException)

Example 2 with UsernameUpdateService

use of org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService in project identity-governance by wso2-extensions.

the class UpdateUsernameApiServiceImplTest method testNotAcceptableStatusOfUpdateUsername.

@Test
public void testNotAcceptableStatusOfUpdateUsername() throws Exception {
    mockedUtils.when(Utils::getUsernameUpdateService).thenReturn(usernameUpdateService);
    Mockito.when(usernameUpdateService.updateUsername(any(UserDTO.class))).thenThrow(new UsernameUpdateClientException(ERROR_MSG, ERROR_CODE, UsernameUpdateClientException.ErrorType.NOT_ACCEPTABLE));
    // The test method executes the lines but does not throw the 406 code.
    Assert.assertEquals(usernameApiService.updateUsernamePut(usernameUpdateRequestDTO).getStatus(), 200);
}
Also used : UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) UsernameUpdateClientException(org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateClientException) Test(org.testng.annotations.Test)

Example 3 with UsernameUpdateService

use of org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService in project identity-governance by wso2-extensions.

the class UpdateUsernameApiServiceImplTest method testServerErrorStatusOfUpdateUsername.

@Test
public void testServerErrorStatusOfUpdateUsername() throws Exception {
    mockedUtils.when(Utils::getUsernameUpdateService).thenReturn(usernameUpdateService);
    Mockito.when(usernameUpdateService.updateUsername(any(UserDTO.class))).thenThrow(new UsernameUpdateException(ERROR_MSG, ERROR_CODE));
    // The test method executes the lines but does not throw the 500 code.
    Assert.assertEquals(usernameApiService.updateUsernamePut(usernameUpdateRequestDTO).getStatus(), 200);
}
Also used : UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) UsernameUpdateException(org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateException) Test(org.testng.annotations.Test)

Example 4 with UsernameUpdateService

use of org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService in project identity-governance by wso2-extensions.

the class UpdateUsernameApiServiceImplTest method testBadRequestStatusOfUpdateUsername.

@Test
public void testBadRequestStatusOfUpdateUsername() throws Exception {
    mockedUtils.when(Utils::getUsernameUpdateService).thenReturn(usernameUpdateService);
    Mockito.when(usernameUpdateService.updateUsername(any(UserDTO.class))).thenThrow(new UsernameUpdateClientException(ERROR_MSG, ERROR_CODE, UsernameUpdateClientException.ErrorType.BAD_REQUEST));
    // The test method executes the lines but does not throw the 400 code.
    Assert.assertEquals(usernameApiService.updateUsernamePut(usernameUpdateRequestDTO).getStatus(), 200);
}
Also used : UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) UsernameUpdateClientException(org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateClientException) Test(org.testng.annotations.Test)

Example 5 with UsernameUpdateService

use of org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService in project identity-governance by wso2-extensions.

the class UpdateUsernameApiServiceImplTest method testNotFoundStatusOfUpdateUsername.

@Test
public void testNotFoundStatusOfUpdateUsername() throws Exception {
    mockedUtils.when(Utils::getUsernameUpdateService).thenReturn(usernameUpdateService);
    Mockito.when(usernameUpdateService.updateUsername(any(UserDTO.class))).thenThrow(new UsernameUpdateClientException(ERROR_MSG, ERROR_CODE, UsernameUpdateClientException.ErrorType.NOT_FOUND));
    // The test method executes the lines but does not throw the 404 code.
    Assert.assertEquals(usernameApiService.updateUsernamePut(usernameUpdateRequestDTO).getStatus(), 200);
}
Also used : UserDTO(org.wso2.carbon.identity.user.rename.core.dto.UserDTO) UsernameUpdateClientException(org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateClientException) Test(org.testng.annotations.Test)

Aggregations

UserDTO (org.wso2.carbon.identity.user.rename.core.dto.UserDTO)5 Test (org.testng.annotations.Test)4 UsernameUpdateClientException (org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateClientException)4 UsernameUpdateException (org.wso2.carbon.identity.user.rename.core.exception.UsernameUpdateException)2 UsernameUpdateService (org.wso2.carbon.identity.user.rename.core.service.UsernameUpdateService)1