Search in sources :

Example 1 with ExchangeAttemptsQueryBO

use of com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO in project AuthGuard by AuthGuard.

the class AuthRoute method getExchangeAttempts.

@Override
public void getExchangeAttempts(final Context context) {
    final String entityId = context.queryParam("entityId");
    final OffsetDateTime fromTimestamp = parseOffsetDateTime(context.queryParam("fromTimestamp"));
    final String fromExchange = context.queryParam("fromExchange");
    // take care of checking the parameters
    if (entityId == null) {
        context.status(400).json(new Error(ErrorCode.MISSING_REQUEST_QUERY.getCode(), "Query parameter entityId is required"));
        return;
    }
    if (fromExchange != null && fromTimestamp == null) {
        context.status(400).json(new Error(ErrorCode.MISSING_REQUEST_QUERY.getCode(), "Query parameter fromTimestamp is required when fromExchange is set"));
        return;
    }
    // do the real work
    final ExchangeAttemptsQueryBO query = ExchangeAttemptsQueryBO.builder().entityId(entityId).fromTimestamp(fromTimestamp).fromExchange(fromExchange).build();
    final Collection<ExchangeAttemptDTO> attempts = exchangeAttemptsService.find(query).stream().map(restMapper::toDTO).collect(Collectors.toList());
    context.json(attempts);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Error(com.nexblocks.authguard.api.dto.entities.Error) ExchangeAttemptDTO(com.nexblocks.authguard.api.dto.entities.ExchangeAttemptDTO) ExchangeAttemptsQueryBO(com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO)

Example 2 with ExchangeAttemptsQueryBO

use of com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO in project AuthGuard by AuthGuard.

the class ExchangeAttemptsServiceImplTest method findByEntityIdAndFromTimestampAndExchange.

@Test
void findByEntityIdAndFromTimestampAndExchange() {
    final OffsetDateTime now = OffsetDateTime.now();
    final ExchangeAttemptsQueryBO query = ExchangeAttemptsQueryBO.builder().entityId("account").fromTimestamp(now).fromExchange("basic").build();
    Mockito.when(repository.findByEntityAndTimestampAndExchange("account", now, "basic")).thenReturn(CompletableFuture.completedFuture(Collections.singletonList(ExchangeAttemptDO.builder().entityId("account").exchangeFrom("basic").exchangeTo("session").build())));
    final Collection<ExchangeAttemptBO> actual = service.find(query);
    final Collection<ExchangeAttemptBO> expected = Collections.singletonList(ExchangeAttemptBO.builder().entityId("account").exchangeFrom("basic").exchangeTo("session").build());
    assertThat(actual).isEqualTo(expected);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) ExchangeAttemptBO(com.nexblocks.authguard.service.model.ExchangeAttemptBO) ExchangeAttemptsQueryBO(com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO) Test(org.junit.jupiter.api.Test)

Example 3 with ExchangeAttemptsQueryBO

use of com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO in project AuthGuard by AuthGuard.

the class ExchangeAttemptsServiceImplTest method findByEntityIdAndFromTimestamp.

@Test
void findByEntityIdAndFromTimestamp() {
    final OffsetDateTime now = OffsetDateTime.now();
    final ExchangeAttemptsQueryBO query = ExchangeAttemptsQueryBO.builder().entityId("account").fromTimestamp(now).build();
    Mockito.when(repository.findByEntityAndTimestamp("account", now)).thenReturn(CompletableFuture.completedFuture(Collections.singletonList(ExchangeAttemptDO.builder().entityId("account").exchangeFrom("basic").exchangeTo("session").build())));
    final Collection<ExchangeAttemptBO> actual = service.find(query);
    final Collection<ExchangeAttemptBO> expected = Collections.singletonList(ExchangeAttemptBO.builder().entityId("account").exchangeFrom("basic").exchangeTo("session").build());
    assertThat(actual).isEqualTo(expected);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) ExchangeAttemptBO(com.nexblocks.authguard.service.model.ExchangeAttemptBO) ExchangeAttemptsQueryBO(com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO) Test(org.junit.jupiter.api.Test)

Example 4 with ExchangeAttemptsQueryBO

use of com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO in project AuthGuard by AuthGuard.

the class ExchangeAttemptsServiceImplTest method findByEntityId.

@Test
void findByEntityId() {
    final ExchangeAttemptsQueryBO query = ExchangeAttemptsQueryBO.builder().entityId("account").build();
    Mockito.when(repository.findByEntity("account")).thenReturn(CompletableFuture.completedFuture(Collections.singletonList(ExchangeAttemptDO.builder().entityId("account").exchangeFrom("basic").exchangeTo("session").build())));
    final Collection<ExchangeAttemptBO> actual = service.find(query);
    final Collection<ExchangeAttemptBO> expected = Collections.singletonList(ExchangeAttemptBO.builder().entityId("account").exchangeFrom("basic").exchangeTo("session").build());
    assertThat(actual).isEqualTo(expected);
}
Also used : ExchangeAttemptBO(com.nexblocks.authguard.service.model.ExchangeAttemptBO) ExchangeAttemptsQueryBO(com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO) Test(org.junit.jupiter.api.Test)

Aggregations

ExchangeAttemptsQueryBO (com.nexblocks.authguard.service.model.ExchangeAttemptsQueryBO)4 ExchangeAttemptBO (com.nexblocks.authguard.service.model.ExchangeAttemptBO)3 OffsetDateTime (java.time.OffsetDateTime)3 Test (org.junit.jupiter.api.Test)3 Error (com.nexblocks.authguard.api.dto.entities.Error)1 ExchangeAttemptDTO (com.nexblocks.authguard.api.dto.entities.ExchangeAttemptDTO)1