|
@@ -10,6 +10,9 @@ import org.mockito.Mock;
|
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
import org.mockito.junit.jupiter.MockitoExtension;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
|
import static org.mockito.ArgumentMatchers.*;
|
|
import static org.mockito.ArgumentMatchers.*;
|
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
@@ -20,6 +23,9 @@ class DifyServiceTest {
|
|
|
@Mock
|
|
@Mock
|
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
|
|
|
|
+ @Mock
|
|
|
|
|
+ private ConfigService configService;
|
|
|
|
|
+
|
|
|
private Gson gson = new Gson();
|
|
private Gson gson = new Gson();
|
|
|
|
|
|
|
|
@InjectMocks
|
|
@InjectMocks
|
|
@@ -41,6 +47,7 @@ class DifyServiceTest {
|
|
|
java.lang.reflect.Field baseUrlField = DifyService.class.getDeclaredField("baseUrl");
|
|
java.lang.reflect.Field baseUrlField = DifyService.class.getDeclaredField("baseUrl");
|
|
|
baseUrlField.setAccessible(true);
|
|
baseUrlField.setAccessible(true);
|
|
|
baseUrlField.set(difyService, "http://localhost:8080");
|
|
baseUrlField.set(difyService, "http://localhost:8080");
|
|
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
}
|
|
@@ -80,4 +87,44 @@ class DifyServiceTest {
|
|
|
assertNotNull(result);
|
|
assertNotNull(result);
|
|
|
assertTrue(result.contains("数字命盘已生成"));
|
|
assertTrue(result.contains("数字命盘已生成"));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // ==================== Academic Workflow (US-9.1) ====================
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testInvokeAcademicWorkflow_success() {
|
|
|
|
|
+ when(configService.getValue(anyString(), anyString())).thenReturn("test-app-id");
|
|
|
|
|
+ String mockResponse = "{\"data\":{\"outputs\":\"{\\\"result\\\":\\\"ok\\\"}\"}}";
|
|
|
|
|
+ when(restTemplate.postForObject(anyString(), any(), eq(String.class))).thenReturn(mockResponse);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> inputs = new HashMap<>();
|
|
|
|
|
+ inputs.put("chart_context", "{\"positions\":{\"O\":7}}");
|
|
|
|
|
+ inputs.put("birthday", "2000-01-01");
|
|
|
|
|
+ inputs.put("name", "Test");
|
|
|
|
|
+
|
|
|
|
|
+ String result = difyService.invokeAcademicWorkflow(inputs, "user_1");
|
|
|
|
|
+
|
|
|
|
|
+ assertNotNull(result);
|
|
|
|
|
+ assertTrue(result.contains("result"));
|
|
|
|
|
+ assertTrue(result.contains("ok"));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ void testInvokeAcademicWorkflow_apiError() {
|
|
|
|
|
+ when(configService.getValue(anyString(), anyString())).thenReturn("test-app-id");
|
|
|
|
|
+ when(restTemplate.postForObject(anyString(), any(), eq(String.class)))
|
|
|
|
|
+ .thenThrow(new RuntimeException("API down"));
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> inputs = new HashMap<>();
|
|
|
|
|
+ inputs.put("chart_context", "{\"positions\":{\"O\":7}}");
|
|
|
|
|
+ inputs.put("birthday", "2000-01-01");
|
|
|
|
|
+ inputs.put("name", "Test");
|
|
|
|
|
+
|
|
|
|
|
+ String result = difyService.invokeAcademicWorkflow(inputs, "user_1");
|
|
|
|
|
+
|
|
|
|
|
+ assertNotNull(result);
|
|
|
|
|
+ // Falls back to mock interpretation with orientation analysis fields
|
|
|
|
|
+ assertTrue(result.contains("talentTendency"));
|
|
|
|
|
+ assertTrue(result.contains("suitableDirection"));
|
|
|
|
|
+ assertTrue(result.contains("learningStyle"));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|