66import io .github .randomcodespace .iq .config .CodeIqConfig ;
77import io .github .randomcodespace .iq .graph .GraphStore ;
88import io .github .randomcodespace .iq .mcp .McpTools ;
9+ import io .github .randomcodespace .iq .model .CodeEdge ;
10+ import io .github .randomcodespace .iq .model .CodeNode ;
911import io .github .randomcodespace .iq .query .QueryService ;
1012import io .github .randomcodespace .iq .query .StatsService ;
1113import io .github .randomcodespace .iq .query .TopologyService ;
2527import java .util .Optional ;
2628
2729import static org .junit .jupiter .api .Assertions .*;
30+ import static org .mockito .ArgumentMatchers .anyList ;
2831import static org .mockito .Mockito .*;
2932import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
3033import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
@@ -47,6 +50,9 @@ class TopologyEndpointTest {
4750 @ Mock
4851 private GraphDatabaseService graphDb ;
4952
53+ @ Mock
54+ private TopologyService topologyService ;
55+
5056 private CodeIqConfig config ;
5157 private MockMvc mockMvc ;
5258 private McpTools mcpTools ;
@@ -58,9 +64,16 @@ void setUp() {
5864 config .setMaxDepth (10 );
5965 config .setMaxRadius (10 );
6066 config .setRootPath ("." );
67+
6168 objectMapper = new ObjectMapper ();
62- var controller = new GraphController (queryService , analyzer , config );
63- mockMvc = MockMvcBuilders .standaloneSetup (controller ).build ();
69+
70+ // GraphStore returns >0 count so TopologyController loads from Neo4j
71+ lenient ().when (graphStore .count ()).thenReturn (1L );
72+ lenient ().when (graphStore .findAll ()).thenReturn (List .of ());
73+
74+ var topologyController = new TopologyController (topologyService , graphStore , config );
75+ mockMvc = MockMvcBuilders .standaloneSetup (topologyController ).build ();
76+
6477 mcpTools = new McpTools (queryService , analyzer , config , objectMapper ,
6578 Optional .empty (), graphDb , new StatsService (),
6679 new TopologyService (), graphStore );
@@ -97,7 +110,7 @@ private Map<String, Object> buildTopologyResponse() {
97110
98111 @ Test
99112 void getTopologyShouldReturnTopologyResponse () throws Exception {
100- when (queryService .getTopology ()).thenReturn (buildTopologyResponse ());
113+ when (topologyService .getTopology (anyList (), anyList () )).thenReturn (buildTopologyResponse ());
101114
102115 mockMvc .perform (get ("/api/topology" ))
103116 .andExpect (status ().isOk ())
@@ -109,7 +122,7 @@ void getTopologyShouldReturnTopologyResponse() throws Exception {
109122
110123 @ Test
111124 void getTopologyShouldReturnServiceDetails () throws Exception {
112- when (queryService .getTopology ()).thenReturn (buildTopologyResponse ());
125+ when (topologyService .getTopology (anyList (), anyList () )).thenReturn (buildTopologyResponse ());
113126
114127 mockMvc .perform (get ("/api/topology" ))
115128 .andExpect (status ().isOk ())
@@ -121,7 +134,7 @@ void getTopologyShouldReturnServiceDetails() throws Exception {
121134
122135 @ Test
123136 void getTopologyShouldReturnInfraDetails () throws Exception {
124- when (queryService .getTopology ()).thenReturn (buildTopologyResponse ());
137+ when (topologyService .getTopology (anyList (), anyList () )).thenReturn (buildTopologyResponse ());
125138
126139 mockMvc .perform (get ("/api/topology" ))
127140 .andExpect (status ().isOk ())
@@ -132,7 +145,7 @@ void getTopologyShouldReturnInfraDetails() throws Exception {
132145
133146 @ Test
134147 void getTopologyShouldReturnConnectionDetails () throws Exception {
135- when (queryService .getTopology ()).thenReturn (buildTopologyResponse ());
148+ when (topologyService .getTopology (anyList (), anyList () )).thenReturn (buildTopologyResponse ());
136149
137150 mockMvc .perform (get ("/api/topology" ))
138151 .andExpect (status ().isOk ())
@@ -143,12 +156,12 @@ void getTopologyShouldReturnConnectionDetails() throws Exception {
143156 }
144157
145158 @ Test
146- void getTopologyDelegatesToQueryService () throws Exception {
147- when (queryService .getTopology ()).thenReturn (buildTopologyResponse ());
159+ void getTopologyDelegatesToTopologyService () throws Exception {
160+ when (topologyService .getTopology (anyList (), anyList () )).thenReturn (buildTopologyResponse ());
148161
149162 mockMvc .perform (get ("/api/topology" )).andExpect (status ().isOk ());
150163
151- verify (queryService ).getTopology ();
164+ verify (topologyService ).getTopology (anyList (), anyList () );
152165 }
153166
154167 @ Test
@@ -157,7 +170,7 @@ void getTopologyReturnsEmptyListsWhenNoData() throws Exception {
157170 empty .put ("services" , List .of ());
158171 empty .put ("infrastructure" , List .of ());
159172 empty .put ("connections" , List .of ());
160- when (queryService .getTopology ()).thenReturn (empty );
173+ when (topologyService .getTopology (anyList (), anyList () )).thenReturn (empty );
161174
162175 mockMvc .perform (get ("/api/topology" ))
163176 .andExpect (status ().isOk ())
0 commit comments