修复海外报价合作仓候选缓存刷新
This commit is contained in:
+3
@@ -13,6 +13,9 @@ class OverseasMasterDataOpenApiContractTest {
|
||||
String yaml = Files.readString(Path.of("src/main/resources/openapi/overseas-master-data-v1.yaml"));
|
||||
assertThat(yaml).contains("/api/platform/v1/last-leg/master-data/overseas-quotes:")
|
||||
.contains("缓存合作仓目录30分钟")
|
||||
.contains("空结果不缓存")
|
||||
.contains("refresh=true强制刷新")
|
||||
.contains("PartnerWarehouseOption:")
|
||||
.contains("/api/platform/v1/last-leg/master-data/exchange-rates:")
|
||||
.contains("/api/platform/v1/last-leg/master-data/vehicles:")
|
||||
.contains("platform:overseas-master-data:exchange-rate:export")
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package com.baiyue.lastleg.masterdata.quote.client;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class DomesticPartnerWarehouseClientContractTest {
|
||||
@Test
|
||||
void freezesCnInternalUrlTokenHeaderAndFourFieldDto() throws Exception {
|
||||
FeignClient feign = DomesticPartnerWarehouseClient.class.getAnnotation(FeignClient.class);
|
||||
assertThat(feign.name()).isEqualTo("warehouse-service");
|
||||
assertThat(feign.url()).isEqualTo("${baiyue.clients.domestic-warehouse.url:}");
|
||||
|
||||
Method method = DomesticPartnerWarehouseClient.class.getDeclaredMethod("activePartners", String.class);
|
||||
assertThat(method.getAnnotation(GetMapping.class).value())
|
||||
.containsExactly("/internal/warehouses/overseas-partners");
|
||||
assertThat(method.getParameters()[0].getAnnotation(RequestHeader.class).value())
|
||||
.isEqualTo("X-Internal-Service-Token");
|
||||
assertThat(Arrays.stream(DomesticPartnerWarehouseClient.Option.class.getRecordComponents())
|
||||
.map(component -> component.getName() + ":" + component.getType().getSimpleName()))
|
||||
.containsExactly("id:Long", "warehouseCode:String", "warehouseName:String", "countryCode:String");
|
||||
}
|
||||
|
||||
@Test
|
||||
void developmentDeploymentRequiresAndPassesTheCnUrlAndSharedInternalToken() throws Exception {
|
||||
String application = Files.readString(Path.of("src/main/resources/application.yml"));
|
||||
String nacos = Files.readString(Path.of("../config/nacos/overseas/lastleg-service.yml"));
|
||||
String common = Files.readString(Path.of("../config/nacos/overseas/baiyue-common.yml"));
|
||||
String compose = Files.readString(Path.of("../deploy/docker-compose.overseas.yml"));
|
||||
String deploy = Files.readString(Path.of("../deploy/scripts/deploy-services.sh"));
|
||||
|
||||
assertThat(application).contains("url: ${DOMESTIC_WAREHOUSE_URL:}")
|
||||
.contains("cache-ttl: ${DOMESTIC_WAREHOUSE_CACHE_TTL:30m}");
|
||||
assertThat(nacos).contains("url: ${DOMESTIC_WAREHOUSE_URL}")
|
||||
.contains("cache-ttl: ${DOMESTIC_WAREHOUSE_CACHE_TTL:30m}");
|
||||
assertThat(common).contains("internal-service-token: ${INTERNAL_SERVICE_TOKEN}");
|
||||
assertThat(compose).contains("INTERNAL_SERVICE_TOKEN: ${INTERNAL_SERVICE_TOKEN}")
|
||||
.contains("DOMESTIC_WAREHOUSE_URL: ${DOMESTIC_WAREHOUSE_URL}");
|
||||
assertThat(deploy).contains("FIRSTLEG_EVENT_BRIDGE_URL DOMESTIC_WAREHOUSE_URL")
|
||||
.contains("NACOS_SERVER_ADDR OVERSEAS_NACOS_NAMESPACE INTERNAL_SERVICE_TOKEN");
|
||||
}
|
||||
}
|
||||
+10
@@ -3,7 +3,9 @@ package com.baiyue.lastleg.masterdata.quote.controller;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -26,5 +28,13 @@ class PlatformOverseasQuoteControllerContractTest {
|
||||
assertThat(authorities.get("update")).contains("platform:overseas-master-data:quote:edit");
|
||||
assertThat(authorities.get("status")).contains("platform:overseas-master-data:quote:status");
|
||||
assertThat(authorities.get("export")).contains("platform:overseas-master-data:quote:export");
|
||||
|
||||
Method options = Stream.of(PlatformOverseasQuoteController.class.getDeclaredMethods())
|
||||
.filter(method -> method.getName().equals("warehouseOptions"))
|
||||
.findFirst().orElseThrow();
|
||||
RequestParam refresh = options.getParameters()[0].getAnnotation(RequestParam.class);
|
||||
assertThat(options.getParameterTypes()).containsExactly(boolean.class);
|
||||
assertThat(refresh).isNotNull();
|
||||
assertThat(refresh.defaultValue()).isEqualTo("false");
|
||||
}
|
||||
}
|
||||
|
||||
+31
@@ -66,4 +66,35 @@ class PartnerWarehouseDirectoryTest {
|
||||
assertThat(option.warehouseId()).isEqualTo("101"));
|
||||
verify(client, times(2)).activePartners("internal-token");
|
||||
}
|
||||
|
||||
@Test
|
||||
void forcedRefreshBypassesAStillValidPositiveSnapshot() {
|
||||
when(client.activePartners("internal-token"))
|
||||
.thenReturn(ApiResponse.success(List.of(new DomesticPartnerWarehouseClient.Option(
|
||||
101L, "US-ONT", "安大略合作仓", "US"))))
|
||||
.thenReturn(ApiResponse.success(List.of(new DomesticPartnerWarehouseClient.Option(
|
||||
102L, "US-LAX", "洛杉矶合作仓", "us"))));
|
||||
|
||||
assertThat(directory.options()).singleElement().satisfies(option ->
|
||||
assertThat(option.warehouseId()).isEqualTo("101"));
|
||||
assertThat(directory.refresh()).singleElement().satisfies(option -> {
|
||||
assertThat(option.warehouseId()).isEqualTo("102");
|
||||
assertThat(option.countryCode()).isEqualTo("US");
|
||||
});
|
||||
verify(client, times(2)).activePartners("internal-token");
|
||||
}
|
||||
|
||||
@Test
|
||||
void malformedDomesticRowsAreFilteredAndAnEmptyFilteredResultIsNotCached() {
|
||||
when(client.activePartners("internal-token"))
|
||||
.thenReturn(ApiResponse.success(List.of(new DomesticPartnerWarehouseClient.Option(
|
||||
101L, " ", "无编码仓", "US"))))
|
||||
.thenReturn(ApiResponse.success(List.of(new DomesticPartnerWarehouseClient.Option(
|
||||
102L, "US-LAX", "洛杉矶合作仓", "US"))));
|
||||
|
||||
assertThat(directory.options()).isEmpty();
|
||||
assertThat(directory.options()).singleElement().satisfies(option ->
|
||||
assertThat(option.warehouseId()).isEqualTo("102"));
|
||||
verify(client, times(2)).activePartners("internal-token");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user