QuotaRatioToElasticSearchJson { public String convertToJson(QuotaUsageUpdatedEvent event) throws JsonProcessingException { return mapper.writeValueAsString(QuotaRatioAsJson.builder() .user(event.getUsername().asString()) .domain(event.getQuotaRoot().getDomain().map(Domain::asString)) .quotaRatio(QuotaRatio.from(event.getSizeQuota(), event.getCountQuota())) .build()); } @Inject  QuotaRatioToElasticSearchJson(); String convertToJson(QuotaUsageUpdatedEvent event);  }
@Test void quotaRatioShouldBeWellConvertedToJson() throws IOException { String user = "user@domain.org"; QuotaUsageUpdatedEvent event = EventFactory.quotaUpdated() .eventId(EVENT_ID) .user(Username.of(user)) .quotaRoot(QuotaRoot.quotaRoot(user, Optional.of(Domain.of("domain.org")))) .quotaCount(QuotaFixture.Counts._52_PERCENT) .quotaSize(QuotaFixture.Sizes._55_PERCENT) .instant(Instant.now()) .build(); QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson(); String convertToJson = quotaRatioToElasticSearchJson.convertToJson(event); assertThatJson(convertToJson) .when(IGNORING_ARRAY_ORDER) .isEqualTo(ClassLoaderUtils.getSystemResourceAsString("quotaRatio.json")); }
@Test void quotaRatioShouldBeWellConvertedToJsonWhenNoDomain() throws IOException { String user = "user"; QuotaUsageUpdatedEvent event = EventFactory.quotaUpdated() .eventId(EVENT_ID) .user(Username.of(user)) .quotaRoot(QuotaRoot.quotaRoot(user, Optional.empty())) .quotaCount(QuotaFixture.Counts._52_PERCENT) .quotaSize(QuotaFixture.Sizes._55_PERCENT) .instant(Instant.now()) .build(); QuotaRatioToElasticSearchJson quotaRatioToElasticSearchJson = new QuotaRatioToElasticSearchJson(); String convertToJson = quotaRatioToElasticSearchJson.convertToJson(event); assertThatJson(convertToJson) .when(IGNORING_ARRAY_ORDER) .isEqualTo(ClassLoaderUtils.getSystemResourceAsString("quotaRatioNoDomain.json")); }