001: // Copyright 2006, 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.structure;
016:
017: import org.apache.tapestry.Binding;
018: import org.apache.tapestry.MarkupWriter;
019: import org.apache.tapestry.internal.test.InternalBaseTestCase;
020: import org.apache.tapestry.ioc.services.TypeCoercer;
021: import org.apache.tapestry.runtime.RenderQueue;
022: import org.testng.annotations.Test;
023:
024: public class ExpansionPageElementImplTest extends InternalBaseTestCase {
025: @Test
026: public void invariant_binding_is_cached() {
027: Binding binding = mockBinding();
028: TypeCoercer coercer = mockTypeCoercer();
029: MarkupWriter writer = mockMarkupWriter();
030: RenderQueue queue = mockRenderQueue();
031:
032: Object value = new Object();
033:
034: train_isInvariant(binding, true);
035:
036: replay();
037:
038: PageElement element = new ExpansionPageElement(binding, coercer);
039:
040: verify();
041:
042: train_get(binding, value);
043: train_coerce(coercer, value, String.class, "STRING-VALUE");
044: writer.write("STRING-VALUE");
045:
046: replay();
047:
048: element.render(writer, queue);
049:
050: verify();
051:
052: // It is now cached ...
053:
054: writer.write("STRING-VALUE");
055:
056: replay();
057:
058: element.render(writer, queue);
059:
060: verify();
061: }
062:
063: @Test
064: public void variant_binding_is_not_cached() {
065: Binding binding = mockBinding();
066: TypeCoercer coercer = mockTypeCoercer();
067: MarkupWriter writer = mockMarkupWriter();
068: RenderQueue queue = mockRenderQueue();
069:
070: Object value = new Object();
071:
072: train_isInvariant(binding, false);
073:
074: replay();
075:
076: PageElement element = new ExpansionPageElement(binding, coercer);
077:
078: verify();
079:
080: train_get(binding, value);
081: train_coerce(coercer, value, String.class, "STRING-VALUE");
082: writer.write("STRING-VALUE");
083:
084: replay();
085:
086: element.render(writer, queue);
087:
088: verify();
089:
090: train_get(binding, value);
091: train_coerce(coercer, value, String.class, "STRING-VALUE2");
092: writer.write("STRING-VALUE2");
093:
094: replay();
095:
096: element.render(writer, queue);
097:
098: verify();
099: }
100: }
|