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