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.ioc.internal;
016:
017: import java.lang.reflect.Method;
018:
019: import org.apache.commons.logging.Log;
020: import org.apache.tapestry.ioc.OrderedConfiguration;
021: import org.apache.tapestry.ioc.def.ContributionDef;
022: import org.testng.annotations.Test;
023:
024: public class ValidatingOrderedConfigurationWrapperTest extends
025: IOCInternalTestCase {
026: @Test
027: public void valid_type_long_form() {
028: ContributionDef def = mockContributionDef();
029: Log log = mockLog();
030: OrderedConfiguration<Runnable> configuration = mockOrderedConfiguration();
031: Runnable contribution = mockRunnable();
032:
033: configuration.add("id", contribution, "after:pre",
034: "before:post");
035:
036: replay();
037:
038: OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(
039: "Service", def, log, Runnable.class, configuration);
040:
041: wrapper.add("id", contribution, "after:pre", "before:post");
042:
043: verify();
044: }
045:
046: @Test
047: public void valid_type_short_form() {
048: ContributionDef def = mockContributionDef();
049: Log log = mockLog();
050: OrderedConfiguration<Runnable> configuration = mockOrderedConfiguration();
051: Runnable contribution = mockRunnable();
052:
053: configuration.add("id", contribution);
054:
055: replay();
056:
057: OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(
058: "Service", def, log, Runnable.class, configuration);
059:
060: wrapper.add("id", contribution);
061:
062: verify();
063: }
064:
065: @Test
066: public void null_object_passed_through() {
067: ContributionDef def = mockContributionDef();
068: Log log = mockLog();
069: OrderedConfiguration<Runnable> configuration = mockOrderedConfiguration();
070:
071: configuration.add("id", null);
072:
073: replay();
074:
075: OrderedConfiguration<Runnable> wrapper = new ValidatingOrderedConfigurationWrapper<Runnable>(
076: "Service", def, log, Runnable.class, configuration);
077:
078: wrapper.add("id", null);
079:
080: verify();
081: }
082:
083: @SuppressWarnings("unchecked")
084: @Test
085: public void incorrect_contribution_type_is_passed_through_as_null() {
086: Method method = findMethod("contributeBarneyService");
087:
088: ContributionDef def = new ContributionDefImpl("Service",
089: method, getClassFactory());
090: Log log = mockLog();
091: OrderedConfiguration<Runnable> configuration = mockOrderedConfiguration();
092:
093: log.warn(IOCMessages.contributionWrongValueType("Service", def,
094: String.class, Runnable.class));
095:
096: configuration.add("id", null);
097:
098: replay();
099:
100: OrderedConfiguration wrapper = new ValidatingOrderedConfigurationWrapper(
101: "Service", def, log, Runnable.class, configuration);
102:
103: wrapper.add("id", "string");
104:
105: verify();
106: }
107:
108: public void contributeBarneyService(
109: OrderedConfiguration<Runnable> configuration) {
110:
111: }
112: }
|