FileDocCategorySizeDatePackage
TestPropertyInjector.javaAPI DocApache Lucene 2.1.05357Wed Feb 14 10:46:02 GMT 2007org.apache.lucene.gdata.server.registry.configuration

TestPropertyInjector

public class TestPropertyInjector extends TestCase
Copyright 2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Fields Summary
private PropertyInjector
injector
Constructors Summary
Methods Summary
protected voidsetUp()

        super.setUp();
        this.injector = new PropertyInjector();
    
protected voidtearDown()

        super.tearDown();
    
public voidtestInjectProperties()

        ComponentConfiguration bean = new ComponentConfiguration();
        bean.set("someValue","bla");
        try{
            this.injector.injectProperties(bean);
            fail("target is not set");
            }catch (IllegalStateException e) {
          
            }
        TestBean testBean = new TestBean();
        this.injector.setTargetObject(testBean);
        try{
            this.injector.injectProperties(null);
            fail("object is null");
            }catch (IllegalArgumentException e) {
          
            }
        try{
        this.injector.injectProperties(bean);
        fail("requiered Property is not available in config bean");
        }catch (InjectionException e) {
          
        }
        
        bean.set("test","fooBar");
        bean.set("testClass","java.lang.Object");
        this.injector.injectProperties(bean);
        
        assertEquals("fooBar",testBean.getTest());
        assertEquals(Object.class,testBean.getTestClass());
        
        
        
        this.injector = new PropertyInjector();
        SubTestBean subTestBean = new SubTestBean();
        this.injector.setTargetObject(subTestBean);
        bean.set("number","333");
        this.injector.injectProperties(bean);
        
        assertEquals("fooBar",subTestBean.getTest());
        assertEquals(Object.class,subTestBean.getTestClass());
        assertEquals(333,subTestBean.getNumber());
        
        bean = new ComponentConfiguration();
        bean.set("test","fooBar");
        bean.set("number","333");
        bean.set("wrapper","1.2");
       
        subTestBean = new SubTestBean();
        this.injector.setTargetObject(subTestBean);
        this.injector.injectProperties(bean);
        
        assertEquals("fooBar",subTestBean.getTest());
        assertEquals(333,subTestBean.getNumber());
        assertEquals(new Float(1.2),subTestBean.getWrapper());
    

    
public voidtestSetTargetObject()

        try {
            this.injector.setTargetObject(null);
            fail("must not be null");
        } catch (IllegalArgumentException e) {
            // TODO: handle exception
        }
        try {
            this.injector.setTargetObject(new Object());
            fail("no getter or setter methodes");
        } catch (InjectionException e) {
            // TODO: handle exception
        }
      
       this.injector.setTargetObject(new TestBean());
       assertEquals(1,this.injector.getOptionalSize());
       assertEquals(1,this.injector.getRequiredSize());