Skip to content

Commit 05b9cd4

Browse files
committed
added test cases to verify that it works with GetMapping as well
1 parent ea227d7 commit 05b9cd4

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/reconcilers/test/WebApiVersionSyntaxReconcilerTest.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,71 @@ public class A {
277277
assertEquals(0, problems.size());
278278
}
279279

280+
@Test
281+
void parseGetMappingWithValidVersion() throws Exception {
282+
String source = """
283+
package example.demo;
284+
285+
import org.springframework.web.bind.annotation.RestController;
286+
import org.springframework.web.bind.annotation.GetMapping;
287+
288+
@RestController
289+
public class A {
290+
@GetMapping(path = "mypath", version = "1.2.3")
291+
public String test() {
292+
return "test";
293+
}
294+
}
295+
""";
296+
List<ReconcileProblem> problems = reconcile(() -> {
297+
SpringMetamodelIndex springIndex = new SpringMetamodelIndex();
298+
299+
WebConfigIndexElement webConfig = new WebConfigIndexElement.Builder(ConfigType.WEB_CONFIG)
300+
.versionStrategy("version-strategy-configured", new Range(new Position(1, 1), new Position(1, 4)))
301+
.buildFor(null);
302+
springIndex.updateElements(getProjectName(), "soneURI", new SpringIndexElement[] {webConfig});
303+
304+
WebApiVersionSyntaxReconciler r = new WebApiVersionSyntaxReconciler(springIndex);
305+
return r;
306+
}, "A.java", source, false);
307+
308+
assertEquals(0, problems.size());
309+
}
310+
311+
@Test
312+
void parseGetMappingWithInvalidVersion() throws Exception {
313+
String source = """
314+
package example.demo;
315+
316+
import org.springframework.web.bind.annotation.RestController;
317+
import org.springframework.web.bind.annotation.GetMapping;
318+
319+
@RestController
320+
public class A {
321+
@GetMapping(path = "mypath", version = "a.b.c")
322+
public String test() {
323+
return "test";
324+
}
325+
}
326+
""";
327+
List<ReconcileProblem> problems = reconcile(() -> {
328+
SpringMetamodelIndex springIndex = new SpringMetamodelIndex();
329+
330+
WebConfigIndexElement webConfig = new WebConfigIndexElement.Builder(ConfigType.WEB_CONFIG)
331+
.versionStrategy("version-strategy-configured", new Range(new Position(1, 1), new Position(1, 4)))
332+
.buildFor(null);
333+
springIndex.updateElements(getProjectName(), "soneURI", new SpringIndexElement[] {webConfig});
334+
335+
WebApiVersionSyntaxReconciler r = new WebApiVersionSyntaxReconciler(springIndex);
336+
return r;
337+
}, "A.java", source, false);
338+
339+
assertEquals(1, problems.size());
340+
ReconcileProblem problem = problems.get(0);
341+
assertEquals(Boot4JavaProblemType.API_VERSION_SYNTAX_ERROR, problem.getType());
342+
343+
String markedStr = source.substring(problem.getOffset(), problem.getOffset() + problem.getLength());
344+
assertEquals("\"a.b.c\"", markedStr);
345+
}
346+
280347
}

0 commit comments

Comments
 (0)