Java Code Examples for org.springframework.mock.web.test.MockHttpServletRequest#setPreferredLocales()

The following examples show how to use org.springframework.mock.web.test.MockHttpServletRequest#setPreferredLocales() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AcceptHeaderLocaleResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolvePreferredNotSupportedWithDefault() {
	this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
	this.resolver.setDefaultLocale(Locale.JAPAN);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addHeader("Accept-Language", KOREA.toLanguageTag());
	request.setPreferredLocales(Collections.singletonList(KOREA));
	assertEquals(Locale.JAPAN, this.resolver.resolveLocale(request));
}
 
Example 2
Source File: AcceptHeaderLocaleResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void defaultLocale() {
	this.resolver.setDefaultLocale(JAPANESE);
	MockHttpServletRequest request = new MockHttpServletRequest();
	assertEquals(JAPANESE, this.resolver.resolveLocale(request));

	request.addHeader("Accept-Language", US.toLanguageTag());
	request.setPreferredLocales(Collections.singletonList(US));
	assertEquals(US, this.resolver.resolveLocale(request));
}
 
Example 3
Source File: AcceptHeaderLocaleResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void resolvePreferredNotSupportedWithDefault() {
	this.resolver.setSupportedLocales(Arrays.asList(US, JAPAN));
	this.resolver.setDefaultLocale(Locale.JAPAN);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addHeader("Accept-Language", KOREA.toLanguageTag());
	request.setPreferredLocales(Collections.singletonList(KOREA));
	assertEquals(Locale.JAPAN, this.resolver.resolveLocale(request));
}
 
Example 4
Source File: AcceptHeaderLocaleResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void defaultLocale() {
	this.resolver.setDefaultLocale(JAPANESE);
	MockHttpServletRequest request = new MockHttpServletRequest();
	assertEquals(JAPANESE, this.resolver.resolveLocale(request));

	request.addHeader("Accept-Language", US.toLanguageTag());
	request.setPreferredLocales(Collections.singletonList(US));
	assertEquals(US, this.resolver.resolveLocale(request));
}
 
Example 5
Source File: GroovyMarkupViewTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private MockHttpServletResponse renderViewWithModel(String viewUrl, Map<String, Object> model, Locale locale) throws Exception {

		GroovyMarkupView view = createViewWithUrl(viewUrl);
		MockHttpServletResponse response = new MockHttpServletResponse();
		MockHttpServletRequest request = new MockHttpServletRequest();
		request.setPreferredLocales(Arrays.asList(locale));
		LocaleContextHolder.setLocale(locale);
		view.renderMergedTemplateModel(model, request, response);
		return response;
	}