Consistent spelling for StandaloneMockMvcBuilder's addPlaceholderValue

This commit is contained in:
Juergen Hoeller 2016-08-10 14:18:41 +02:00
parent 02e9477711
commit a4b6682c3e
2 changed files with 20 additions and 27 deletions

View File

@ -119,7 +119,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
private Boolean removeSemicolonContent; private Boolean removeSemicolonContent;
private Map<String, String> placeHolderValues = new HashMap<>(); private Map<String, String> placeholderValues = new HashMap<>();
/** /**
@ -317,9 +317,10 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
* request mappings. This method allows manually provided placeholder values so they * request mappings. This method allows manually provided placeholder values so they
* can be resolved. Alternatively consider creating a test that initializes a * can be resolved. Alternatively consider creating a test that initializes a
* {@link WebApplicationContext}. * {@link WebApplicationContext}.
* @since 4.2.8
*/ */
public StandaloneMockMvcBuilder addPlaceHolderValue(String name, String value) { public StandaloneMockMvcBuilder addPlaceholderValue(String name, String value) {
this.placeHolderValues.put(name, value); this.placeholderValues.put(name, value);
return this; return this;
} }
@ -364,8 +365,8 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
} }
private List<ViewResolver> initViewResolvers(WebApplicationContext wac) { private List<ViewResolver> initViewResolvers(WebApplicationContext wac) {
this.viewResolvers = (this.viewResolvers == null) ? this.viewResolvers = (this.viewResolvers != null ? this.viewResolvers :
Arrays.<ViewResolver>asList(new InternalResourceViewResolver()) : this.viewResolvers; Collections.<ViewResolver>singletonList(new InternalResourceViewResolver()));
for (Object viewResolver : this.viewResolvers) { for (Object viewResolver : this.viewResolvers) {
if (viewResolver instanceof WebApplicationObjectSupport) { if (viewResolver instanceof WebApplicationObjectSupport) {
((WebApplicationObjectSupport) viewResolver).setApplicationContext(wac); ((WebApplicationObjectSupport) viewResolver).setApplicationContext(wac);
@ -380,7 +381,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
public StaticRequestMappingHandlerMapping getHandlerMapping() { public StaticRequestMappingHandlerMapping getHandlerMapping() {
StaticRequestMappingHandlerMapping handlerMapping = new StaticRequestMappingHandlerMapping(); StaticRequestMappingHandlerMapping handlerMapping = new StaticRequestMappingHandlerMapping();
handlerMapping.setEmbeddedValueResolver(new StaticStringValueResolver(placeHolderValues)); handlerMapping.setEmbeddedValueResolver(new StaticStringValueResolver(placeholderValues));
handlerMapping.setUseSuffixPatternMatch(useSuffixPatternMatch); handlerMapping.setUseSuffixPatternMatch(useSuffixPatternMatch);
handlerMapping.setUseTrailingSlashMatch(useTrailingSlashPatternMatch); handlerMapping.setUseTrailingSlashMatch(useTrailingSlashPatternMatch);
handlerMapping.setOrder(0); handlerMapping.setOrder(0);
@ -440,8 +441,8 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
try { try {
((InitializingBean) mvcValidator).afterPropertiesSet(); ((InitializingBean) mvcValidator).afterPropertiesSet();
} }
catch (Exception e) { catch (Exception ex) {
throw new BeanInitializationException("Failed to initialize Validator", e); throw new BeanInitializationException("Failed to initialize Validator", ex);
} }
} }
return mvcValidator; return mvcValidator;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -23,6 +23,8 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.converter.json.SpringHandlerInstantiator; import org.springframework.http.converter.json.SpringHandlerInstantiator;
@ -36,9 +38,6 @@ import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ser.impl.UnknownSerializer;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
@ -50,12 +49,10 @@ import static org.junit.Assert.*;
*/ */
public class StandaloneMockMvcBuilderTests { public class StandaloneMockMvcBuilderTests {
// SPR-10825 @Test // SPR-10825
@Test
public void placeHoldersInRequestMapping() throws Exception { public void placeHoldersInRequestMapping() throws Exception {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController()); TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
builder.addPlaceHolderValue("sys.login.ajax", "/foo"); builder.addPlaceholderValue("sys.login.ajax", "/foo");
builder.build(); builder.build();
RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class); RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class);
@ -67,9 +64,7 @@ public class StandaloneMockMvcBuilderTests {
assertEquals("handleWithPlaceholders", ((HandlerMethod) chain.getHandler()).getMethod().getName()); assertEquals("handleWithPlaceholders", ((HandlerMethod) chain.getHandler()).getMethod().getName());
} }
// SPR-13637 @Test // SPR-13637
@Test
public void suffixPatternMatch() throws Exception { public void suffixPatternMatch() throws Exception {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController()); TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
builder.setUseSuffixPatternMatch(false); builder.setUseSuffixPatternMatch(false);
@ -87,18 +82,15 @@ public class StandaloneMockMvcBuilderTests {
assertNull(chain); assertNull(chain);
} }
// SPR-12553 @Test // SPR-12553
@Test
public void applicationContextAttribute() { public void applicationContextAttribute() {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController()); TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PlaceholderController());
builder.addPlaceHolderValue("sys.login.ajax", "/foo"); builder.addPlaceholderValue("sys.login.ajax", "/foo");
WebApplicationContext wac = builder.initWebAppContext(); WebApplicationContext wac = builder.initWebAppContext();
assertEquals(wac, WebApplicationContextUtils assertEquals(wac, WebApplicationContextUtils
.getRequiredWebApplicationContext(wac.getServletContext())); .getRequiredWebApplicationContext(wac.getServletContext()));
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void addFiltersFiltersNull() { public void addFiltersFiltersNull() {
StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController()); StandaloneMockMvcBuilder builder = MockMvcBuilders.standaloneSetup(new PersonController());
@ -123,9 +115,7 @@ public class StandaloneMockMvcBuilderTests {
builder.addFilter(new ContinueFilter(), (String) null); builder.addFilter(new ContinueFilter(), (String) null);
} }
// SPR-13375 @Test // SPR-13375
@Test
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public void springHandlerInstantiator() { public void springHandlerInstantiator() {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController()); TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
@ -159,6 +149,7 @@ public class StandaloneMockMvcBuilderTests {
} }
} }
@Controller @Controller
private static class PersonController { private static class PersonController {
@ -173,6 +164,7 @@ public class StandaloneMockMvcBuilderTests {
} }
} }
private class ContinueFilter extends OncePerRequestFilter { private class ContinueFilter extends OncePerRequestFilter {
@Override @Override