Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andy McCright <j.andrew.mccright@gmail.com>
- Loading branch information
Showing
3 changed files
with
157 additions
and
8 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
107 changes: 107 additions & 0 deletions
107
resteasy-core/src/test/java/org/jboss/resteasy/plugins/server/servlet/ServletUtilTest.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,107 @@ | ||
package org.jboss.resteasy.plugins.server.servlet; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.jboss.resteasy.specimpl.ResteasyUriInfo; | ||
import org.junit.Test; | ||
|
||
public class ServletUtilTest { | ||
|
||
@Test | ||
public void extractUriInfo_simple() { | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn(""); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app/resource")); | ||
ResteasyUriInfo rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("", rui.getContextPath()); | ||
assertEquals("/app/resource", rui.getPath()); | ||
} | ||
|
||
@Test | ||
public void extractUriInfo_simpleWithContextRoot() { | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn("/contextRoot"); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/contextRoot/app/resource")); | ||
ResteasyUriInfo rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("/contextRoot", rui.getContextPath()); | ||
assertEquals("/app/resource", rui.getPath()); | ||
} | ||
|
||
@Test | ||
public void extractUriInfo_encoded() | ||
{ | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn(""); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app/resource!")); | ||
ResteasyUriInfo rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("", rui.getContextPath()); | ||
assertEquals("/app/resource!", rui.getPath()); | ||
|
||
request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn(""); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app/resource%21")); | ||
rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("", rui.getContextPath()); | ||
assertEquals("/app/resource!", rui.getPath()); | ||
|
||
request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn(""); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app!/resource")); | ||
rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("", rui.getContextPath()); | ||
assertEquals("/app!/resource", rui.getPath()); | ||
|
||
request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn(""); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/app%21/resource")); | ||
rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("", rui.getContextPath()); | ||
assertEquals("/app!/resource", rui.getPath()); | ||
} | ||
|
||
@Test | ||
public void extractUriInfo_encodedWithContextRoot() | ||
{ | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn("/contextRoot"); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/contextRoot/app/resource!")); | ||
ResteasyUriInfo rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("/contextRoot", rui.getContextPath()); | ||
assertEquals("/app/resource!", rui.getPath()); | ||
|
||
request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn("/contextRoot"); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/contextRoot/app/resource%21")); | ||
rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("/contextRoot", rui.getContextPath()); | ||
assertEquals("/app/resource!", rui.getPath()); | ||
|
||
request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn("/contextRoot"); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/contextRoot/app!/resource")); | ||
rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("/contextRoot", rui.getContextPath()); | ||
assertEquals("/app!/resource", rui.getPath()); | ||
|
||
request = mock(HttpServletRequest.class); | ||
when(request.getContextPath()).thenReturn("/contextRoot"); | ||
when(request.getQueryString()).thenReturn(null); | ||
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8000/contextRoot/app%21/resource")); | ||
rui = ServletUtil.extractUriInfo(request, null); | ||
assertEquals("/contextRoot", rui.getContextPath()); | ||
assertEquals("/app!/resource", rui.getPath()); | ||
} | ||
} |