Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RESTEASY-1569] changed calculation to get proper path substring. Add…
…ed tests for regex capturing groups
- Loading branch information
Showing
8 changed files
with
370 additions
and
1 deletion.
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
118 changes: 118 additions & 0 deletions
118
...st/java/org/jboss/resteasy/test/resource/path/ResourceLocatorRegexCapturingGroupTest.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,118 @@ | ||
package org.jboss.resteasy.test.resource.path; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.resteasy.test.resource.path.resource.ResourceLocatorRegexCapturingGroup; | ||
import org.jboss.resteasy.test.resource.path.resource.ResourceLocatorRegexCapturingGroupSubResourceNoPath; | ||
import org.jboss.resteasy.test.resource.path.resource.ResourceLocatorRegexCapturingGroupSubResourceWithPath; | ||
import org.jboss.resteasy.utils.PortProviderUtil; | ||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* @Path annotation paths can consist of Regex Capturing groups used with | ||
* Resource Locator scenarios. | ||
* | ||
* User: rsearls | ||
* Date: 2/17/17 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class ResourceLocatorRegexCapturingGroupTest { | ||
private static final String ERROR_MSG = "Response contain wrong content"; | ||
static Client client; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
client = ClientBuilder.newClient(); | ||
} | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
WebArchive war = TestUtil.prepareArchive(ResourceLocatorRegexCapturingGroupTest.class.getSimpleName()); | ||
war.addClasses(ResourceLocatorRegexCapturingGroupSubResourceNoPath.class, | ||
ResourceLocatorRegexCapturingGroupSubResourceWithPath.class); | ||
war.addAsWebInfResource(ResourceLocatorRegexCapturingGroupTest.class.getPackage(), "web.xml", "web.xml"); | ||
return TestUtil.finishContainerPrepare(war, null, ResourceLocatorRegexCapturingGroup.class); | ||
} | ||
|
||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, ResourceLocatorRegexCapturingGroupTest.class.getSimpleName()); | ||
} | ||
|
||
@AfterClass | ||
public static void close() throws Exception { | ||
client.close(); | ||
} | ||
|
||
@AfterClass | ||
public static void after() throws Exception { | ||
|
||
} | ||
|
||
/** | ||
* @tpTestDetails Test for root resource and for subresource. | ||
* @tpSince RESTEasy 3.0.16 | ||
*/ | ||
@Test | ||
public void testBasic() throws Exception { | ||
{ | ||
Response response = client.target(generateURL("/capture/basic")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "basic success", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
{ | ||
Response response = client.target(generateURL("/capture/BASIC/test")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "BASIC test", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testBird() throws Exception { | ||
{ | ||
Response response = client.target(generateURL("/capture/nobird")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "nobird success", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
|
||
{ | ||
Response response = client.target(generateURL("/capture/BIRD/test")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "BIRD test", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testFly() throws Exception { | ||
{ | ||
Response response = client.target(generateURL("/capture/a/nofly/b")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "a/nofly/b success", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
|
||
{ | ||
Response response = client.target(generateURL("/capture/a/FLY/b/test")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "a/FLY/b test", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
...java/org/jboss/resteasy/test/resource/path/ResourceLocatorRegexNonCapturingGroupTest.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,97 @@ | ||
package org.jboss.resteasy.test.resource.path; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.resteasy.test.asynch.AsyncPostProcessingTest; | ||
import org.jboss.resteasy.test.resource.path.resource.*; | ||
import org.jboss.resteasy.utils.PortProviderUtil; | ||
import org.jboss.resteasy.utils.TestUtil; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import javax.ws.rs.client.Client; | ||
import javax.ws.rs.client.ClientBuilder; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* @Path annotation paths can consist of Regex Non-Capturing groups used with | ||
* Resource Locator scenarios. | ||
* | ||
* User: rsearls | ||
* Date: 2/18/17 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class ResourceLocatorRegexNonCapturingGroupTest { | ||
private static final String ERROR_MSG = "Response contain wrong content"; | ||
static Client client; | ||
|
||
@BeforeClass | ||
public static void setup() throws Exception { | ||
client = ClientBuilder.newClient(); | ||
} | ||
|
||
@Deployment | ||
public static Archive<?> deploy() { | ||
WebArchive war = TestUtil.prepareArchive(ResourceLocatorRegexNonCapturingGroupTest.class.getSimpleName()); | ||
war.addClasses(ResourceLocatorRegexCapturingGroupSubResourceNoPath.class, | ||
ResourceLocatorRegexCapturingGroupSubResourceWithPath.class); | ||
war.addAsWebInfResource(ResourceLocatorRegexNonCapturingGroupTest.class.getPackage(), "web.xml", "web.xml"); | ||
return TestUtil.finishContainerPrepare(war, null, ResourceLocatorRegexNonCapturingGroup.class); | ||
} | ||
|
||
private String generateURL(String path) { | ||
return PortProviderUtil.generateURL(path, ResourceLocatorRegexNonCapturingGroupTest.class.getSimpleName()); | ||
} | ||
|
||
@AfterClass | ||
public static void close() throws Exception { | ||
client.close(); | ||
} | ||
|
||
@AfterClass | ||
public static void after() throws Exception { | ||
|
||
} | ||
|
||
@Test | ||
public void testBird() throws Exception { | ||
{ | ||
Response response = client.target(generateURL("/noCapture/nobird")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "nobird success", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
|
||
{ | ||
Response response = client.target(generateURL("/noCapture/BIRD/test")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "BIRD test", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testFly() throws Exception { | ||
{ | ||
Response response = client.target(generateURL("/noCapture/a/nofly/b")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "a/nofly/b success", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
|
||
{ | ||
Response response = client.target(generateURL("/noCapture/a/FLY/b/test")).request().get(); | ||
Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus()); | ||
Assert.assertEquals(ERROR_MSG, "a/FLY/b test", response.readEntity(String.class)); | ||
response.close(); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...va/org/jboss/resteasy/test/resource/path/resource/ResourceLocatorRegexCapturingGroup.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,42 @@ | ||
package org.jboss.resteasy.test.resource.path.resource; | ||
|
||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
|
||
/** | ||
* User: rsearls | ||
* Date: 2/17/17 | ||
*/ | ||
@Path("/capture") | ||
public class ResourceLocatorRegexCapturingGroup { | ||
|
||
@Path("basic") | ||
public ResourceLocatorRegexCapturingGroupSubResourceNoPath basic() { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceNoPath ("basic"); | ||
} | ||
|
||
@Path("BASIC") | ||
public ResourceLocatorRegexCapturingGroupSubResourceWithPath basicTwo() { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceWithPath("BASIC"); | ||
} | ||
|
||
@Path("{name: (nobird|NOBIRD)}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceNoPath nobird(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceNoPath(name); | ||
} | ||
|
||
@Path("{name: (bird|BIRD)}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceWithPath bird(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceWithPath(name); | ||
} | ||
|
||
@Path("{name: a/(fly|FLY)/b}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceWithPath fly(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceWithPath(name); | ||
} | ||
|
||
@Path("{name: a/(nofly|NOFLY)/b}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceNoPath nofly(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceNoPath(name); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...easy/test/resource/path/resource/ResourceLocatorRegexCapturingGroupSubResourceNoPath.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,24 @@ | ||
package org.jboss.resteasy.test.resource.path.resource; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* User: rsearls | ||
* Date: 2/17/17 | ||
*/ | ||
@Produces("text/plain") | ||
public class ResourceLocatorRegexCapturingGroupSubResourceNoPath { | ||
private String name; | ||
|
||
public ResourceLocatorRegexCapturingGroupSubResourceNoPath(String name) { | ||
this.name = name; | ||
} | ||
|
||
@GET | ||
public Response get() { | ||
return Response.ok(name +" success").build(); | ||
} | ||
} | ||
|
25 changes: 25 additions & 0 deletions
25
...sy/test/resource/path/resource/ResourceLocatorRegexCapturingGroupSubResourceWithPath.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,25 @@ | ||
package org.jboss.resteasy.test.resource.path.resource; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Response; | ||
|
||
/** | ||
* User: rsearls | ||
* Date: 2/17/17 | ||
*/ | ||
@Produces("text/plain") | ||
public class ResourceLocatorRegexCapturingGroupSubResourceWithPath { | ||
private String name; | ||
|
||
public ResourceLocatorRegexCapturingGroupSubResourceWithPath(String name) { | ||
this.name = name; | ||
} | ||
|
||
@GET | ||
@Path("/test") | ||
public Response get() { | ||
return Response.ok(name + " test").build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...org/jboss/resteasy/test/resource/path/resource/ResourceLocatorRegexNonCapturingGroup.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,33 @@ | ||
package org.jboss.resteasy.test.resource.path.resource; | ||
|
||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
|
||
/** | ||
* User: rsearls | ||
* Date: 2/17/17 | ||
*/ | ||
@Path("/noCapture") | ||
public class ResourceLocatorRegexNonCapturingGroup { | ||
|
||
@Path("{name: (?:nobird|NOBIRD)}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceNoPath nobird(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceNoPath(name); | ||
} | ||
|
||
@Path("{name: (?:bird|BIRD)}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceWithPath bird(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceWithPath(name); | ||
} | ||
|
||
@Path("{name: a/(?:fly|FLY)/b}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceWithPath fly(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceWithPath(name); | ||
} | ||
|
||
@Path("{name: a/(?:nofly|NOFLY)/b}") | ||
public ResourceLocatorRegexCapturingGroupSubResourceNoPath nofly(@PathParam("name") String name) { | ||
return new ResourceLocatorRegexCapturingGroupSubResourceNoPath(name); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
testsuite/integration-tests/src/test/resources/org/jboss/resteasy/test/resource/path/web.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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<web-app | ||
xmlns="http://xmlns.jcp.org/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" | ||
version="3.1"> | ||
|
||
<servlet-mapping> | ||
<servlet-name>javax.ws.rs.core.Application</servlet-name> | ||
<url-pattern>/*</url-pattern> | ||
</servlet-mapping> | ||
|
||
</web-app> |