Skip to content

Commit 8d299c6

Browse files
Add test sample for SpringComposedRequestMappingCheck
1 parent feac032 commit 8d299c6

File tree

6 files changed

+176
-1
lines changed

6 files changed

+176
-1
lines changed

its/autoscan/src/test/java/org/sonar/java/it/AutoScanTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void javaCheckTestSources() throws Exception {
120120
.setProjectName(PROJECT_NAME)
121121
.setProjectVersion("0.1.0-SNAPSHOT")
122122
.setSourceEncoding("UTF-8")
123-
.setSourceDirs("aws/src/main/java/,default/src/main/java/,java-17/src/main/java/,spring-3.2/src/main/java/")
123+
.setSourceDirs("aws/src/main/java/,default/src/main/java/,java-17/src/main/java/,spring-3.2/src/main/java/,spring-web-4.0/src/main/java/")
124124
.setTestDirs("default/src/test/java/,test-classpath-reader/src/test/java")
125125
.setProperty("sonar.java.source", "22")
126126
// common properties

java-checks-test-sources/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<module>java-17</module>
2222
<module>test-classpath-reader</module>
2323
<module>spring-3.2</module>
24+
<module>spring-web-4.0</module>
2425
</modules>
2526

2627
<build>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>org.sonarsource.java</groupId>
8+
<artifactId>java-checks-test-sources</artifactId>
9+
<version>8.11.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>spring-web-4.0</artifactId>
13+
<name>SonarQube Java :: Checks Test Sources :: Spring Web 4.0</name>
14+
15+
<properties>
16+
<sonar.skip>true</sonar.skip>
17+
<forbiddenapis.skip>true</forbiddenapis.skip>
18+
<skipTests>true</skipTests>
19+
<maven.deploy.skip>true</maven.deploy.skip>
20+
</properties>
21+
22+
<dependencies>
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>spring-web</artifactId>
26+
<version>4.0.0.RELEASE</version>
27+
<scope>provided</scope>
28+
</dependency>
29+
</dependencies>
30+
31+
<profiles>
32+
<profile>
33+
<id>analyze-tests</id>
34+
<properties>
35+
<sonar.skip>false</sonar.skip>
36+
</properties>
37+
</profile>
38+
</profiles>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<configuration>
46+
<release>22</release>
47+
<source>22</source>
48+
<target>22</target>
49+
</configuration>
50+
</plugin>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-surefire-plugin</artifactId>
54+
<configuration>
55+
<argLine>--enable-preview</argLine>
56+
</configuration>
57+
</plugin>
58+
<plugin>
59+
<groupId>org.simplify4u.plugins</groupId>
60+
<artifactId>sign-maven-plugin</artifactId>
61+
<executions>
62+
<execution>
63+
<id>sign-artifacts</id>
64+
<phase>none</phase>
65+
</execution>
66+
</executions>
67+
</plugin>
68+
<plugin>
69+
<artifactId>maven-jar-plugin</artifactId>
70+
<executions>
71+
<execution>
72+
<id>default-jar</id>
73+
<phase>none</phase>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
<plugin>
78+
<artifactId>maven-source-plugin</artifactId>
79+
<executions>
80+
<execution>
81+
<id>attach-sources</id>
82+
<phase>none</phase>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
<plugin>
87+
<artifactId>maven-javadoc-plugin</artifactId>
88+
<executions>
89+
<execution>
90+
<id>attach-javadocs</id>
91+
<phase>none</phase>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
<plugin>
96+
<artifactId>maven-install-plugin</artifactId>
97+
<executions>
98+
<execution>
99+
<id>default-install</id>
100+
<phase>none</phase>
101+
</execution>
102+
</executions>
103+
</plugin>
104+
<plugin>
105+
<groupId>com.mycila</groupId>
106+
<artifactId>license-maven-plugin</artifactId>
107+
<configuration>
108+
<licenseSets>
109+
<licenseSet>
110+
<excludes>
111+
<exclude>src/main/java/**</exclude>
112+
<exclude>src/test/java/**</exclude>
113+
</excludes>
114+
</licenseSet>
115+
</licenseSets>
116+
</configuration>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
121+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package checks;
2+
3+
import org.springframework.web.bind.annotation.RequestMapping;
4+
import org.springframework.web.bind.annotation.RequestMethod;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
import static org.springframework.web.bind.annotation.RequestMethod.POST;
8+
9+
10+
/**
11+
* This class serves as a sample for older spring-web version (4.0) where @GetMapping, @PostMapping and so on were not present
12+
* hence no issues are expected to be reported here when using the generic @RequestMapping
13+
*/
14+
@RestController
15+
@RequestMapping("/home")
16+
public class SpringComposedRequestMappingCheckSample {
17+
18+
@RequestMapping(method = RequestMethod.GET)
19+
String m2() {
20+
return "";
21+
}
22+
23+
@RequestMapping(method = {POST})
24+
String m3() {
25+
return "";
26+
}
27+
28+
@RequestMapping(method = {RequestMethod.PUT})
29+
String m4() {
30+
return "";
31+
}
32+
33+
@RequestMapping(method = RequestMethod.PATCH)
34+
String m5() {
35+
return "";
36+
}
37+
38+
}

java-checks-testkit/src/main/java/org/sonar/java/checks/Constants.java

+2
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ private Constants() {
2323

2424
public static final String SPRING_3_2 = "../java-checks-test-sources/spring-3.2";
2525
public static final String SPRING_3_2_CLASSPATH = SPRING_3_2 + "/target/test-classpath.txt";
26+
public static final String SPRING_WEB_4_0 = "../java-checks-test-sources/spring-web-4.0";
27+
public static final String SPRING_WEB_4_0_CLASSPATH = SPRING_WEB_4_0 + "/target/test-classpath.txt";
2628
}

java-checks/src/test/java/org/sonar/java/checks/spring/SpringComposedRequestMappingCheckTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
package org.sonar.java.checks.spring;
1818

1919
import org.junit.jupiter.api.Test;
20+
import org.sonar.java.checks.Constants;
2021
import org.sonar.java.checks.verifier.CheckVerifier;
22+
import org.sonar.java.test.classpath.TestClasspathUtils;
23+
24+
import static org.sonar.java.checks.verifier.TestUtils.mainCodeSourcesPathInModule;
2125

2226
class SpringComposedRequestMappingCheckTest {
2327

@@ -34,4 +38,13 @@ void test() {
3438
.verifyNoIssues();
3539
}
3640

41+
@Test
42+
void test_spring_web_4_0() {
43+
CheckVerifier.newVerifier()
44+
.onFile(mainCodeSourcesPathInModule(Constants.SPRING_WEB_4_0, "checks/SpringComposedRequestMappingCheckSample.java"))
45+
.withCheck(new SpringComposedRequestMappingCheck())
46+
.withClassPath(TestClasspathUtils.loadFromFile(Constants.SPRING_WEB_4_0_CLASSPATH))
47+
.verifyNoIssues();
48+
}
49+
3750
}

0 commit comments

Comments
 (0)