Remove per-export proxy selection
This commit is contained in:
+27
-12
@@ -9,8 +9,7 @@ public record ApiDocExportRequest(
|
||||
List<String> projectPaths,
|
||||
boolean onlyInterfaces,
|
||||
boolean facadeNamesOnly,
|
||||
boolean apiPackagesOnly,
|
||||
boolean debugProxyEnabled) {
|
||||
boolean apiPackagesOnly) {
|
||||
|
||||
public enum Mode {
|
||||
PATH, FQN, BATCH
|
||||
@@ -30,29 +29,45 @@ public record ApiDocExportRequest(
|
||||
}
|
||||
}
|
||||
|
||||
public static ApiDocExportRequest path(
|
||||
String path, boolean debugProxyEnabled) {
|
||||
public static ApiDocExportRequest path(String path) {
|
||||
return new ApiDocExportRequest(
|
||||
Mode.PATH, path, List.of(),
|
||||
false, false, false, debugProxyEnabled);
|
||||
false, false, false);
|
||||
}
|
||||
|
||||
public static ApiDocExportRequest fqn(
|
||||
String className, boolean debugProxyEnabled) {
|
||||
@Deprecated
|
||||
public static ApiDocExportRequest path(String path, boolean ignored) {
|
||||
return path(path);
|
||||
}
|
||||
|
||||
public static ApiDocExportRequest fqn(String className) {
|
||||
return new ApiDocExportRequest(
|
||||
Mode.FQN, className, List.of(),
|
||||
false, false, false, debugProxyEnabled);
|
||||
false, false, false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ApiDocExportRequest fqn(String className, boolean ignored) {
|
||||
return fqn(className);
|
||||
}
|
||||
|
||||
public static ApiDocExportRequest batch(
|
||||
List<String> projectPaths,
|
||||
boolean onlyInterfaces,
|
||||
boolean facadeNamesOnly,
|
||||
boolean apiPackagesOnly,
|
||||
boolean debugProxyEnabled) {
|
||||
boolean apiPackagesOnly) {
|
||||
return new ApiDocExportRequest(
|
||||
Mode.BATCH, "", projectPaths,
|
||||
onlyInterfaces, facadeNamesOnly, apiPackagesOnly,
|
||||
debugProxyEnabled);
|
||||
onlyInterfaces, facadeNamesOnly, apiPackagesOnly);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ApiDocExportRequest batch(
|
||||
List<String> projectPaths,
|
||||
boolean onlyInterfaces,
|
||||
boolean facadeNamesOnly,
|
||||
boolean apiPackagesOnly,
|
||||
boolean ignored) {
|
||||
return batch(projectPaths, onlyInterfaces, facadeNamesOnly, apiPackagesOnly);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -33,9 +33,8 @@ public final class RunApiDocExportUseCase {
|
||||
OperationContext context) throws Exception {
|
||||
Objects.requireNonNull(request, "request");
|
||||
Objects.requireNonNull(context, "context");
|
||||
String endpoint = request.debugProxyEnabled()
|
||||
? Objects.requireNonNullElse(debugEndpointSupplier.get(), "")
|
||||
: "";
|
||||
String endpoint = Objects.requireNonNullElse(
|
||||
debugEndpointSupplier.get(), "");
|
||||
exporter.export(request, endpoint, context);
|
||||
return new Result(true);
|
||||
}
|
||||
|
||||
+8
-6
@@ -3,35 +3,37 @@ package com.example.workutils.biz.apidoc.application;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ApiDocExportRequestTest {
|
||||
|
||||
@Test
|
||||
void pathModeRequiresAPath() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ApiDocExportRequest.path(" ", false));
|
||||
() -> ApiDocExportRequest.path(" "));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fqnModeTrimsClassName() {
|
||||
ApiDocExportRequest request =
|
||||
ApiDocExportRequest.fqn(" com.example.UserFacade ", true);
|
||||
ApiDocExportRequest.fqn(" com.example.UserFacade ");
|
||||
|
||||
assertEquals(ApiDocExportRequest.Mode.FQN, request.mode());
|
||||
assertEquals("com.example.UserFacade", request.input());
|
||||
assertTrue(request.debugProxyEnabled());
|
||||
assertFalse(Arrays.stream(ApiDocExportRequest.class.getRecordComponents())
|
||||
.anyMatch(component -> component.getName().equals("debugProxyEnabled")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void batchModeCopiesProjectPaths() {
|
||||
List<String> paths = new ArrayList<>(List.of("D:/a"));
|
||||
ApiDocExportRequest request = ApiDocExportRequest.batch(
|
||||
paths, true, true, false, false);
|
||||
paths, true, true, false);
|
||||
|
||||
paths.add("D:/b");
|
||||
|
||||
@@ -42,6 +44,6 @@ class ApiDocExportRequestTest {
|
||||
void batchModeRequiresAtLeastOneProject() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> ApiDocExportRequest.batch(
|
||||
List.of(), true, true, true, false));
|
||||
List.of(), true, true, true));
|
||||
}
|
||||
}
|
||||
|
||||
+22
-23
@@ -11,40 +11,39 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
class RunApiDocExportUseCaseTest {
|
||||
|
||||
@Test
|
||||
void disabledDebugDoesNotResolveProxyEndpoint() throws Exception {
|
||||
void alwaysPassesTheStartupEndpointToTheExporter() throws Exception {
|
||||
AtomicInteger proxyCalls = new AtomicInteger();
|
||||
AtomicReference<String> endpoint = new AtomicReference<>();
|
||||
RunApiDocExportUseCase useCase = new RunApiDocExportUseCase(
|
||||
() -> {
|
||||
proxyCalls.incrementAndGet();
|
||||
return "proxy";
|
||||
return "http://127.0.0.1:1234/dubbo/invoke";
|
||||
},
|
||||
(request, debugEndpoint, context) ->
|
||||
endpoint.set(debugEndpoint));
|
||||
|
||||
useCase.execute(ApiDocExportRequest.path("A.java", false),
|
||||
OperationContext.none());
|
||||
|
||||
assertEquals(0, proxyCalls.get());
|
||||
assertEquals("", endpoint.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void enabledDebugResolvesProxyEndpointOnce() throws Exception {
|
||||
AtomicInteger proxyCalls = new AtomicInteger();
|
||||
AtomicReference<String> endpoint = new AtomicReference<>();
|
||||
RunApiDocExportUseCase useCase = new RunApiDocExportUseCase(
|
||||
() -> {
|
||||
proxyCalls.incrementAndGet();
|
||||
return "proxy";
|
||||
},
|
||||
(request, debugEndpoint, context) ->
|
||||
endpoint.set(debugEndpoint));
|
||||
|
||||
useCase.execute(ApiDocExportRequest.path("A.java", true),
|
||||
useCase.execute(ApiDocExportRequest.path("A.java"),
|
||||
OperationContext.none());
|
||||
|
||||
assertEquals(1, proxyCalls.get());
|
||||
assertEquals("proxy", endpoint.get());
|
||||
assertEquals("http://127.0.0.1:1234/dubbo/invoke", endpoint.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyStartupEndpointStillRunsTheExporter() throws Exception {
|
||||
AtomicInteger exports = new AtomicInteger();
|
||||
AtomicReference<String> endpoint = new AtomicReference<>();
|
||||
RunApiDocExportUseCase useCase = new RunApiDocExportUseCase(
|
||||
() -> "",
|
||||
(request, debugEndpoint, context) -> {
|
||||
endpoint.set(debugEndpoint);
|
||||
exports.incrementAndGet();
|
||||
});
|
||||
|
||||
useCase.execute(ApiDocExportRequest.path("A.java"),
|
||||
OperationContext.none());
|
||||
|
||||
assertEquals(1, exports.get());
|
||||
assertEquals("", endpoint.get());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user