Search in sources :

Example 1 with UserSyncStatusResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse in project cloudbreak by hortonworks.

the class UserSyncStatusToUserSyncStatusResponseConverterTest method convertJsonException.

@Test
void convertJsonException() throws IOException {
    Json eventGenerationIds = mock(Json.class);
    IOException e = new IOException("test exception");
    when(eventGenerationIds.get(any(Class.class))).thenThrow(e);
    UserSyncStatus status = new UserSyncStatus();
    status.setStack(mock(Stack.class));
    status.setUmsEventGenerationIds(eventGenerationIds);
    UserSyncStatusResponse response = underTest.convert(status);
    assertThat(response).returns(null, UserSyncStatusResponse::getLastStartedUserSyncId).returns(null, UserSyncStatusResponse::getLastSuccessfulUserSyncId).returns(null, UserSyncStatusResponse::getEventGenerationIds);
}
Also used : UserSyncStatusResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 2 with UserSyncStatusResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse in project cloudbreak by hortonworks.

the class UserSyncStatusToUserSyncStatusResponseConverterTest method convert.

@Test
void convert() {
    String requestedId = UUID.randomUUID().toString();
    Operation requested = new Operation();
    requested.setOperationId(requestedId);
    String successfulId = UUID.randomUUID().toString();
    Operation successful = new Operation();
    successful.setOperationId(successfulId);
    Map<String, String> eventGenerationIdMap = Map.of("key1", "value1", "key2", "value2");
    UmsEventGenerationIds eventGenerationIds = new UmsEventGenerationIds();
    eventGenerationIds.setEventGenerationIds(eventGenerationIdMap);
    UserSyncStatus status = new UserSyncStatus();
    status.setLastStartedFullSync(requested);
    status.setLastSuccessfulFullSync(successful);
    status.setUmsEventGenerationIds(new Json(eventGenerationIds));
    UserSyncStatusResponse response = underTest.convert(status);
    assertThat(response).returns(requestedId, UserSyncStatusResponse::getLastStartedUserSyncId).returns(successfulId, UserSyncStatusResponse::getLastSuccessfulUserSyncId).returns(eventGenerationIdMap, UserSyncStatusResponse::getEventGenerationIds);
}
Also used : UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) UserSyncStatusResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test)

Example 3 with UserSyncStatusResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse in project cloudbreak by hortonworks.

the class UserSyncStatusToUserSyncStatusResponseConverter method convert.

@Override
public UserSyncStatusResponse convert(UserSyncStatus userSyncStatus) {
    UserSyncStatusResponse response = new UserSyncStatusResponse();
    Optional.ofNullable(userSyncStatus.getLastStartedFullSync()).ifPresent(op -> response.setLastStartedUserSyncId(op.getOperationId()));
    Optional.ofNullable(userSyncStatus.getLastSuccessfulFullSync()).ifPresent(op -> response.setLastSuccessfulUserSyncId(op.getOperationId()));
    Optional.ofNullable(userSyncStatus.getUmsEventGenerationIds()).ifPresent(eids -> {
        try {
            response.setEventGenerationIds(eids.get(UmsEventGenerationIds.class).getEventGenerationIds());
        } catch (IOException e) {
            LOGGER.warn("Failed to convert event generation ids [{}] for environment '{}'", userSyncStatus.getUmsEventGenerationIds(), userSyncStatus.getStack().getEnvironmentCrn());
        }
    });
    return response;
}
Also used : UserSyncStatusResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse) IOException(java.io.IOException)

Aggregations

UserSyncStatusResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse)3 Json (com.sequenceiq.cloudbreak.common.json.Json)2 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)2 IOException (java.io.IOException)2 Test (org.junit.jupiter.api.Test)2 Operation (com.sequenceiq.freeipa.entity.Operation)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)1