|
31 | 31 | public class ExplorerHandlerTest { |
32 | 32 | @Test |
33 | 33 | public void testHandle() throws Exception { |
| 34 | + testHandle("http", 8080, "http://apis-explorer.appspot.com/apis-explorer/" |
| 35 | + + "?base=http://localhost:8080/_ah/api&root=http://localhost:8080/_ah/api"); |
| 36 | + } |
| 37 | + |
| 38 | + @Test |
| 39 | + public void testHandle_explicitHttpPort() throws Exception { |
| 40 | + testHandle("http", 80, "http://apis-explorer.appspot.com/apis-explorer/" |
| 41 | + + "?base=http://localhost/_ah/api&root=http://localhost/_ah/api"); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testHandle_explicitHttpsPort() throws Exception { |
| 46 | + testHandle("https", 443, "http://apis-explorer.appspot.com/apis-explorer/" |
| 47 | + + "?base=https://localhost/_ah/api&root=https://localhost/_ah/api"); |
| 48 | + } |
| 49 | + |
| 50 | + private void testHandle(String scheme, int port, String expectedLocation) throws Exception { |
34 | 51 | MockHttpServletRequest request = new MockHttpServletRequest(); |
| 52 | + request.setScheme(scheme); |
35 | 53 | request.setServerName("localhost"); |
36 | | - request.setServerPort(8080); |
| 54 | + request.setServerPort(port); |
37 | 55 | request.setRequestURI("/_ah/api/explorer/"); |
38 | 56 | MockHttpServletResponse response = new MockHttpServletResponse(); |
39 | 57 | ExplorerHandler handler = new ExplorerHandler(); |
40 | 58 | EndpointsContext context = new EndpointsContext("GET", "explorer", request, response); |
41 | 59 | handler.handle(context); |
42 | 60 |
|
43 | 61 | assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_FOUND); |
44 | | - assertThat(response.getHeader("Location")).isEqualTo( |
45 | | - "http://apis-explorer.appspot.com/apis-explorer/?base=http://localhost:8080/_ah/api" |
46 | | - + "&root=http://localhost:8080/_ah/api"); |
| 62 | + assertThat(response.getHeader("Location")).isEqualTo(expectedLocation); |
47 | 63 | } |
48 | 64 | } |
0 commit comments