Skip to content

Commit

Permalink
MCBFF-21: resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonAntonich committed Nov 26, 2024
1 parent 499e9a0 commit b073269
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.folio.circulationbff.domain.dto.AllowedServicePoints;
import org.folio.circulationbff.domain.dto.BffRequest;
import org.folio.circulationbff.domain.dto.BffSearchInstance;
import org.folio.circulationbff.domain.dto.EcsRequestExternal;
import org.folio.circulationbff.domain.dto.EcsTlr;
import org.folio.circulationbff.domain.dto.EmptyBffSearchInstance;
import org.folio.circulationbff.domain.dto.MediatedRequest;
import org.folio.circulationbff.domain.dto.PickSlipCollection;
Expand All @@ -18,6 +20,7 @@
import org.folio.circulationbff.domain.dto.UserCollection;
import org.folio.circulationbff.rest.resource.CirculationBffApi;
import org.folio.circulationbff.service.CirculationBffService;
import org.folio.circulationbff.service.EcsRequestExternalService;
import org.folio.circulationbff.service.MediatedRequestsService;
import org.folio.circulationbff.service.SearchService;
import org.folio.circulationbff.service.UserService;
Expand All @@ -37,6 +40,13 @@ public class CirculationBffController implements CirculationBffApi {
private final SearchService searchService;
private final MediatedRequestsService mediatedRequestsService;
private final UserService userService;
private final EcsRequestExternalService ecsRequestExternalService;

@Override
public ResponseEntity<EcsTlr> postEcsRequestExternal(EcsRequestExternal ecsRequestExternal) {
return ResponseEntity.status(HttpStatus.OK)
.body(ecsRequestExternalService.createEcsRequestExternal(ecsRequestExternal));
}

@Override
public ResponseEntity<PickSlipCollection> getPickSlips(String servicePointId) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.folio.circulationbff.service;

public interface SettingsService {
boolean isEcsTlrFeatureEnabled();
boolean isEcsTlrFeatureEnabled(String tenantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ public interface UserTenantsService {
String getCentralTenant();
boolean isCentralTenant();
boolean isCentralTenant(String tenantId);
String getCentralTenantId();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class EcsRequestExternalServiceImpl implements EcsRequestExternalService

@Override
public EcsTlr createEcsRequestExternal(EcsRequestExternal ecsRequestExternal) {
String centralTenantId = userTenantsService.getCentralTenantId();
String centralTenantId = userTenantsService.getCentralTenant();

return systemUserScopedExecutionService.executeSystemUserScoped(centralTenantId,
() -> ecsTlrClient.createEcsExternalRequest(ecsRequestExternal));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package org.folio.circulationbff.service;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;

import java.util.stream.Stream;

import org.folio.circulationbff.client.feign.CirculationClient;
import org.folio.circulationbff.client.feign.EcsTlrClient;
import org.folio.circulationbff.domain.dto.CirculationSettings;
import org.folio.circulationbff.domain.dto.CirculationSettingsResponse;
import org.folio.circulationbff.domain.dto.CirculationSettingsValue;
import org.folio.circulationbff.domain.dto.TlrSettings;
import org.folio.circulationbff.service.impl.SettingsServiceImpl;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.testcontainers.shaded.org.apache.commons.lang3.BooleanUtils;

@ExtendWith(MockitoExtension.class)
class SettingServiceTest {

@Mock
private EcsTlrClient ecsTlrClient;

@Mock
private CirculationClient circulationClient;

@Mock
private UserTenantsService userTenantsService;

@InjectMocks
private SettingsServiceImpl service;

@ParameterizedTest
@MethodSource("settingsToResponse")
void isEcsTlrSettingsEnabledTest(boolean isCentralTenant, TlrSettings tlrSettings,
CirculationSettingsResponse circulationSettingsResponse, boolean expectedValue) {

when(userTenantsService.isCentralTenant()).thenReturn(isCentralTenant);
mockByIsCentralTenantId(circulationSettingsResponse, tlrSettings, isCentralTenant);

assertThat(service.isEcsTlrFeatureEnabled(), equalTo(expectedValue));
}

private void mockByIsCentralTenantId(CirculationSettingsResponse circulationSettingsResponse,
TlrSettings tlrSettings, boolean isCentralTenant) {

if (BooleanUtils.isTrue(isCentralTenant)) {
when(ecsTlrClient.getTlrSettings()).thenReturn(tlrSettings);
} else {
when(circulationClient.getCirculationSettingsByQuery(anyString()))
.thenReturn(circulationSettingsResponse);
}
}

private static CirculationSettingsResponse buildCirculationSettingsResponse(
boolean isEcsTlrEnabled) {

CirculationSettingsResponse circulationSettingsResponse = new CirculationSettingsResponse();
CirculationSettings circulationSettings = new CirculationSettings();
CirculationSettingsValue value = new CirculationSettingsValue();
value.enabled(isEcsTlrEnabled);
circulationSettings.setValue(value);
circulationSettingsResponse.addCirculationSettingsItem(circulationSettings);
circulationSettingsResponse.setTotalRecords(1);
return circulationSettingsResponse;
}

private static TlrSettings buildTlrSettings(boolean isTlrEnabled) {
TlrSettings tlrSettings = new TlrSettings();
tlrSettings.setEcsTlrFeatureEnabled(isTlrEnabled);
return tlrSettings;
}

private static Stream<Arguments> settingsToResponse() {
return Stream.of(
Arguments.of(true, buildTlrSettings(true), null, true),
Arguments.of(true, buildTlrSettings(false), null, false),
Arguments.of(false, null, buildCirculationSettingsResponse(true),
true),
Arguments.of(false, null, buildCirculationSettingsResponse(false),
false)
);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.when;

Expand All @@ -12,7 +11,6 @@
import org.folio.circulationbff.client.feign.UserTenantsClient;
import org.folio.circulationbff.domain.dto.UserTenant;
import org.folio.circulationbff.domain.dto.UserTenantCollection;
import org.folio.circulationbff.exception.UserTenantException;
import org.folio.circulationbff.service.impl.UserTenantsServiceImpl;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -47,18 +45,9 @@ void getCentralTenantIdTest() {
when(userTenantsClient.getUserTenants(anyInt())).thenReturn(new UserTenantCollection()
.addUserTenantsItem(new UserTenant().centralTenantId(CENTRAL_TENANT_ID)));

assertThat(userTenantsService.getCentralTenantId(), equalTo(CENTRAL_TENANT_ID));
assertThat(userTenantsService.getCentralTenant(), equalTo(CENTRAL_TENANT_ID));
}

@Test
void getCentralTenantIdShouldThrowUserTenantExceptionTest() {
when(userTenantsClient.getUserTenants(anyInt())).thenReturn(new UserTenantCollection()
.addUserTenantsItem(null));

assertThrows(UserTenantException.class, () -> userTenantsService.getCentralTenantId());
}


private static Stream<Arguments> userTenantCollectionToExpectedValue() {
return Stream.of(
Arguments.of(buildCollection(TENANT_ID), false),
Expand Down

0 comments on commit b073269

Please sign in to comment.