1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.rest.mock2;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import org.apache.juneau.*;
23 import org.apache.juneau.rest.mock.*;
24 import org.junit.jupiter.api.*;
25
26 class MockServletRequest_Test extends TestBase {
27
28
29
30
31
32 @Test void a01_uris_basic() {
33 var req = MockServletRequest.create("GET", "/foo");
34 assertBean(
35 req,
36 "contextPath,pathInfo,pathTranslated,queryString,requestURI,requestURL,servletPath",
37 ",/foo,/mock-path/foo,<null>,/foo,/foo,"
38 );
39 }
40
41 @Test void a02_uris_full() {
42 var req = MockServletRequest.create("GET", "http://localhost:8080/foo?bar=baz#quz");
43 assertBean(
44 req,
45 "contextPath,pathInfo,pathTranslated,queryString,requestURI,requestURL,servletPath",
46 ",/foo,/mock-path/foo,bar=baz,/foo,http://localhost:8080/foo,"
47 );
48 }
49
50 @Test void a03_uris_full2() {
51 var req = MockServletRequest.create("GET", "http://localhost:8080/foo/bar/baz?bar=baz#quz");
52 assertBean(
53 req,
54 "contextPath,pathInfo,pathTranslated,queryString,requestURI,requestURL,servletPath",
55 ",/foo/bar/baz,/mock-path/foo/bar/baz,bar=baz,/foo/bar/baz,http://localhost:8080/foo/bar/baz,"
56 );
57 }
58
59 @Test void a04_uris_contextPath() {
60 var req = MockServletRequest.create("GET", "http://localhost:8080/foo/bar/baz?bar=baz#quz").contextPath("/foo");
61 assertBean(
62 req,
63 "contextPath,pathInfo,pathTranslated,queryString,requestURI,requestURL,servletPath",
64 "/foo,/bar/baz,/mock-path/bar/baz,bar=baz,/foo/bar/baz,http://localhost:8080/foo/bar/baz,"
65 );
66 }
67
68 @Test void a05_uris_servletPath() {
69 assertBean(
70 MockServletRequest.create("GET", "http://localhost:8080/foo/bar/baz?bar=baz#quz").servletPath("/foo"),
71 "contextPath,pathInfo,pathTranslated,queryString,requestURI,requestURL,servletPath",
72 ",/bar/baz,/mock-path/bar/baz,bar=baz,/foo/bar/baz,http://localhost:8080/foo/bar/baz,/foo"
73 );
74 }
75
76
77
78
79
80 @Test void b01_query_basic() {
81 var req = MockServletRequest.create("GET", "/foo?bar=baz&bing=qux");
82 assertBean(
83 req,
84 "queryString,parameterMap,parameterNames",
85 "bar=baz&bing=qux,{bar=[baz],bing=[qux]},[bar,bing]"
86 );
87 assertEquals("baz", req.getParameter("bar"));
88 assertList(req.getParameterValues("bar"), "baz");
89 }
90
91 @Test void b02_query_multivalues() {
92 var req = MockServletRequest.create("GET", "/foo?bar=baz&bar=bing");
93 assertBean(
94 req,
95 "queryString,parameterMap,parameterNames",
96 "bar=baz&bar=bing,{bar=[baz,bing]},[bar]"
97 );
98 assertEquals("baz", req.getParameter("bar"));
99 assertList(req.getParameterValues("bar"), "baz", "bing");
100 }
101 }