Skip to content

Commit 9ac1445

Browse files
committed
Tests and README adjustments
1 parent a36eb6b commit 9ac1445

File tree

11 files changed

+230
-62
lines changed

11 files changed

+230
-62
lines changed

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ def mkRoutes(router: Router) =
449449

450450
### `Future[T]` and `Promise[T]` support in Rest-Endpoints
451451

452-
If you're using Scala 3, you might be using `Future` for async operations.
453452
This extension allows you to return `Future[T]` and `Promise[T]` from your rest-endpoints.
454453

455454
```scala
@@ -475,6 +474,25 @@ end GreetingResource
475474

476475
If the `Future[T]` or `Promise[T]` fails, the normal exception handling is invoked.
477476

477+
Make sure to have the following dependencies in your `pom.xml` to make it work:
478+
479+
```xml
480+
<dependency>
481+
<groupId>io.quarkus</groupId>
482+
<artifactId>quarkus-rest</artifactId>
483+
</dependency>
484+
<dependency>
485+
<groupId>io.quarkiverse.scala</groupId>
486+
<artifactId>quarkus-scala3</artifactId>
487+
<version>${project.version}</version>
488+
</dependency>
489+
<dependency>
490+
<groupId>io.quarkiverse.scala</groupId>
491+
<artifactId>quarkus-scala3-deployment</artifactId>
492+
<version>${project.version}</version>
493+
</dependency>
494+
```
495+
478496

479497
## Contributors ✨
480498

deployment/src/main/java/io/quarkiverse/scala/scala3/deployment/FutureReturnTypeMethodScanner.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ private void ensureNotBlocking(MethodInfo method) {
2525
}
2626
}
2727

28+
public FutureReturnTypeMethodScanner() {
29+
}
30+
2831
@Override
2932
public List<HandlerChainCustomizer> scan(MethodInfo method, ClassInfo actualEndpointClass,
3033
Map<String, Object> methodContext) {

deployment/src/main/java/io/quarkiverse/scala/scala3/deployment/Scala3Processor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void registerScalaJacksonModule(BuildProducer<ClassPathJacksonModuleBuildItem> c
3232

3333
@BuildStep
3434
MethodScannerBuildItem enableAsyncMethodsInRestEndpoints() {
35+
System.out.println("Enabling async methods in rest endpoints");
3536
return new MethodScannerBuildItem(new FutureReturnTypeMethodScanner());
3637
}
3738
}

integration-tests/pom.xml

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,58 @@
88
</parent>
99
<artifactId>quarkus-scala3-integration-tests</artifactId>
1010
<name>Quarkus - Scala3 - Integration Tests</name>
11+
<properties>
12+
<scala-maven-plugin.version>4.9.0</scala-maven-plugin.version>
13+
<scala.version>3.4.1</scala.version>
14+
</properties>
1115
<dependencies>
1216
<dependency>
1317
<groupId>io.quarkus</groupId>
14-
<artifactId>quarkus-resteasy</artifactId>
18+
<artifactId>quarkus-rest</artifactId>
19+
<scope>test</scope>
1520
</dependency>
1621
<dependency>
1722
<groupId>io.quarkiverse.scala</groupId>
1823
<artifactId>quarkus-scala3</artifactId>
1924
<version>${project.version}</version>
2025
</dependency>
26+
<dependency>
27+
<groupId>io.quarkiverse.scala</groupId>
28+
<artifactId>quarkus-scala3-deployment</artifactId>
29+
<version>${project.version}</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.scala-lang</groupId>
33+
<artifactId>scala3-compiler_3</artifactId>
34+
<version>${scala.version}</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.scala-lang</groupId>
39+
<artifactId>scala3-library_3</artifactId>
40+
<version>${scala.version}</version>
41+
<scope>test</scope>
42+
</dependency>
2143
<dependency>
2244
<groupId>io.quarkus</groupId>
2345
<artifactId>quarkus-junit5</artifactId>
2446
<scope>test</scope>
2547
</dependency>
48+
<dependency>
49+
<groupId>io.quarkus</groupId>
50+
<artifactId>quarkus-junit5-internal</artifactId>
51+
<scope>test</scope>
52+
</dependency>
2653
<dependency>
2754
<groupId>io.rest-assured</groupId>
2855
<artifactId>rest-assured</artifactId>
2956
<scope>test</scope>
3057
</dependency>
58+
3159
</dependencies>
3260
<build>
61+
<sourceDirectory>src/main/scala</sourceDirectory>
62+
<testSourceDirectory>src/test/scala</testSourceDirectory>
3363
<plugins>
3464
<plugin>
3565
<groupId>io.quarkus</groupId>
@@ -42,6 +72,51 @@
4272
</execution>
4373
</executions>
4474
</plugin>
75+
<plugin>
76+
<artifactId>maven-compiler-plugin</artifactId>
77+
<configuration>
78+
<annotationProcessorPaths>
79+
<path>
80+
<groupId>io.quarkus</groupId>
81+
<artifactId>quarkus-extension-processor</artifactId>
82+
<version>${quarkus.version}</version>
83+
</path>
84+
</annotationProcessorPaths>
85+
</configuration>
86+
</plugin>
87+
<plugin>
88+
<groupId>net.alchim31.maven</groupId>
89+
<artifactId>scala-maven-plugin</artifactId>
90+
<version>${scala-maven-plugin.version}</version>
91+
<executions>
92+
<execution>
93+
<?m2e ignore?>
94+
<id>scala-compile-first</id>
95+
<phase>process-resources</phase>
96+
<goals>
97+
<goal>add-source</goal>
98+
<goal>compile</goal>
99+
</goals>
100+
</execution>
101+
<execution>
102+
<?m2e ignore?>
103+
<id>scala-test-compile</id>
104+
<phase>process-test-resources</phase>
105+
<goals>
106+
<goal>add-source</goal>
107+
<goal>testCompile</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
<configuration>
112+
<args>
113+
<arg>-Wunused:all</arg>
114+
<arg>-feature</arg>
115+
<arg>-deprecation</arg>
116+
<arg>-Ysemanticdb</arg>
117+
</args>
118+
</configuration>
119+
</plugin>
45120
</plugins>
46121
</build>
47122
<profiles>
@@ -54,6 +129,7 @@
54129
</activation>
55130
<build>
56131
<plugins>
132+
57133
<plugin>
58134
<artifactId>maven-surefire-plugin</artifactId>
59135
<configuration>

integration-tests/src/main/java/io/quarkiverse/scala/scala3/it/Scala3Resource.java

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package io.quarkiverse.scala.scala3.it
2+
3+
import jakarta.ws.rs.GET
4+
import jakarta.ws.rs.Path
5+
import jakarta.ws.rs.Produces
6+
import jakarta.ws.rs.core.MediaType.TEXT_PLAIN
7+
8+
import scala.concurrent.Future
9+
import scala.concurrent.Promise
10+
import scala.concurrent.ExecutionContext.Implicits.global
11+
12+
@Path("")
13+
class Scala3Resource {
14+
15+
@GET
16+
@Path("/hello")
17+
def hello(): String = "Hello from Scala 3.4.1"
18+
19+
@GET
20+
@Path("/simple-future")
21+
@Produces(Array(TEXT_PLAIN))
22+
def simpleFuture: Future[String] = for {
23+
_ <- Future { Thread.sleep(2000L) }
24+
s <- Future.successful("Hello from a Future in Scala 3.4.1")
25+
} yield s
26+
27+
@GET
28+
@Path("simple-promise")
29+
@Produces(Array(TEXT_PLAIN))
30+
def simplePromise: Promise[String] = Promise.successful("Promise returned")
31+
32+
33+
@GET
34+
@Path("future-failure")
35+
@Produces(Array(TEXT_PLAIN))
36+
def futureFailure: Future[String] = Future.failed(new RuntimeException("Future failed"))
37+
38+
}

integration-tests/src/test/java/io/quarkiverse/scala/scala3/it/NativeScala3ResourceIT.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

integration-tests/src/test/java/io/quarkiverse/scala/scala3/it/Scala3ResourceTest.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.quarkiverse.scala.scala3.it
2+
3+
import io.restassured.RestAssured.*
4+
import io.restassured.internal.{ResponseSpecificationImpl, ValidatableResponseImpl}
5+
import io.restassured.response.{ExtractableResponse, Response, ValidatableResponse}
6+
import io.restassured.specification.{RequestSender, RequestSpecification, ResponseSpecification}
7+
8+
class GivenConstructor(givenBlock: RequestSpecification => RequestSpecification):
9+
def When(whenBlock: RequestSpecification => Response): ExpectationConstructor =
10+
ExpectationConstructor(givenBlock, whenBlock)
11+
12+
class ExpectationConstructor(
13+
givenBlock: RequestSpecification => RequestSpecification,
14+
whenBlock: RequestSpecification => Response
15+
):
16+
def Then(validatable: ValidatableResponse => Unit) =
17+
val appliedGiven: RequestSpecification = givenBlock.apply(`given`())
18+
val appliedWhen: Response = whenBlock.apply(appliedGiven)
19+
validatable.apply(appliedWhen.`then`())
20+
21+
object Given:
22+
def apply(givenBlock: RequestSpecification => RequestSpecification): GivenConstructor = GivenConstructor(givenBlock)
23+
24+
def When(whenBlock: RequestSpecification => Response) =
25+
def blankGiven(givenBlock: RequestSpecification): RequestSpecification = `given`()
26+
Given(blankGiven).When(whenBlock)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.quarkiverse.scala.scala3.it
2+
3+
import io.quarkus.test.junit.QuarkusIntegrationTest
4+
5+
@QuarkusIntegrationTest
6+
class NativeScala3ResourceIT extends Scala3ResourceTest {
7+
8+
}

0 commit comments

Comments
 (0)