Support placeholder values in Spring MVC Test

Issue: SPR-10825
This commit is contained in:
Rossen Stoyanchev
2013-08-22 14:54:02 -04:00
parent 47d40053a4
commit c211c98b40
2 changed files with 121 additions and 13 deletions

View File

@@ -0,0 +1,64 @@
/*
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.test.web.servlet.setup;
import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockServletContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import static org.junit.Assert.*;
/**
* @author Rossen Stoyanchev
*/
public class StandaloneMockMvcBuilderTests {
// SPR-10825
@Test
public void placeHoldersInRequestMapping() throws Exception {
StubWebApplicationContext cxt = new StubWebApplicationContext(new MockServletContext());
StandaloneMockMvcBuilder builder = new StandaloneMockMvcBuilder(new PlaceholderController());
builder.addPlaceHolderValues("sys.login.ajax", "/foo");
builder.initWebAppContext(cxt);
RequestMappingHandlerMapping hm = cxt.getBean(RequestMappingHandlerMapping.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo");
HandlerExecutionChain chain = hm.getHandler(request);
assertNotNull(chain);
assertEquals("handleWithPlaceholders", ((HandlerMethod) chain.getHandler()).getMethod().getName());
}
@Controller
private static class PlaceholderController {
@RequestMapping(value = "${sys.login.ajax}")
private void handleWithPlaceholders() { }
}
}