01: // Copyright 2006, 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.services;
16:
17: import java.io.IOException;
18: import java.util.Locale;
19:
20: import org.apache.tapestry.services.Request;
21: import org.apache.tapestry.services.RequestFilter;
22: import org.apache.tapestry.services.RequestHandler;
23: import org.apache.tapestry.services.Response;
24: import org.apache.tapestry.test.TapestryTestCase;
25: import org.testng.annotations.Test;
26:
27: public class LocalizationFilterTest extends TapestryTestCase {
28: @Test
29: public void set_locale_and_service() throws IOException {
30: RequestHandler handler = mockRequestHandler();
31: Request request = mockRequest();
32: Response response = mockResponse();
33: LocalizationSetter setter = newMock(LocalizationSetter.class);
34:
35: train_getLocale(request, Locale.CANADA_FRENCH);
36:
37: // We don't actually verify that setThreadLocale() occurs before service(),
38: // but sometimes you just have to trust that the code executes in the
39: // order its written.
40: setter.setThreadLocale(Locale.CANADA_FRENCH);
41:
42: train_service(handler, request, response, true);
43:
44: replay();
45:
46: RequestFilter filter = new LocalizationFilter(setter);
47:
48: assertTrue(filter.service(request, response, handler));
49:
50: verify();
51: }
52:
53: }
|