-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Warn when a spring-web class is not annotated with @RestController
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ng-web/deployment/src/test/java/io/quarkus/spring/web/test/MissingRestControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.spring.web.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import java.util.logging.LogRecord; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class MissingRestControllerTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(NonAnnotatedController.class, ProperController.class)) | ||
.setApplicationName("missing-rest-controller") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.setLogRecordPredicate(r -> "io.quarkus.spring.web.deployment.SpringWebProcessor".equals(r.getLoggerName())); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void testBuildLogs() { | ||
List<LogRecord> buildLogRecords = prodModeTestResults.getRetainedBuildLogRecords(); | ||
assertThat(buildLogRecords).isNotEmpty(); | ||
assertThat(buildLogRecords).hasOnlyOneElementSatisfying(r -> { | ||
assertThat(r.getMessage()) | ||
.contains("but was not annotated with") | ||
.contains(NonAnnotatedController.class.getName()) | ||
.doesNotContain(ProperController.class.getName()); | ||
}); | ||
} | ||
|
||
@RequestMapping("/non") | ||
public static class NonAnnotatedController { | ||
|
||
@GetMapping("/hello") | ||
public String greet() { | ||
return "hello"; | ||
} | ||
} | ||
|
||
@RestController | ||
@RequestMapping("/proper") | ||
public static class ProperController { | ||
|
||
@GetMapping("/hello") | ||
public String greet() { | ||
return "hello"; | ||
} | ||
} | ||
} |