Skip to content

Commit

Permalink
Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bvsharp committed Jun 26, 2024
1 parent 07b6a16 commit b720454
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
31 changes: 14 additions & 17 deletions src/main/java/org/folio/fqm/repository/DataRefreshRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,14 @@ public class DataRefreshRepository {

private final SimpleHttpClient simpleHttpClient;

// public DataRefreshResponse refreshData(String tenantId) {
// List<String> failedConcurrentRefreshes = refreshMaterializedViews(tenantId, MATERIALIZED_VIEW_NAMES, true);
// List<String> failedRefreshes = refreshMaterializedViews(tenantId, failedConcurrentRefreshes, false);
// List<String> 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<String> refreshMaterializedViews(String tenantId, List<String> viewsToRefresh, boolean refreshConcurrently) {
List<String> failedRefreshes = new ArrayList<>();
String refreshType = refreshConcurrently ? "concurrently" : "non-concurrently";
Expand All @@ -116,6 +107,12 @@ public List<String> refreshMaterializedViews(String tenantId, List<String> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/org/folio/fqm/service/DataRefreshServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> expectedSuccessRefreshes = MATERIALIZED_VIEW_NAMES
.stream()
.filter(view -> !view.equals("drv_languages"))
.toList();
List<String> 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);
}
}

0 comments on commit b720454

Please sign in to comment.