001: // Copyright 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.internal.services;
016:
017: import org.apache.tapestry.TapestryConstants;
018: import org.apache.tapestry.internal.InternalComponentResources;
019: import org.apache.tapestry.internal.structure.ComponentPageElement;
020: import org.apache.tapestry.internal.structure.Page;
021: import org.apache.tapestry.internal.test.InternalBaseTestCase;
022: import org.apache.tapestry.services.MetaDataLocator;
023: import org.apache.tapestry.services.Request;
024: import org.testng.annotations.Test;
025:
026: public class RequestEncodingInitializerImplTest extends
027: InternalBaseTestCase {
028: @Test
029: public void encoding_in_content_type() {
030: RequestPageCache cache = mockRequestPageCache();
031: Page page = mockPage();
032: ComponentPageElement element = mockComponentPageElement();
033: InternalComponentResources resources = mockInternalComponentResources();
034: MetaDataLocator locator = mockMetaDataLocator();
035: Request request = mockRequest();
036: String pageName = "MyPage";
037:
038: train_get(cache, pageName, page);
039: train_getRootElement(page, element);
040: train_getComponentResources(element, resources);
041:
042: train_findMeta(locator,
043: TapestryConstants.RESPONSE_CONTENT_TYPE, resources,
044: "text/html;charset=zebra");
045:
046: request.setEncoding("zebra");
047:
048: replay();
049:
050: RequestEncodingInitializer init = new RequestEncodingInitializerImpl(
051: cache, locator, request);
052:
053: init.initializeRequestEncoding(pageName);
054:
055: verify();
056: }
057:
058: @Test
059: public void encoding_on_second_meta_data() {
060: RequestPageCache cache = mockRequestPageCache();
061: Page page = mockPage();
062: ComponentPageElement element = mockComponentPageElement();
063: InternalComponentResources resources = mockInternalComponentResources();
064: MetaDataLocator locator = mockMetaDataLocator();
065: Request request = mockRequest();
066: String pageName = "MyPage";
067: String encoding = "ostritch";
068:
069: train_get(cache, pageName, page);
070: train_getRootElement(page, element);
071: train_getComponentResources(element, resources);
072:
073: train_findMeta(locator,
074: TapestryConstants.RESPONSE_CONTENT_TYPE, resources,
075: "text/html");
076:
077: train_findMeta(locator, TapestryConstants.RESPONSE_ENCODING,
078: resources, encoding);
079:
080: request.setEncoding(encoding);
081:
082: replay();
083:
084: RequestEncodingInitializer init = new RequestEncodingInitializerImpl(
085: cache, locator, request);
086:
087: init.initializeRequestEncoding(pageName);
088:
089: verify();
090: }
091:
092: protected final void train_findMeta(MetaDataLocator locator,
093: String metaDataKey, InternalComponentResources resources,
094: String metaDataValue) {
095: expect(locator.findMeta(metaDataKey, resources)).andReturn(
096: metaDataValue);
097: }
098:
099: protected final MetaDataLocator mockMetaDataLocator() {
100: return newMock(MetaDataLocator.class);
101: }
102:
103: }
|