Skip to content

Commit 37a222e

Browse files
committed
Spring 5 integration tests
Signed-off-by: Daniel Kec <daniel.kec@oracle.com>
1 parent 4c10f29 commit 37a222e

29 files changed

+1648
-0
lines changed

ext/spring5/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
<groupId>org.glassfish.hk2</groupId>
8989
<artifactId>hk2-api</artifactId>
9090
</exclusion>
91+
<exclusion>
92+
<groupId>org.springframework</groupId>
93+
<artifactId>spring-context</artifactId>
94+
</exclusion>
9195
</exclusions>
9296
</dependency>
9397

@@ -109,6 +113,18 @@
109113
</exclusions>
110114
</dependency>
111115

116+
<dependency>
117+
<groupId>org.springframework</groupId>
118+
<artifactId>spring-context</artifactId>
119+
<version>${spring5.version}</version>
120+
<exclusions>
121+
<exclusion>
122+
<groupId>commons-logging</groupId>
123+
<artifactId>commons-logging</artifactId>
124+
</exclusion>
125+
</exclusions>
126+
</dependency>
127+
112128
<dependency>
113129
<groupId>org.springframework</groupId>
114130
<artifactId>spring-web</artifactId>

tests/integration/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
<module>servlet-tests</module>
125125
<module>sonar-test</module>
126126
<module>spring4</module>
127+
<module>spring5</module>
127128
<module>tracing-support</module>
128129
<module>microprofile/config/helidon</module>
129130
<module>microprofile/config/webapp</module>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
tests
3+
=====
4+
5+
Tests are located in jersey-spring-test module.
6+
The module contains a test webapp and test code.
7+
The tests can be run in Jersey test container or an external container.
8+
9+
- Running tests in Jersey test container
10+
mvn clean test
11+
12+
- Running tests in an external container
13+
build the test app
14+
deploy to an external container
15+
configure container connection info in jersey-spring-test/pom.xml, if needed
16+
run tests in integration test mode:
17+
mvn -Pit verify
18+
19+
- Running tests in embedded Jetty instance
20+
build the test app
21+
deploy to Jetty:
22+
mvn -Pjetty jetty:run
23+
run tests in integration test mode in another console session:
24+
mvn -Pit verify
25+
26+
test class naming conventions
27+
- *ITTest.java: run in unit and IT test mode
28+
- *Test.java: run as unit tests
29+
- *IT.java: run as IT tests
30+

tests/integration/spring5/pom.xml

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
5+
6+
This program and the accompanying materials are made available under the
7+
terms of the Eclipse Public License v. 2.0, which is available at
8+
http://www.eclipse.org/legal/epl-2.0.
9+
10+
This Source Code may also be made available under the following Secondary
11+
Licenses when the conditions for such availability set forth in the
12+
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
13+
version 2 with the GNU Classpath Exception, which is available at
14+
https://www.gnu.org/software/classpath/license.html.
15+
16+
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17+
18+
-->
19+
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
22+
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<parent>
26+
<groupId>org.glassfish.jersey.tests.integration</groupId>
27+
<artifactId>project</artifactId>
28+
<version>2.30-SNAPSHOT</version>
29+
</parent>
30+
31+
<artifactId>spring5</artifactId>
32+
33+
<packaging>war</packaging>
34+
<name>jersey-tests-integration-spring5</name>
35+
36+
<description>
37+
Jersey tests for Spring 5 integration
38+
</description>
39+
40+
<dependencies>
41+
42+
<dependency>
43+
<groupId>jakarta.servlet</groupId>
44+
<artifactId>jakarta.servlet-api</artifactId>
45+
<version>${servlet4.version}</version>
46+
<scope>provided</scope>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>jakarta.ws.rs</groupId>
51+
<artifactId>jakarta.ws.rs-api</artifactId>
52+
<scope>compile</scope>
53+
</dependency>
54+
55+
<dependency>
56+
<groupId>org.glassfish.jersey.ext</groupId>
57+
<artifactId>jersey-spring5</artifactId>
58+
<version>${project.version}</version>
59+
<scope>compile</scope>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.glassfish.jersey.test-framework</groupId>
64+
<artifactId>jersey-test-framework-core</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
68+
<dependency>
69+
<groupId>org.glassfish.jersey.containers</groupId>
70+
<artifactId>jersey-container-servlet</artifactId>
71+
<scope>runtime</scope>
72+
</dependency>
73+
74+
<dependency>
75+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
76+
<artifactId>jersey-test-framework-provider-external</artifactId>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>commons-logging</groupId>
82+
<artifactId>commons-logging</artifactId>
83+
<scope>runtime</scope>
84+
</dependency>
85+
</dependencies>
86+
87+
<build>
88+
<plugins>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-compiler-plugin</artifactId>
92+
</plugin>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-failsafe-plugin</artifactId>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.eclipse.jetty</groupId>
99+
<artifactId>jetty-maven-plugin</artifactId>
100+
<configuration>
101+
<webApp>
102+
<contextPath>/</contextPath>
103+
<webInfIncludeJarPattern>.*$</webInfIncludeJarPattern>
104+
</webApp>
105+
</configuration>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
110+
<profiles>
111+
<profile>
112+
<id>delayed-strategy-skip-test</id>
113+
<activation>
114+
<property>
115+
<name>org.glassfish.jersey.injection.manager.strategy</name>
116+
<value>delayed</value>
117+
</property>
118+
</activation>
119+
<build>
120+
<plugins>
121+
<plugin>
122+
<groupId>org.apache.maven.plugins</groupId>
123+
<artifactId>maven-failsafe-plugin</artifactId>
124+
<configuration>
125+
<skipTests>true</skipTests>
126+
</configuration>
127+
</plugin>
128+
</plugins>
129+
</build>
130+
</profile>
131+
</profiles>
132+
</project>
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.jersey.server.spring.test;
18+
19+
import java.math.BigDecimal;
20+
21+
import javax.ws.rs.Consumes;
22+
import javax.ws.rs.GET;
23+
import javax.ws.rs.PUT;
24+
import javax.ws.rs.Path;
25+
import javax.ws.rs.PathParam;
26+
import javax.ws.rs.core.MediaType;
27+
28+
import javax.inject.Inject;
29+
import javax.inject.Named;
30+
import javax.servlet.http.HttpServletRequest;
31+
32+
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.beans.factory.annotation.Qualifier;
34+
35+
/**
36+
* Jersey managed JAX-RS resource for testing jersey-spring.
37+
*
38+
* @author Marko Asplund (marko.asplund at yahoo.com)
39+
*/
40+
@Path("/jersey/account")
41+
public class AccountJerseyResource {
42+
43+
@Inject
44+
@Named("AccountService-singleton")
45+
private AccountService accountServiceInject;
46+
47+
@Autowired
48+
@Qualifier("AccountService-singleton")
49+
private AccountService accountServiceAutowired;
50+
51+
@Inject
52+
@Named("AccountService-request-1")
53+
private AccountService accountServiceRequest1;
54+
55+
@Autowired
56+
@Qualifier("AccountService-request-1")
57+
private AccountService accountServiceRequest2;
58+
59+
@Autowired
60+
@Qualifier("AccountService-prototype-1")
61+
private AccountService accountServicePrototype1;
62+
63+
@Autowired
64+
@Qualifier("AccountService-prototype-1")
65+
private AccountService accountServicePrototype2;
66+
67+
@Autowired
68+
private HttpServletRequest httpServletRequest;
69+
70+
@Inject
71+
private HK2ServiceSingleton hk2Singleton;
72+
73+
@Inject
74+
private HK2ServiceRequestScoped hk2RequestScoped;
75+
76+
@Inject
77+
private HK2ServicePerLookup hk2PerLookup;
78+
79+
private String message = "n/a";
80+
81+
// resource methods for testing resource class scope
82+
@GET
83+
@Path("message")
84+
public String getMessage() {
85+
return message;
86+
}
87+
88+
@PUT
89+
@Path("message")
90+
@Consumes(MediaType.TEXT_PLAIN)
91+
public String setMessage(final String message) {
92+
this.message = message;
93+
return message;
94+
}
95+
96+
// JERSEY-2506 FIX VERIFICATION
97+
@GET
98+
@Path("server")
99+
public String verifyServletRequestInjection() {
100+
return "PASSED: " + httpServletRequest.getServerName();
101+
}
102+
103+
@GET
104+
@Path("singleton/server")
105+
public String verifyServletRequestInjectionIntoSingleton() {
106+
return accountServiceInject.verifyServletRequestInjection();
107+
}
108+
109+
@GET
110+
@Path("singleton/autowired/server")
111+
public String verifyServletRequestInjectionIntoAutowiredSingleton() {
112+
return accountServiceAutowired.verifyServletRequestInjection();
113+
}
114+
115+
@GET
116+
@Path("request/server")
117+
public String verifyServletRequestInjectionIntoRequestScopedBean() {
118+
return accountServiceRequest1.verifyServletRequestInjection();
119+
}
120+
121+
@GET
122+
@Path("prototype/server")
123+
public String verifyServletRequestInjectionIntoPrototypeScopedBean() {
124+
return accountServicePrototype1.verifyServletRequestInjection();
125+
}
126+
127+
// resource methods for testing singleton scoped beans
128+
@GET
129+
@Path("singleton/inject/{accountId}")
130+
public BigDecimal getAccountBalanceSingletonInject(@PathParam("accountId") final String accountId) {
131+
return accountServiceInject.getAccountBalance(accountId);
132+
}
133+
134+
@GET
135+
@Path("singleton/autowired/{accountId}")
136+
public BigDecimal getAccountBalanceSingletonAutowired(@PathParam("accountId") final String accountId) {
137+
return accountServiceAutowired.getAccountBalance(accountId);
138+
}
139+
140+
@PUT
141+
@Path("singleton/{accountId}")
142+
@Consumes(MediaType.TEXT_PLAIN)
143+
public void setAccountBalanceSingleton(@PathParam("accountId") final String accountId, final String balance) {
144+
accountServiceInject.setAccountBalance(accountId, new BigDecimal(balance));
145+
}
146+
147+
// resource methods for testing request scoped beans
148+
@PUT
149+
@Path("request/{accountId}")
150+
@Consumes(MediaType.TEXT_PLAIN)
151+
public BigDecimal setAccountBalanceRequest(@PathParam("accountId") final String accountId, final String balance) {
152+
accountServiceRequest1.setAccountBalance(accountId, new BigDecimal(balance));
153+
return accountServiceRequest2.getAccountBalance(accountId);
154+
}
155+
156+
// resource methods for testing prototype scoped beans
157+
@PUT
158+
@Path("prototype/{accountId}")
159+
@Consumes(MediaType.TEXT_PLAIN)
160+
public BigDecimal setAccountBalancePrototype(@PathParam("accountId") final String accountId, final String balance) {
161+
accountServicePrototype1.setAccountBalance(accountId, new BigDecimal(balance));
162+
return accountServicePrototype2.getAccountBalance(accountId);
163+
}
164+
}

0 commit comments

Comments
 (0)