This commit is contained in:
2026-08-20 13:07:40 +08:00
parent 15d3ffbc0a
commit d340c418e8
@@ -1,6 +1,7 @@
package com.baiyue.finance;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assumptions;
import org.yaml.snakeyaml.Yaml;
import java.nio.charset.StandardCharsets;
@@ -18,34 +19,64 @@ class FinanceExportContractTest {
"FINANCE_RECEIVABLE_STATISTICS");
@Test
void keepsOpenApiAndAllFileDefinitionsOnTheSameNineTypes() throws Exception {
String openApi = Files.readString(resolve("docs", "财务管理", "openapi", "finance-phase1-five-pages-v1.yaml"), StandardCharsets.UTF_8);
String application = Files.readString(resolve("baiyue-firstleg", "file", "src", "main", "resources", "application.yml"), StandardCharsets.UTF_8);
String local = Files.readString(resolve("baiyue-firstleg", "config", "nacos", "local", "file-service.yml"), StandardCharsets.UTF_8);
String cn = Files.readString(resolve("baiyue-firstleg", "config", "nacos", "cn", "file-service.yml"), StandardCharsets.UTF_8);
void keepsAllFileDefinitionsOnTheSameNineTypes() throws Exception {
Path backendRoot = backendRoot();
String application = Files.readString(backendRoot.resolve("file/src/main/resources/application.yml"), StandardCharsets.UTF_8);
String local = Files.readString(backendRoot.resolve("config/nacos/local/file-service.yml"), StandardCharsets.UTF_8);
String cn = Files.readString(backendRoot.resolve("config/nacos/cn/file-service.yml"), StandardCharsets.UTF_8);
Yaml yaml = new Yaml();
assertThat((Object) yaml.load(openApi)).isNotNull();
assertThat((Object) yaml.load(application)).isNotNull();
assertThat((Object) yaml.load(local)).isNotNull();
assertThat((Object) yaml.load(cn)).isNotNull();
assertThat(openApi).contains("/internal/exports/v1/{exportType}/batches:")
.contains("customerId?, status?, settlementNo?")
.contains("所有 DETAIL 仅 settlementId")
.doesNotContain("DETAIL: settlementId, direction");
for (String type : TYPES) {
assertThat(openApi).contains("- " + type);
assertThat(application).contains(type + ":").contains("provider-path: /internal/exports/v1/" + type + "/batches");
assertThat(local).contains(type + ":").contains("provider-path: /internal/exports/v1/" + type + "/batches");
assertThat(cn).contains(type + ":").contains("provider-path: /internal/exports/v1/" + type + "/batches");
}
}
private static Path resolve(String... segments) {
Path repository = Path.of("").toAbsolutePath().normalize();
while (repository != null && !Files.exists(repository.resolve("apps").resolve("admin-web"))) repository = repository.getParent();
if (repository == null) throw new IllegalStateException("repository root not found");
return repository.resolve(Path.of(segments[0], java.util.Arrays.copyOfRange(segments, 1, segments.length)));
@Test
void keepsOuterOpenApiOnTheSameNineTypesWhenAvailable() throws Exception {
Path outerRoot = outerRoot();
Assumptions.assumeTrue(outerRoot != null, "outer product contract repository is not part of this checkout");
String openApi = Files.readString(
outerRoot.resolve("docs/财务管理/openapi/finance-phase1-five-pages-v1.yaml"),
StandardCharsets.UTF_8);
assertThat((Object) new Yaml().load(openApi)).isNotNull();
assertThat(openApi).contains("/internal/exports/v1/{exportType}/batches:")
.contains("customerId?, status?, settlementNo?")
.contains("所有 DETAIL 仅 settlementId")
.doesNotContain("DETAIL: settlementId, direction");
for (String type : TYPES) {
assertThat(openApi).contains("- " + type);
}
}
private static Path backendRoot() {
Path current = Path.of("").toAbsolutePath().normalize();
while (current != null) {
if (Files.exists(current.resolve("pom.xml"))
&& Files.isDirectory(current.resolve("finance"))
&& Files.isDirectory(current.resolve("file"))) {
return current;
}
current = current.getParent();
}
throw new IllegalStateException("backend repository root not found");
}
private static Path outerRoot() {
Path current = backendRoot();
while (current != null) {
if (Files.isDirectory(current.resolve("apps/admin-web"))
&& Files.isDirectory(current.resolve("docs/财务管理"))) {
return current;
}
current = current.getParent();
}
return null;
}
}