Package org.strecks.util

Source Code of org.strecks.util.TestPropertyValueGetter

/*
* Copyright 2005-2006 the original author or authors.
*
* 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.
*/

package org.strecks.util;

import org.strecks.bind.handler.impl.BindableBean;
import org.strecks.bind.handler.impl.DomainClass;
import org.strecks.bind.handler.impl.TargetBean;
import org.strecks.exceptions.ApplicationRuntimeException;
import org.strecks.util.impl.JavaBean;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
* @author Phil Zoio
*/
public class TestPropertyValueGetter
{

  @Test
  public void testPropertyValueGetter1() throws Exception
  {
    JavaBean bean = new JavaBean();
    bean.setStringProperty("stringval");
    bean.setBooleanProperty(true);

    Assert.assertEquals(PropertyValueGetter.getPropertyValue(bean, "stringProperty"), "stringval");
    Assert.assertEquals(PropertyValueGetter.getPropertyValue(bean, "booleanProperty"), true);
  }

  @Test
  public void testPropertyValueGetterUnknown() throws Exception
  {
    JavaBean bean = new JavaBean();

    try
    {
      PropertyValueGetter.getPropertyValue(bean, "unknownProperty");
    }
    catch (ApplicationRuntimeException e)
    {
      Assert.assertEquals(e.getMessage(),
          "Required getter methods not found from class org.strecks.util.impl.JavaBean using property expression unknownProperty");
    }
  }

  @Test
  public void testGetPropertyDescriptor() throws Exception
  {
    JavaBean bean = new JavaBean();
    assert null != PropertyValueGetter.getPropertyDescriptor(bean, "stringProperty");
    assert null != PropertyValueGetter.getPropertyDescriptor(bean, "booleanProperty");

  }

  @Test
  public void testPropertyDescriptorGetterUnknown() throws Exception
  {
    JavaBean bean = new JavaBean();

    try
    {
      PropertyValueGetter.getPropertyDescriptor(bean, "unknownProperty");
    }
    catch (ApplicationRuntimeException e)
    {
      Assert
          .assertEquals(e.getMessage(),
              "Unable to read property descriptor for bean org.strecks.util.impl.JavaBean, property unknownProperty");
    }
  }

  @Test
  public void testGetSilentPropertyDescriptor() throws Exception
  {
    JavaBean bean = new JavaBean();
    assert null != PropertyValueGetter.getPropertyDescriptorSilently(bean, "stringProperty");
    assert null == PropertyValueGetter.getPropertyDescriptorSilently(bean, "unknownProperty");

  }

  @Test
  public void testGetSilentPropertyClass() throws Exception
  {
    JavaBean bean = new JavaBean();
    assert null != PropertyValueGetter.getPropertyTypeSilently(bean, "stringProperty");
    assert null == PropertyValueGetter.getPropertyTypeSilently(bean, "unknownProperty");

  }

  @Test
  public void testGetTargetBean()
  {

    TargetBean bean = new TargetBean();
    bean.setStringProperty("2");
    BindableBean form = new BindableBean();
    form.setTargetBean(bean);
    DomainClass domclass = new DomainClass(1);
    bean.setDomainClass(domclass);

    Object targetBean = PropertyValueGetter.getTargetBean(form, "targetBean");
    assert targetBean instanceof TargetBean;

    targetBean = PropertyValueGetter.getTargetBean(form, "targetBean.domainClass");
    assert targetBean instanceof DomainClass;

    bean.setDomainClass(null);
    assert null == PropertyValueGetter.getTargetBean(form, "targetBean.domainClass");

    form.setTargetBean(null);
    assert null == PropertyValueGetter.getTargetBean(form, "targetBean.domainClass");
    assert null == PropertyValueGetter.getTargetBean(form, "targetBean");

  }

}
TOP

Related Classes of org.strecks.util.TestPropertyValueGetter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.