forked from helidon-io/helidon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for injection of ServerRequest and ServerResponse also via CD…
…I. New functional test to verify both types of injection. See issue helidon-io#6698.
- Loading branch information
Showing
9 changed files
with
353 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>helidon-tests-functional-project</artifactId> | ||
<groupId>io.helidon.tests.functional</groupId> | ||
<version>4.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>helidon-tests-functional-request-scope-injection</artifactId> | ||
<name>Helidon Functional Test: Helidon Request Scope Injection</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.bundles</groupId> | ||
<artifactId>helidon-microprofile-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.config</groupId> | ||
<artifactId>helidon-config-yaml</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.helidon.microprofile.tests</groupId> | ||
<artifactId>helidon-microprofile-tests-junit5</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-params</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
60 changes: 60 additions & 0 deletions
60
...n/src/main/java/io/helidon/tests/functional/context/injection/CheckInjectionResource.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,60 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.tests.functional.context.injection; | ||
|
||
import java.util.Objects; | ||
|
||
import io.helidon.nima.webserver.http.ServerRequest; | ||
import io.helidon.nima.webserver.http.ServerResponse; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
/** | ||
* Verifies that {@code ServerRequest} and {@code ServerResponse} are injectable | ||
* both via {@code @Context} and {@code @Inject}. | ||
*/ | ||
@Path("/check") | ||
public class CheckInjectionResource { | ||
|
||
@Context | ||
private ServerRequest serverRequest; | ||
|
||
@Context | ||
private ServerResponse serverResponse; | ||
|
||
@Inject | ||
private ServerRequest serverRequestCdi; | ||
|
||
@Inject | ||
private ServerResponse serverResponseCdi; | ||
|
||
@GET | ||
public Response checkInjection() { | ||
Objects.requireNonNull(serverRequest); | ||
Objects.requireNonNull(serverResponse); | ||
Objects.requireNonNull(serverRequestCdi); | ||
Objects.requireNonNull(serverResponseCdi); | ||
if (!serverRequestCdi.path().equals(serverRequest.path()) | ||
|| !serverResponseCdi.status().equals(serverResponse.status())) { | ||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); | ||
} | ||
return Response.ok().build(); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...e-injection/src/main/java/io/helidon/tests/functional/context/injection/package-info.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,20 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Simple app to verify injection of {@code ServerRequest} and {@code ServerResponse}. | ||
*/ | ||
package io.helidon.tests.functional.context.injection; |
25 changes: 25 additions & 0 deletions
25
tests/functional/request-scope-injection/src/main/resources/META-INF/beans.xml
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,25 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2023 Oracle and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee | ||
https://jakarta.ee/xml/ns/jakartaee/beans_3_0.xsd" | ||
version="3.0" | ||
bean-discovery-mode="annotated"> | ||
</beans> |
45 changes: 45 additions & 0 deletions
45
...ction/src/test/java/io/helidon/tests/functional/context/injection/CheckInjectionTest.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,45 @@ | ||
/* | ||
* Copyright (c) 2023 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.tests.functional.context.injection; | ||
|
||
import io.helidon.microprofile.tests.junit5.HelidonTest; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.client.WebTarget; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
/** | ||
* Unit test for {@link CheckInjectionResource}. | ||
*/ | ||
@HelidonTest | ||
class CheckInjectionTest { | ||
|
||
private final WebTarget baseTarget; | ||
|
||
@Inject | ||
CheckInjectionTest(WebTarget baseTarget) { | ||
this.baseTarget = baseTarget; | ||
} | ||
|
||
@Test | ||
void testCheckInjection() { | ||
WebTarget target = baseTarget.path("/check"); | ||
assertThat(target.request().get().getStatus(), is(200)); | ||
} | ||
} |
Oops, something went wrong.