From b72045462c4a1a34498a8b912c050989d6ab7693 Mon Sep 17 00:00:00 2001 From: Bobby Sharp Date: Wed, 26 Jun 2024 14:16:35 -0400 Subject: [PATCH] Add coverage --- .../fqm/repository/DataRefreshRepository.java | 31 +++++++++---------- .../fqm/resource/DataRefreshController.java | 1 - .../controller/DataRefreshControllerTest.java | 1 - .../fqm/service/DataRefreshServiceTest.java | 21 +++++++++++++ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/folio/fqm/repository/DataRefreshRepository.java b/src/main/java/org/folio/fqm/repository/DataRefreshRepository.java index be27d04f3..9ee9928d4 100644 --- a/src/main/java/org/folio/fqm/repository/DataRefreshRepository.java +++ b/src/main/java/org/folio/fqm/repository/DataRefreshRepository.java @@ -79,23 +79,14 @@ public class DataRefreshRepository { private final SimpleHttpClient simpleHttpClient; -// public DataRefreshResponse refreshData(String tenantId) { -// List failedConcurrentRefreshes = refreshMaterializedViews(tenantId, MATERIALIZED_VIEW_NAMES, true); -// List failedRefreshes = refreshMaterializedViews(tenantId, failedConcurrentRefreshes, false); -// List successRefreshes = new ArrayList<>(MATERIALIZED_VIEW_NAMES -// .stream() -// .filter(matView -> !failedRefreshes.contains(matView)) -// .toList()); -// if (refreshExchangeRates(tenantId)) { -// successRefreshes.add(EXCHANGE_RATE_TABLE); -// } else { -// failedRefreshes.add(EXCHANGE_RATE_TABLE); -// } -// return new DataRefreshResponse() -// .successfulRefresh(successRefreshes) -// .failedRefresh(failedRefreshes); -// } - + /** + * Refresh a list of materialized views + * + * @param tenantId Tenant ID + * @param viewsToRefresh List of materialized views to refresh + * @param refreshConcurrently Whether to execute a concurrent refresh + * @return List of all materialized views that failed to refresh + */ public List refreshMaterializedViews(String tenantId, List viewsToRefresh, boolean refreshConcurrently) { List failedRefreshes = new ArrayList<>(); String refreshType = refreshConcurrently ? "concurrently" : "non-concurrently"; @@ -116,6 +107,12 @@ public List refreshMaterializedViews(String tenantId, List views return failedRefreshes; } + /** + * Refresh the currency exchange rates for a tenant, based on the tenant's default system currency. + * + * @param tenantId Tenant ID + * @return True if refresh successful, false otherwise + */ public boolean refreshExchangeRates(String tenantId) { log.info("Refreshing exchange rates"); String fullTableName = tenantId + "_mod_fqm_manager." + EXCHANGE_RATE_TABLE; diff --git a/src/main/java/org/folio/fqm/resource/DataRefreshController.java b/src/main/java/org/folio/fqm/resource/DataRefreshController.java index 190ee47de..c0d995778 100644 --- a/src/main/java/org/folio/fqm/resource/DataRefreshController.java +++ b/src/main/java/org/folio/fqm/resource/DataRefreshController.java @@ -4,7 +4,6 @@ import org.folio.fqm.domain.dto.DataRefreshResponse; import org.folio.fqm.service.DataRefreshService; import org.folio.spring.FolioExecutionContext; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RestController; diff --git a/src/test/java/org/folio/fqm/controller/DataRefreshControllerTest.java b/src/test/java/org/folio/fqm/controller/DataRefreshControllerTest.java index ec40b2fa0..0dbf7379f 100644 --- a/src/test/java/org/folio/fqm/controller/DataRefreshControllerTest.java +++ b/src/test/java/org/folio/fqm/controller/DataRefreshControllerTest.java @@ -15,7 +15,6 @@ import java.util.List; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; diff --git a/src/test/java/org/folio/fqm/service/DataRefreshServiceTest.java b/src/test/java/org/folio/fqm/service/DataRefreshServiceTest.java index afab251c8..6a6a9afe5 100644 --- a/src/test/java/org/folio/fqm/service/DataRefreshServiceTest.java +++ b/src/test/java/org/folio/fqm/service/DataRefreshServiceTest.java @@ -54,4 +54,25 @@ void shouldRetryRefreshIfConcurrentRefreshFails() { verify(dataRefreshRepository, times(1)).refreshMaterializedViews(tenantId, List.of("drv_languages"), false); assertEquals(expectedDataRefreshResponse, actualDataRefreshResponse); } + + @Test + void shouldReturnFailedRefreshes() { + String tenantId = "tenant_01"; + List expectedSuccessRefreshes = MATERIALIZED_VIEW_NAMES + .stream() + .filter(view -> !view.equals("drv_languages")) + .toList(); + List expectedFailedRefreshes = List.of("drv_languages", "currency_exchange_rates"); + DataRefreshResponse expectedDataRefreshResponse = new DataRefreshResponse() + .successfulRefresh(expectedSuccessRefreshes) + .failedRefresh(expectedFailedRefreshes); + when(dataRefreshRepository.refreshMaterializedViews(tenantId, MATERIALIZED_VIEW_NAMES, true)) + .thenReturn(new ArrayList<>(List.of("drv_languages"))); + when(dataRefreshRepository.refreshMaterializedViews(tenantId, List.of("drv_languages"), false)) + .thenReturn(new ArrayList<>(List.of("drv_languages"))); + when(dataRefreshRepository.refreshExchangeRates(tenantId)).thenReturn(false); + DataRefreshResponse actualDataRefreshResponse = dataRefreshService.refreshData(tenantId); + verify(dataRefreshRepository, times(1)).refreshMaterializedViews(tenantId, List.of("drv_languages"), false); + assertEquals(expectedDataRefreshResponse, actualDataRefreshResponse); + } }