@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); }
@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; }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @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; } }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @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; }  }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @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; }  @Override UserSyncStatusResponse convert(UserSyncStatus userSyncStatus); }
UserSyncStatusToUserSyncStatusResponseConverter implements Converter<UserSyncStatus, UserSyncStatusResponse> { @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; }  @Override UserSyncStatusResponse convert(UserSyncStatus userSyncStatus);  }