001 // Copyright 2005 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.valid; 016 017 import static org.easymock.EasyMock.expect; 018 019 import org.apache.hivemind.Location; 020 import org.apache.hivemind.lib.BeanFactory; 021 import org.apache.tapestry.BaseComponentTestCase; 022 import org.apache.tapestry.IBinding; 023 import org.apache.tapestry.coerce.ValueConverter; 024 import org.apache.tapestry.engine.IScriptSource; 025 import org.testng.annotations.Test; 026 027 /** 028 * Tests for {@link org.apache.tapestry.valid.ValidatorBindingFactory}. 029 * 030 * @author Howard M. Lewis Ship 031 * @since 4.0 032 */ 033 @Test 034 public class TestValidatorBindingFactory extends BaseComponentTestCase 035 { 036 public void testFactory() 037 { 038 IValidator validator = newMock(IValidator.class); 039 ValueConverter vc = newMock(ValueConverter.class); 040 041 BeanFactory vbf = newMock(BeanFactory.class); 042 043 IScriptSource scriptSource = newMock(IScriptSource.class); 044 045 expect(vbf.get("foo,bar=baz")).andReturn(validator); 046 047 Location l = newLocation(); 048 049 validator.setScriptSource(scriptSource); 050 051 replay(); 052 053 ValidatorBindingFactory factory = new ValidatorBindingFactory(); 054 factory.setValueConverter(vc); 055 factory.setValidatorBeanFactory(vbf); 056 factory.setScriptSource(scriptSource); 057 058 IBinding binding = factory.createBinding(null, "validator bean", "foo,bar=baz", l); 059 060 assertSame(validator, binding.getObject()); 061 assertSame(l, binding.getLocation()); 062 063 verify(); 064 } 065 }