/*
* 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.form.controller;
import org.strecks.form.impl.NestedBean;
import org.strecks.form.impl.TestForm;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
/**
* @author Phil Zoio
*/
public class TestFormBinding
{
private TestForm form;
private DelegatingForm delegator;
@BeforeMethod
public void readBindables()
{
form = new TestForm();
delegator = FormTestUtils.getDelegatingForm(form);
}
@Test
public void testBindingToTarget()
{
NestedBean nestedBean = new NestedBean();
form.setNestedBean(nestedBean);
form.setIntegerValue("3");
form.setLongValue("11");
delegator.bindInwards(null);
assert nestedBean.getTargetIntegerValue() == 3;
assert form.getTargetLongValue() == 11;
}
@Test
public void testBindingToNull()
{
form.setIntegerValue("3");
form.setLongValue("11");
delegator.bindInwards(null);
// nothing happens even though no nested bean is set
}
@Test
public void testBindingFromTarget()
{
NestedBean nestedBean = new NestedBean();
form.setNestedBean(nestedBean);
nestedBean.setTargetIntegerValue(3);
form.setTargetLongValue(11L);
delegator.bindOutwards(null);
assert form.getIntegerValue().equals("3");
assert form.getLongValue().equals("11");
}
@Test
public void testBindingFromNull()
{
delegator.bindOutwards(null);
// nothing happens even though no nested bean is set
assert form.getIntegerValue() == null;
assert form.getLongValue() == null;
}
}