Search in sources :

Example 6 with CreateAccountRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.

the class AccountsApiTest method createWithCredentialsAccountExists.

@Test
void createWithCredentialsAccountExists() {
    final CreateAccountRequestDTO accountRequest = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("email@server.com").build()).domain("main").build();
    final CreateCredentialsRequestDTO credentialsRequest = CreateCredentialsRequestDTO.builder().plainPassword("password").addIdentifiers(UserIdentifierDTO.builder().identifier("username").type(UserIdentifier.Type.USERNAME).build()).build();
    final CreateCompleteAccountRequestDTO completeRequest = CreateCompleteAccountRequestDTO.builder().account(accountRequest).credentials(credentialsRequest).build();
    final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(UUID.randomUUID().toString()).build();
    final AccountBO accountBO = mapper().toBO(accountRequest);
    final AccountBO accountResponse = accountBO.withId(UUID.randomUUID().toString());
    final CredentialsBO credentialsBO = mapper().toBO(credentialsRequest).withAccountId(accountResponse.getId());
    final CredentialsBO credentialsResponse = credentialsBO.withId(UUID.randomUUID().toString());
    Mockito.when(accountsService.create(Mockito.eq(accountBO), Mockito.any())).thenThrow(new CompletionException(new IdempotencyException(IdempotentRecordBO.builder().entityId(accountResponse.getId()).build())));
    Mockito.when(credentialsService.create(Mockito.eq(credentialsBO), Mockito.any())).thenReturn(credentialsResponse);
    LOG.info("Request {}", accountRequest);
    final ValidatableResponse httpResponse = given().body(completeRequest).contentType(ContentType.JSON).header(IdempotencyHeader.HEADER_NAME, requestContext.getIdempotentKey()).post(url("complete")).then().statusCode(201).contentType(ContentType.JSON);
    final CreateCompleteAccountResponseDTO response = httpResponse.extract().response().getBody().as(CreateCompleteAccountResponseDTO.class);
    assertThat(response.getAccountId()).isEqualTo(accountResponse.getId());
    assertThat(response.getCredentialsId()).isEqualTo(credentialsResponse.getId());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) CredentialsBO(com.nexblocks.authguard.service.model.CredentialsBO) ValidatableResponse(io.restassured.response.ValidatableResponse) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) CreateAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO) CompletionException(java.util.concurrent.CompletionException) IdempotencyException(com.nexblocks.authguard.service.exceptions.IdempotencyException) CreateCompleteAccountResponseDTO(com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountResponseDTO) CreateCompleteAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO) Test(org.junit.jupiter.api.Test)

Example 7 with CreateAccountRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.

the class AccountsApiTest method createWithCredentialsAllExist.

@Test
void createWithCredentialsAllExist() {
    final CreateAccountRequestDTO accountRequest = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("email@server.com").build()).domain("main").build();
    final CreateCredentialsRequestDTO credentialsRequest = CreateCredentialsRequestDTO.builder().plainPassword("password").addIdentifiers(UserIdentifierDTO.builder().identifier("username").type(UserIdentifier.Type.USERNAME).build()).build();
    final CreateCompleteAccountRequestDTO completeRequest = CreateCompleteAccountRequestDTO.builder().account(accountRequest).credentials(credentialsRequest).build();
    final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(UUID.randomUUID().toString()).build();
    final AccountBO accountBO = mapper().toBO(accountRequest);
    final AccountBO accountResponse = accountBO.withId(UUID.randomUUID().toString());
    final CredentialsBO credentialsBO = mapper().toBO(credentialsRequest).withAccountId(accountResponse.getId());
    final CredentialsBO credentialsResponse = credentialsBO.withId(UUID.randomUUID().toString());
    Mockito.when(accountsService.create(Mockito.eq(accountBO), Mockito.any())).thenThrow(new CompletionException(new IdempotencyException(IdempotentRecordBO.builder().entityId(accountResponse.getId()).build())));
    Mockito.when(credentialsService.create(Mockito.eq(credentialsBO), Mockito.any())).thenThrow(new CompletionException(new IdempotencyException(IdempotentRecordBO.builder().entityId(credentialsResponse.getId()).build())));
    LOG.info("Request {}", accountRequest);
    final ValidatableResponse httpResponse = given().body(completeRequest).contentType(ContentType.JSON).header(IdempotencyHeader.HEADER_NAME, requestContext.getIdempotentKey()).post(url("complete")).then().statusCode(201).contentType(ContentType.JSON);
    final CreateCompleteAccountResponseDTO response = httpResponse.extract().response().getBody().as(CreateCompleteAccountResponseDTO.class);
    assertThat(response.getAccountId()).isEqualTo(accountResponse.getId());
    assertThat(response.getCredentialsId()).isEqualTo(credentialsResponse.getId());
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) CredentialsBO(com.nexblocks.authguard.service.model.CredentialsBO) ValidatableResponse(io.restassured.response.ValidatableResponse) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) CreateAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO) CompletionException(java.util.concurrent.CompletionException) IdempotencyException(com.nexblocks.authguard.service.exceptions.IdempotencyException) CreateCompleteAccountResponseDTO(com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountResponseDTO) CreateCompleteAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO) CreateCredentialsRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO) Test(org.junit.jupiter.api.Test)

Example 8 with CreateAccountRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.

the class RestMapperTest method createAccountRequestToAccountBO.

@Test
void createAccountRequestToAccountBO() {
    final CreateAccountRequestDTO requestDTO = easyRandom.nextObject(CreateAccountRequestDTO.class);
    final AccountDTO accountDTO = AccountDTO.builder().externalId(requestDTO.getExternalId()).firstName(requestDTO.getFirstName()).lastName(requestDTO.getLastName()).middleName(requestDTO.getMiddleName()).fullName(requestDTO.getFullName()).email(requestDTO.getEmail()).backupEmail(requestDTO.getBackupEmail()).phoneNumber(requestDTO.getPhoneNumber()).permissions(requestDTO.getPermissions()).roles(requestDTO.getRoles()).active(requestDTO.isActive()).metadata(requestDTO.getMetadata()).domain(requestDTO.getDomain()).build();
    // verified in another test case
    final AccountBO expected = restMapper.toBO(accountDTO);
    final AccountBO actual = restMapper.toBO(requestDTO);
    assertThat(actual).isEqualTo(expected);
}
Also used : CreateAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO) Test(org.junit.jupiter.api.Test)

Example 9 with CreateAccountRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.

the class CreateAccountRequestValidatorTest method validateInvalidEmail.

@Test
void validateInvalidEmail() {
    final CreateAccountRequestDTO request = CreateAccountRequestDTO.builder().externalId("external").email(AccountEmailDTO.builder().email("invalid").build()).domain("main").build();
    final Validator<CreateAccountRequestDTO> validator = Validators.getForClass(CreateAccountRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).contains(new Violation("email", ViolationType.INVALID_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CreateAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO) Test(org.junit.jupiter.api.Test)

Example 10 with CreateAccountRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO in project AuthGuard by AuthGuard.

the class CreateAccountRequestValidatorTest method validateNoDomain.

@Test
void validateNoDomain() {
    final CreateAccountRequestDTO request = CreateAccountRequestDTO.builder().build();
    final Validator<CreateAccountRequestDTO> validator = Validators.getForClass(CreateAccountRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).contains(new Violation("domain", ViolationType.MISSING_REQUIRED_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CreateAccountRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO) Test(org.junit.jupiter.api.Test)

Aggregations

CreateAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAccountRequestDTO)11 Test (org.junit.jupiter.api.Test)11 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)6 AccountBO (com.nexblocks.authguard.service.model.AccountBO)4 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)4 ValidatableResponse (io.restassured.response.ValidatableResponse)4 CreateCompleteAccountRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountRequestDTO)3 CreateCompleteAccountResponseDTO (com.nexblocks.authguard.api.dto.requests.CreateCompleteAccountResponseDTO)3 CreateCredentialsRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateCredentialsRequestDTO)3 CredentialsBO (com.nexblocks.authguard.service.model.CredentialsBO)3 IdempotencyException (com.nexblocks.authguard.service.exceptions.IdempotencyException)2 CompletionException (java.util.concurrent.CompletionException)2 AccountDTO (com.nexblocks.authguard.api.dto.entities.AccountDTO)1