|
4 | 4 | import static org.junit.Assert.assertEquals; |
5 | 5 |
|
6 | 6 | import java.io.IOException; |
| 7 | +import java.util.Arrays; |
| 8 | +import java.util.Collections; |
| 9 | +import java.util.UUID; |
7 | 10 |
|
8 | 11 | import javax.servlet.ServletException; |
9 | 12 | import javax.servlet.http.HttpServletRequest; |
10 | 13 |
|
| 14 | +import com.google.common.collect.ImmutableMap; |
11 | 15 | import org.jooby.MediaType; |
12 | 16 | import org.jooby.test.MockUnit; |
13 | 17 | import org.junit.Test; |
@@ -148,6 +152,45 @@ public void noparams() throws IOException, Exception { |
148 | 152 |
|
149 | 153 | } |
150 | 154 |
|
| 155 | + @Test |
| 156 | + public void attributes() throws Exception { |
| 157 | + String tmpdir = System.getProperty("java.io.tmpdir"); |
| 158 | + final UUID serverAttribute = UUID.randomUUID(); |
| 159 | + new MockUnit(HttpServletRequest.class) |
| 160 | + .expect(unit -> { |
| 161 | + HttpServletRequest req = unit.get(HttpServletRequest.class); |
| 162 | + expect(req.getContentType()).andReturn("text/html"); |
| 163 | + expect(req.getPathInfo()).andReturn("/"); |
| 164 | + expect(req.getAttributeNames()).andReturn( |
| 165 | + Collections.enumeration(Collections.singletonList("server.attribute"))); |
| 166 | + expect(req.getAttribute("server.attribute")).andReturn(serverAttribute); |
| 167 | + }) |
| 168 | + .run(unit -> { |
| 169 | + assertEquals(ImmutableMap.of("server.attribute", serverAttribute), |
| 170 | + new ServletServletRequest(unit.get(HttpServletRequest.class), tmpdir) |
| 171 | + .attributes()); |
| 172 | + }); |
| 173 | + |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void emptyAttributes() throws Exception { |
| 178 | + String tmpdir = System.getProperty("java.io.tmpdir"); |
| 179 | + new MockUnit(HttpServletRequest.class) |
| 180 | + .expect(unit -> { |
| 181 | + HttpServletRequest req = unit.get(HttpServletRequest.class); |
| 182 | + expect(req.getContentType()).andReturn("text/html"); |
| 183 | + expect(req.getPathInfo()).andReturn("/"); |
| 184 | + expect(req.getAttributeNames()).andReturn(Collections.emptyEnumeration()); |
| 185 | + }) |
| 186 | + .run(unit -> { |
| 187 | + assertEquals(Collections.emptyMap(), |
| 188 | + new ServletServletRequest(unit.get(HttpServletRequest.class), tmpdir) |
| 189 | + .attributes()); |
| 190 | + }); |
| 191 | + |
| 192 | + } |
| 193 | + |
151 | 194 | @Test(expected = IOException.class) |
152 | 195 | public void filesFailure() throws IOException, Exception { |
153 | 196 | String tmpdir = System.getProperty("java.io.tmpdir"); |
|
0 commit comments