|
| 1 | +/* |
| 2 | + * Copyright 2012-2015 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.security.oauth2.provider.endpoint; |
| 18 | + |
| 19 | +import static org.junit.Assert.assertEquals; |
| 20 | + |
| 21 | +import java.util.Collections; |
| 22 | +import java.util.HashMap; |
| 23 | +import java.util.Map; |
| 24 | + |
| 25 | +import org.junit.Test; |
| 26 | +import org.springframework.mock.web.MockHttpServletRequest; |
| 27 | +import org.springframework.mock.web.MockHttpServletResponse; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author Dave Syer |
| 31 | + * |
| 32 | + */ |
| 33 | +public class SpelViewTests { |
| 34 | + |
| 35 | + private SpelView view; |
| 36 | + |
| 37 | + private MockHttpServletResponse response = new MockHttpServletResponse(); |
| 38 | + private MockHttpServletRequest request = new MockHttpServletRequest(); |
| 39 | + |
| 40 | + @Test |
| 41 | + public void sunnyDay() throws Exception { |
| 42 | + view = new SpelView("${hit}"); |
| 43 | + view.render(Collections.singletonMap("hit", "Ouch"), request, response); |
| 44 | + assertEquals("Ouch", response.getContentAsString()); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void nonRecursive() throws Exception { |
| 49 | + view = new SpelView("${hit}"); |
| 50 | + view.render(Collections.singletonMap("hit", "${ouch}"), request, response); |
| 51 | + // Expressions embedded in resolved values do not resolve recursively |
| 52 | + assertEquals("${ouch}", response.getContentAsString()); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void recursive() throws Exception { |
| 57 | + // Recursive expressions in the template resolve |
| 58 | + view = new SpelView("${${hit}}"); |
| 59 | + Map<String,Object> map = new HashMap<String, Object>(); |
| 60 | + map.put("hit", "me"); |
| 61 | + map.put("me", "${ouch}"); |
| 62 | + view.render(map, request, response); |
| 63 | + // But expressions embedded in resolved values do not |
| 64 | + assertEquals("${ouch}", response.getContentAsString()); |
| 65 | + } |
| 66 | + |
| 67 | +} |
0 commit comments