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.InternalComponentResources;
020: import org.apache.tapestry.internal.services.Instantiator;
021: import org.apache.tapestry.internal.test.InternalBaseTestCase;
022: import org.apache.tapestry.ioc.services.TypeCoercer;
023: import org.apache.tapestry.model.ComponentModel;
024: import org.apache.tapestry.model.ParameterModel;
025: import org.apache.tapestry.runtime.Component;
026: import org.testng.annotations.Test;
027:
028: public class InternalComponentResourcesImplTest extends
029: InternalBaseTestCase {
030: @Test
031: public void render_informal_parameters_no_bindings() {
032: ComponentPageElement element = mockComponentPageElement();
033: Component component = mockComponent();
034: Instantiator ins = mockInstantiator(component);
035: MarkupWriter writer = mockMarkupWriter();
036: TypeCoercer coercer = mockTypeCoercer();
037: ComponentModel model = mockComponentModel();
038:
039: train_getModel(ins, model);
040:
041: replay();
042:
043: InternalComponentResources resources = new InternalComponentResourcesImpl(
044: element, null, ins, coercer, null);
045:
046: resources.renderInformalParameters(writer);
047:
048: verify();
049: }
050:
051: @Test
052: public void render_informal_parameters_skips_formal_parameters() {
053: ComponentPageElement element = mockComponentPageElement();
054: Component component = mockComponent();
055: Instantiator ins = mockInstantiator(component);
056: MarkupWriter writer = mockMarkupWriter();
057: TypeCoercer coercer = mockTypeCoercer();
058: ComponentModel model = mockComponentModel();
059: ParameterModel pmodel = mockParameterModel();
060: Binding binding = mockBinding();
061:
062: train_getModel(ins, model);
063:
064: train_getParameterModel(model, "fred", pmodel);
065:
066: replay();
067:
068: InternalComponentResources resources = new InternalComponentResourcesImpl(
069: element, null, ins, coercer, null);
070:
071: resources.bindParameter("fred", binding);
072:
073: resources.renderInformalParameters(writer);
074:
075: verify();
076: }
077:
078: @Test
079: public void render_an_informal_parameter() {
080: ComponentPageElement element = mockComponentPageElement();
081: Component component = mockComponent();
082: Instantiator ins = mockInstantiator(component);
083: MarkupWriter writer = mockMarkupWriter();
084: TypeCoercer coercer = mockTypeCoercer();
085: ComponentModel model = mockComponentModel();
086: Binding binding = mockBinding();
087: Object rawValue = new Object();
088: String convertedValue = "*converted*";
089:
090: train_getModel(ins, model);
091:
092: train_getParameterModel(model, "fred", null);
093:
094: train_get(binding, rawValue);
095:
096: train_coerce(coercer, rawValue, String.class, convertedValue);
097:
098: writer.attributes("fred", convertedValue);
099:
100: replay();
101:
102: InternalComponentResources resources = new InternalComponentResourcesImpl(
103: element, null, ins, coercer, null);
104:
105: resources.bindParameter("fred", binding);
106:
107: resources.renderInformalParameters(writer);
108:
109: verify();
110: }
111: }
|