Files
svc-hall-service/src/test/java/com/yunhai/svchall/service/impl/FlowCenterClientRoutingTest.java
T

53 lines
2.7 KiB
Java

package com.yunhai.svchall.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yunhai.platform.openapi.core.*;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.jupiter.api.Assertions.*;
class FlowCenterClientRoutingTest {
private YschOpenCall call(String gateway) {
OpenApiProperties open = new OpenApiProperties();
open.setBaseHost(gateway);
return new YschOpenCall(new YschCallProperties(), open, new ObjectMapper(), null);
}
@Test
void enabledWithoutExplicitTargetUsesSdk() {
YschOpenCall call = call("http://gateway:10013");
assertFalse(call.hasTarget("flow-center"));
FlowCenterClient client = new FlowCenterClient(call, new ObjectMapper(), true, "");
assertTrue(client.enabled());
assertEquals(true, ReflectionTestUtils.getField(client, "directoryResolved"));
assertNull(ReflectionTestUtils.getField(client, "flowSpec"));
assertEquals("http://gateway:10013/form-center", call.resolveTarget("form-center").resolveBaseUrl());
assertDoesNotThrow(() -> new FormCenterCatalogClient(call));
assertDoesNotThrow(() -> new FcSubmissionClient(call));
assertDoesNotThrow(() -> new FormSyncClient(call));
}
@Test
void explicitThenLegacyThenSdkPriority() {
YschCallProperties props = new YschCallProperties();
props.getTargets().put("flow-center", TargetSpec.of("http://explicit", "/flow-center"));
YschOpenCall explicit = new YschOpenCall(props, new ObjectMapper(), null);
FlowCenterClient client = new FlowCenterClient(explicit, new ObjectMapper(), true, "http://legacy/ctx");
assertEquals(true, ReflectionTestUtils.getField(client, "directoryResolved"));
client = new FlowCenterClient(call("http://gateway"), new ObjectMapper(), true, "http://legacy/ctx");
assertEquals(false, ReflectionTestUtils.getField(client, "directoryResolved"));
TargetSpec spec = (TargetSpec) ReflectionTestUtils.getField(client, "flowSpec");
assertEquals("http://legacy/ctx", spec.resolveBaseUrl());
}
@Test
void enabledWithoutResolvableAddressFailsButDisabledDoesNot() {
assertThrows(IllegalStateException.class,
() -> new FlowCenterClient(call(null), new ObjectMapper(), true, ""));
assertThrows(IllegalStateException.class,
() -> new FlowCenterClient(call("http://gateway/open-gateway"), new ObjectMapper(), true, ""));
assertFalse(new FlowCenterClient(call(null), new ObjectMapper(), false, "").enabled());
assertFalse(new FlowCenterClient(call(null), new ObjectMapper(), false, "unused-legacy-value").enabled());
}
}