You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by pf...@apache.org on 2005/01/31 23:26:04 UTC
cvs commit: jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/form TestLabeledPropertySelectionModel.java
pferraro 2005/01/31 14:26:04
Added: framework/src/test/org/apache/tapestry/junit/form
TestLabeledPropertySelectionModel.java
Log:
Test case for LabeledPropertySelectionModel.
Revision Changes Path
1.1 jakarta-tapestry/framework/src/test/org/apache/tapestry/junit/form/TestLabeledPropertySelectionModel.java
Index: TestLabeledPropertySelectionModel.java
===================================================================
// Copyright 2004, 2005 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.
package org.apache.tapestry.junit.form;
import org.apache.tapestry.form.IPropertySelectionModel;
import org.apache.tapestry.form.LabeledPropertySelectionModel;
import org.apache.tapestry.junit.TapestryTestCase;
/**
* Test case for {@link org.apache.tapestry.form.LabeledPropertySelectionModel}.
*
* @author Paul Ferraro
* @since 3.1
*/
public class TestLabeledPropertySelectionModel extends TapestryTestCase
{
public void testEmptyModel()
{
LabeledPropertySelectionModel model = new LabeledPropertySelectionModel();
validateLabel(model, "", null, "");
assertEquals(model.getOptionCount(), 1);
}
public void testDefaultLabeledModel()
{
LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel());
validateLabel(model, "", null, "");
validateModel(model);
}
public void testLabeledModel()
{
String label = "Select a value";
Object option = null;
String value = "-1";
LabeledPropertySelectionModel model = new LabeledPropertySelectionModel(createInnerModel(), label, option, value);
assertEquals(label, model.getLabel());
assertEquals(option, model.getOption());
assertEquals(value, model.getValue());
validateLabel(model, label, option, value);
validateModel(model);
}
private void validateLabel(IPropertySelectionModel model, String label, Object option, String value)
{
assertTrue(model.getOptionCount() > 0);
assertEquals(model.getLabel(0), label);
assertEquals(model.getOption(0), option);
assertEquals(model.getValue(0), value);
assertEquals(model.translateValue(value), option);
}
private void validateModel(IPropertySelectionModel model)
{
assertEquals(model.getOptionCount(), 3);
assertEquals(model.getLabel(1), "true");
assertEquals(model.getOption(1), Boolean.TRUE);
assertEquals(model.getValue(1), "0");
assertEquals(model.translateValue("0"), Boolean.TRUE);
assertEquals(model.getLabel(2), "false");
assertEquals(model.getOption(2), Boolean.FALSE);
assertEquals(model.getValue(2), "1");
assertEquals(model.translateValue("1"), Boolean.FALSE);
}
private IPropertySelectionModel createInnerModel()
{
return new IPropertySelectionModel()
{
private boolean[] values = new boolean[] { true, false };
public int getOptionCount()
{
return values.length;
}
public Object getOption(int index)
{
return Boolean.valueOf(values[index]);
}
public String getLabel(int index)
{
return Boolean.toString(values[index]);
}
public String getValue(int index)
{
return Integer.toString(index);
}
public Object translateValue(String value)
{
return getOption(Integer.parseInt(value));
}
};
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org